Wednesday, September 4, 2019

Finally, MQTT Sensor for Home Network

I had been building my own home alarm system a long time ago.  I found that the event server had a memory leak I tried to figure out numerous times, but never succeeded in getting it identified.  It would just get killed randomly on the raspberry pi.  I needed a better interface.

The first iteration was the Arduino with code and a custom TCP connection for alerts.  The server side was the problem here.  This functioned well, but the "server" was a cheap desktop PC that failed because it was on all the time and wasn't designed to.  The PCI bus failed, and it went down.

After the server crash, I then moved it to a raspberry pi to get it online (I didn't care about the PC).  Though it functioned well, it was at this point that a memory leak raised it's ugly head.  I found a number of that I tried to figure out numerous times, but never succeeded in getting it identified.  It would just get killed randomly on the server by the out-of-object memory killer.  (SSH would also get killed, which made it difficult - the process killed was random, and the SSH job dying would force me to pull the plug on it and go through the filesystem scans, HMPH!).

At that point, I switched over to MQTT.  I ran some initial tests using Raspberry PI GPIO's as inputs and Mosquito as the server.  Most seemed to work, but the raspberry Pi would die on me weirdly.  I think the issues with the memory leak were the Linux distribution on the Pi, but it still frustrated me.  Rebooting it forced me to start those processes manually, even though they were in the proper RC files.

At this point, just MQTT (still Mosquito) and a few MQTT translator python scripts was the next move.  It's been going for a while now (with a few power outages) and it fires right up into operational state fairly quickly.  The GPIO's (probably where the kernel had the memory issues) have been offloaded to an Olimex ESP32-PoE device.  It has a simple MQTT plug-in loaded onto it and all it does is check pins and update the MQTT server. I do have one problem where the garage reports errors regularly, so I have to figure out one line (hope a mouse didn't chew through it, or next I'll have to go mouse hunting).

No comments:

Post a Comment