Well after getting over the flu, FINALLY, I have been back at the coding for this winter. Here is a little of some of the additions I have been working on:
Version3 is done and put to bed. I decided on the protocol I am going to use from now on for all the MQTT topics, and subscriptions. I kept changing the way I was posting stuff to the MQTT server, through many revisons, it was time to decide on a standard.
For Room nodes posting to the server I have decided on the standard of /SYSTEM/ROOM/node. Therefore if Kitchen light #1 in the house is activated, the the posted topic is /HOUSE/Kitchen/KIT1/. For the Engineering space. the all nodes post to /ENG/SYSTEM/Node. I know this seems silly maybe but I found out on version 3 that a small change one place creates a ripple effect cause you to change the published topics for nearly everything to reflect the change....SO Lesson learned when planning a system, decide on a protocol early on, stick with it.
Since version 3 is done, the improvements to version 4 included database integration. I HATE database admin stuff, but it soon because a necessary evil. I checked out many be decided of for the open souce database MySQL. I had to educate myself in the use, writing queries, and the proper creation of the database and the associated tables. In all reality, I had given databases a bad wrap, it was quite easy to learn and now I have one large database, with several tables.
The reason for database usage was quite simple. though the nodes can publish to the MQTT server, and other nodes can subscribe to topics and act on the published data, I needed places where nodes could pull current stored data. I am also working on what happens in the event of a power loss at the house. Its my intention that I will eventually be able to restore the house to the pre- loss of power state, once power is restored, by pulling the last data set out of the database. That part hasnt not been implemented yet, but will.
With the new found use of my database, it was necessary to update the table with new data in real time. A little funky for me really since I was relying on MQTT to do all the work. Also with using arduino based MQTT libraries, I discovered that there is no way to pass a "last will and testament" to the MQTT server.Wills arent not currently implemented in the latest MQTT libraries for arduinos.....SO what happens then if a node drops offline? The solution of course is time stamping the data, and then I can check the last time stamps against when I last heard the node....surpass a predetermined time frame, I have to assume the node is not communicating with the MQTT server.......
Finally I have decided on adding a couple of python scripts to the MQTT server. One of these scripts now acts as a logic layer. This script will also channel information between all of the room nodes in the house, to the Controller arduino thats actually switching lights on and off. I decided this was simpler. Adding this "logic layer" allows me to modify virtually anything, without the need to touch the Controller arduino. So for instance of I add something to the system, the logic script can be modified offline, saved and restarted as the new logic script. It provides one place to make changes in the system without the need to pull out the laptop, start up the arduino IDE and program the house control arduino. I will discuss this script in more detail in the next post.
I also added a second python script to the server computer. This script, called "trigger" merely is a simple script, basically running in an endless loop. It monitors the servers clock, and issues "triggers" based on time. So for instance, at 7:30pm I want the front porch light to come on, daily, I simply add the trigger to the script. If I was to modify the script, again I can do it offline, adding what I want, and then save it and restart the script to apply the new trigger. No need for additional RTC shields for arduinos, as all of the triggers fire off MQTT publications to the master controller arduino on the same topic the logic script does. Thus, at 7:30pm, the script will tell the controller to turn on the front porch light.......Ill discuss trigger script in more detail as well in a later post.
So I have been busy, and Ill start sharing more on the new revision in the near future.
In the meantime, happy coding!
No comments:
Post a Comment