Aquarium monitor

Not satisfied by not finishing my first project, I boldly go where I have gone before. This time I approach my other hobby of fish keeping with all the unbridled enthusiasm of the wandering electronics geek. I’m going to build a fish tank monitor!

This was all started by building a small tropical fish tank for my in-laws. This will be sited away from where I live, and rather than the hard landscaped gravel aquarium with plastic plants which it started as, I have suggested a more living aquarium with shrimp, snails, few fish and easy plants such as ‘Cuba’ and lilies. In addition a much more capable external Eheim canister filter will scrub the water well, and I am recommending little if no water changes as that works very well for my 120l fish tank.

But all this will happen a long distance away from here and I want to know how things are going remotely – hence the felt need for a monitoring station. While there are ones like the Seneye they do need a replaceable slide every month, and others like the Mindstream or Apex are truly expensive – plus they are built to control dosing or other schedules like lighting. I can do all of that using a cheap timer, and don’t need the expensive gear for what needs to be a simple tank.

Ideally I’d like to hook up a couple of sensors to a single-board computer such as an Odroid or Raspberry Pi, and connect to the local WiFi to transmit readings through to somewhere else – none of that worries me at all and using things like MQTT make it all very simple. Apparently for the Seneye you don’t even need the branded web server as you can use another server to do it – see here. But the sensors are the right pain as I’ll explain below. I’d like to be able to read:

  • temperature probe – these are simple
  • pH probe – much more complex and needs both calibration, and removing from the water due to fouling. I could use something like this to read the probe
  • NH3 as this affects the fish badly
  • light levels – likely simple as well
  • water levels – no water = bad! Conduction strip or
  • … anything else I dream up.

I don’t need a display nor a GUI front-end as I am happiest when treating my SBCs as remote and headless – I find it tunes the mind to not trying everything and understanding how to recover remotely without a keyboard.

Weather calendar: constrained memory

I am learning a whole lot more about the constrained environment of the microprocessor. For a start, you don’t have a Linux command line! And, perhaps more insidious, you do not have much memory.

Platforms such as Arduino or Pyboard have very restricted memory spaces, and in essence you ‘sit’ within the Python interpreter and run commands there. Actually it is not fully like this, some implement a REPL or some implement a server that takes FTP or Telnet commands, but it is very different from working even in a small single-board computer such as a Raspberry Pi or Odroid which have full Linux, command line shells such as Bash, and even desktops/browsers.

What happened was that I was getting along well with my project displaying weather patterns on the e-ink device and started retrieving more and more details on the controller, however after a short few iterations got memory errors. Thinking this just to be a problem of garbage collection, I called that method and got better iterations – but still eventually crashed out. It seems that the Json parsers and whatnot are leaking memory and no amount of garbage collection will help – and the direct calls to URLs for the weather services surely isn’t helping!

So, refactor.

I’ve now split the code into two components: a server component most likely running under NodeRED on one of my SBCs, and the display component which will simply take the weather readings from the server and display them, concentrating on what it does best.

I may also get advantages by using this method as it can run on smaller embedded devices such as the ESP8266 which do low-power much better than the fuller devices such as the WiPy2. Who knows, maybe months of displays without resorting to replacing the batteries?

Complexity

I started musing about the complexity of modern computer systems after talking with a colleague about recent computer crashes. Those not familiar with modern computer systems expect them to work better than they do and seem to take delight in handing out blame where none lies. Having worked for decades in computers both large and small I am astounded by a couple of things: that complex computer systems actually work pretty well, and that they don’t crash more.

Humans seem to naturally enjoy reducing things to black and white, or two or three choices. Listen to the evolutionary biologists and they’d claim all sorts of things to prove this, such as living in caves and having only a few foods to eat or whatnot. I don’t entirely believe them either – they sound too much like looking for the hypothesis in the evidence, rather than the other way around.

In my professional life I have been through perhaps 3 or 4 major incidents where massive numbers of people could have been impacted and each time a very focused and dedicated technical team have averted disaster. These things are not easy and take real hard work. I’d rather rely on people who have experienced real complex issues than those armchair generals that never saw a battle.

Case in point: you’d perhaps expect that major companies know exactly what systems they have installed, how many applications run on them and where they are? You’d be wrong, as time and time again I hear stories or know by personal experience that they do not know entirely where things are. This varies from the incidental (we didn’t know that we were running that much software) through to the monumental: a major corporation thinking it had about 8,000 systems and finding that they had … 14,000. That is quite a difference from what they expected.

Putting aside our human tendency to over-simplify, what happens as systems get even more complex? Can we get computers to manage other computers, can we adopt methods and architectures which are much more emergent rather than the procedural and directive that we currently use? What happens when the system becomes more than the sum of its parts and can’t be governed except by itself?