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
type = S
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.
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.
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...
Read more »