Close

"Device?" are you ok?

A project log for Aquarium controller / home automation

I am building an automated aquarium controller to fit into my home automation system.

pjpj 09/18/2016 at 21:220 Comments

Why is it that I get these ideas in the bath? LOL.

As part of the software I have a database for each sub system, (Aqua, Home and Burg) (Aquariums, Home, Burglar alarm)

In the database I have a table called Devices

(I use SQLite3 for speed, safety and ease of use. Python works well with this integrated library)

The records are (similar to) this

devid = tnk1flt1
live = 0
srvr = Server01
node = Ardu01
minv = 0
maxv = 0
wait = 0
desc = tank1 float1
cont = 9
next = 
type = S
stat = 

They identify each device on the network of devices on my system.

(These records are for sensors and actuators. I can record the status of each of the actuators as well because I want this system to be able to work 100% if I have a computer crash; I want the system and the computer to start as if nothing has happened - I don't want anything held or left in memory!)

The above entry, for instance, is for Float sensor-1 in Aquarium-1.

devid = unique name

The live is 0 (0=inactive, 1=active. so I can stop a device from being processed by the system. )

srvr is the mqtt broker server is called Server01

node is the Node where the device lies (*1) is called Ardu01 (each node is a project box with an arduino or nodemcu that has any number of devices attached to it. The devices can be sensors or actuators. Float sensors, flow sensors, temperature sensors, etc and pumps, heaters, lights etc)

minv and maxv are the minimum value it can be is 0 and the maximum value it can be is 0.

The wait time that it must be checked (Every 0 minutes) (0=don't wait to recheck) (*2)

desc is a small description

cont. The checking program must continue with a flag of 9 (I will tell you more about that another day dear reader)

next means when it is allowed to check this device again. (another sneaky field of data I will explain another time)

type is for what type of device it is (A for an actuator and S for a sensor) ($ is for a non-fail device, see note (3*) for this one)

the stat field is for actuators. (1=on, 0=off) (i.e. curtains; closed=0, open=1) etc

Anyway... as I get a msg from the Node (arduino or nodemcu or whatever) saying that the device has given a reading, the program resident on that node checks if the reading is within the min and max levels. If it isn't then it send a mqtt message to the broker saying so. The python program resident on the main computer (it's called "sentinel" - coz it sounds flash!) picks up this message and then acts upon it.

SO

I was thinking! (in the bath) what if one of my devices is sick/has broken/been eaten by the dog etc etc?

My sentinel program would not know as it is a passive program that just waits for mqtt messages advising of certain conditions.

SO

I am designing another program (haven't thought of a cool name for it) (answers on a postcard please) (all answers considered LOL)

This new program will use the devices list as explained above. It will go through each record and send out a special type of mqtt message (with an action code of $) (have i explained to you dear reader about the format of my mqtt messages yet? No? Really? OK I will do that some day soon) When these devices pick up a "?" type of mqtt message it will then send back an information mqtt msg with an action code of "!" (>=Action, !=Information, ?=Query, $=Status etc) So this new program will pick up that msg and "all will be good"..... unless of course the device does not return a msg and then all is NOT WELL, so the program will go into meltdown mode, and start buzzing buzzers, flashing lights, sending emails and all sorts of overkill stuff!

Another addition to this program could be using the sensors to see if the actuators are actually working. Let me explain... Let's say that the daylight-sensor says it is now going dark then the logical conclusion to this would be to send a msg to the curtain-actuator to close, and update the devices record. That part we have got - yes?, ok. Now, if we attached another sensor to the curtain machine to actually check that the curtain closer has actually closed... now... that would be very cool. We perhaps could have a status display on our main screen showing the statuses (statii?) of all the devices and underneath each device text we could display the sensor's text to see if the device is working. Something like this...

+----------+----------+
|*tnk1pmp1*|*tnk1led1*|
|status=on |status=off|
|*tnk1flw1*|*tnk1lsn1*|
|status=on |status=on |
| ALL OK   |***FAIL***|  
+----------+----------+
as you can see in the first display box there are two device's information. the left box on the top there is *tnk1pmp1* (tank1 pump1) and the status says it is on (this piece of data was updated when the pump was told to switch on). Underneath that is another device called *tnk1flw1* (tank1 flow-meter 1) and that is reporting that it is on so, all is ok. However, let us look at the box on the right, the device is *tnk1led1* (tank1 led lights1) last time it was switched off the device file was updated with OFF... but... the device underneath that is *tnk1lsn1* (tank1 light sensor1) and that sensor is reporting that it is ON so this is a FAIL STATE!. Perhaps we could buzz and flash and email etc. Sometimes I think that this is a bit overboard but considering the fact that I am not actually next to me automatic fish tank system all the time and there is possibilities of a water malfunction for instance it would be very good if i could get to know about it for not that much effort on my part. What do you reckon dear reader?


(*1)

I will explain a little of my terminology here just in case I have forgot elsewhere and to give you a little reminder.

the server. There is only one on my home automation system and it is, at the moment, a SBC (Single Board Computer) called an Odroid. The O.S. I run on it is linux mint. I have my IoT MQTT Broker on this server. It is named SERVER01. It is a small fanless circuit board with a load of stuff on it and it cost me £50 as at September 2016. This will live in my cupboard under the stairs with the rest of my other network and comms equipment.

the node. There will be many nodes on my home automation system, (which by the way has been titled as HoCo) (Home Computer System). Each node will be a largeish project pox with an Arduino or Nodemcu in it. There will be a couple of power supplies, a few relays, a couple of LEDs and a few sockets ready for any sensor or actuator that will plug into it. I have different sockets for for different devices for safety. It will be mains driven. Each node is named aaann where aaaa is either ardu (for an arduino) or nmcu (for a NodeMCU) and n is a number in sequence.

the device. A device is an Actuator (pump, light, strobe. bell. switch, heater, curtain closer etc) or a Sensor (light-sensor, humidity-sensor, temperature-sensor etc). A node can have more than one device. Each device is named aaanbbbn where aaa is the general descriptive collection abbreviation (e.g. TNK for Tank, LNG for Lounge, RES for water-resevoir etc), n is a number in a sequence . bbb is the descriptive name of the sensor/actuator (e.g. PMP for pump, FLT for a float-sensor etc) and, again, n is a number in a sequence. So, for example, tnk1pmp1 is pump number 1 in thank number 1, another example would be LNG2DOR3 Lounge number 2 and door number 3.


(*2)

There is going to be time where I dont want the system to keep on re-checking a device after the code inside the node says that a particular device's value is unacceptable (e.g. the moisture-sensor says that a flower pot's soil is too dry). The reason that I dont want to keep on re-checking the device is that after I have switched on a pump, say, for a few seconds to water the said flower pot, it will take a few seconds/minutes for the water to seap through the soil. And, if not ignored, the pump will keep on watering the soil and cause a problem. The same reasoning, for instance, could be if the temperature of the tank water is too cold. (Forget for the minute i have thermostat controlled heaters). If the system got the message the water is too cold then the system would switch the heater on. This process would repeat switching on the heater.

SO

I have built in a design for a wait scenario. Once the device has flagged up that there is a problem I update the INI devices file with the next time that checking can continue.

The wait entry in each record is the number of minutes to add to the current time.

The next entry in each record is the time when checking can be resumed.

Phew - I hope you got all that!

(*3)

I have now invented a 3rd type of device. I call it a non-fail-device, that is, it is a device that does not fail like normal sensor-type devices could. Examples of non-fail-devices are light sensors and outside-rain-sensors. These just simply record the status of something. But, as my logic for arduinodes are to send messages of their status and values etc then these NFD's (non-fail-devices... keep up!) are to send message of their status too. So, if I need to find out their value I will read the devices file as this will be updated when the sentinel program receives their message - get it? No! what do you mean no! it is as clear as, erm, mud. :-(

Discussions