LowPowerLab Forum

Hardware support => Projects => Topic started by: Kapock on June 24, 2017, 08:54:48 AM

Title: Another Alarm System
Post by: Kapock on June 24, 2017, 08:54:48 AM
Our current alarm system was getting cranky after 7 years so I began research for a replacement. The current alarm system manufacture advertises that it is not for DIY and I could not make sense of their new product line anyway so an upgrade from the same company was out. I was happy with their 5+ years sensor battery life but little else. Weeks of frustrating due diligence produced little in the way of new possibilities. I am not interested in a system that requires an account on a companies web site which in many cases means control of the system through their website requiring access credentials to my local net.

Reluctantly I decided to look into a "roll your own". A little experimentation convinced me to give it a try. The new system consists of just one type of sensor at this time (a window and door magnetic switch) connected to a Motino. Each motino sends periodic messages to a central motino which reformats the message and sends it via serial cable to an Intel NUC that I bought some years ago. I upgraded the OS on the NUC to the new Ubuntu LTS, added nginx, G++, and SSH. Reporting and Control is through a web interface. I can pick up any tablet or smart phone around the house to view and control the system.

After poor experiences with ZWave I felt it necessary to be able to measure and understand the behavior of the network. The spread sheet looking image below shows the web page that displays network behavior. I am seeing about a 1% packet loss which is better than I hoped for and a relatively consistent signal strength reading from the nodes. The RSSI column is an average of the last 5 readings. At his time the nodes wake up every 4 seconds to check the sensor and every 30 secs (or so) to report in to control. These values will change during roll out. Node # 6 does not exist, it was added to test "last heard from" processing. I am more interested in the relative change in battery voltage rather than absolute accuracy. During 3 weeks of testing the batteries (3 well used AA cells) for node # 2 have decreased by 0.03 volts. The plan is to use 3 AAA cells but that may change after further testing. During sleep mode each remote node uses about 11 microamps.

To further understand the network behavior the last 60 readings of RSSI are saved and can be plotted. A sample plot is displayed below. The happy conclusion (for me) is that the readings are consistent although it makes for a boring plot.

The main control page has oversized buttons so it will be easier to use from a touch screen tablet and smart phone. The alarm system can be changed from OFF, to AT HOME, to AWAY. Alarms that occur when the system is set to AWAY or At HOME are send out via SMS and email. The second row of buttons provides the ability to turn SMS and Mail off to prevent an accidental flood during testing. The middle button on the 3rd row displays overall alarm status. The bottom row has only 1 working button (Network) which calls up the Net Status page. The net status page is refreshed every 15 seconds. A PHP TCP connection to the control program provides exchange of commands and information between the control program and server side PHP code.

The remote nodes still have to be packaged which will stress my non-existent mechanical abilities. The plan is to then add other types of nodes (temp, humidity, motion,...), improve the network instrumentation, and continue to develop the control software. 5 More motinos are on order.

Since the RFM69 radios worked out of the box the RFM69 software is still a black box to me. I have read some conflicting information about interrupts on the arduinos and expect to come back to this forum with a few questions (perhaps more than a few).

This has been and continues to be great fun to work on. I'm not sure about the appropriate image size for attachments. Be happy to post larger images if these are too small. I hope this has been worth your reading time.
Title: Re: Another Alarm System
Post by: Felix on June 25, 2017, 11:59:41 AM
Very nice, would be great to see more details of your implementation both hardware and software!
Title: Re: Another Alarm System
Post by: Kapock on June 30, 2017, 10:46:29 AM
Here is a little more detail about the operation of the alarm system.

The main control program thread runs every second on the Intel NUC. It has 3 threads running: TCP - a thread that is a TCP server mainly to provide information to the PHP web server pages, UDP - a thread to receive UDP commands from the web server and act on them (SMS OFF, Mail OFF, Siren OFF,... This could have easily been handled by the TCP thread), and the Serial Input thread which reads the incoming messages from the central motino. The serial thread is given the highest thread priority. It issues a blocking read on the serial port awaiting either 32 bytes or expiration of VTIME. Received messages are parsed and the information stored in the node data base.

The web server pages normally run on nginx on the NUC but can also run on a windows 10 computer. When PHP generates a page it first connects via TCP to the TCP thread and requests information needed for the web page display. The windows computer is easier for me to use for editing and testing. Once I am finished editing and testing, files can be moved unchanged to the NUC and everything runs as expected. The TCP interface logically disconnects the webserver from the control program running in the NUC so theoretically the web server code could run on any computer in the house capable of running a web server.

The battery voltage is now read only once every 10 minutes, to be changed to once per hour in the future. To read the voltage Vcc is applied to two 500K resistors connected in serial to ground. The voltage is read from the middle of the two resistors. A reading of 4.02 volts on the web display was confirmed by a reading of 4.01 volts with my Fluke meter.

I want to reduce the current load of the voltage divider resistors and was thinking of moving the ground connection of the resistors to a digital input. Then when I want to read battery voltage I would set the input pin low, read the voltage and then set the pin high. when the pin is high the input voltage on the pin will be equal to Vcc which for 3 AA cells could be around 4.5 volts. I looked for max input values on the 3.3 volt chip and have not been able to find them yet.

Does anyone know if I can put 4.5 volts on a digital input pin on the 3.3 volt chip without harming the chip? And another question: do you think the scheme abovde will actually reduce current drain when not measuring battery voltage? I have already accidentally let the smoke out of a few RFM69s so am a little cautious.


Title: Re: Another Alarm System
Post by: Felix on June 30, 2017, 01:47:19 PM
Does anyone know if I can put 4.5 volts on a digital input pin on the 3.3 volt chip without harming the chip?
You cannot, you can damage it. Usually the absolute max specs state that you can put at most VCC+0.5V on a GPIO.
Title: Re: Another Alarm System
Post by: ChemE on June 30, 2017, 02:42:32 PM
...And another question: do you think the scheme abovde will actually reduce current drain when not measuring battery voltage?

4.5V/1,000,000Ω = 4.5μA which is about the sleep current of a Moteino running on the WDT.  I don't think there is any doubt that running the voltage divider off a digital pin would reduce this current essentially to zero since it only needs to be energized for a few ms per hour.

EDIT: For fun I applied a duty cycle of 10ms/hour to the above voltage divider current.  I get 12.5 pA.  If this was too high for you, you could always bump up your resistors to 2MΩ each to get down to 3pA.  ;D

EDIT2: Apparently you might expose your ADC to too high a voltage if you disconnect the bottom resistor: http://forum.arduino.cc/index.php?topic=161390.0
Title: Re: Another Alarm System
Post by: Kapock on June 30, 2017, 05:04:53 PM
Felix - thanks for the warning. A number of motinos are now breathing a sigh of relief.

ChemE -  I would love to get the current drain down to pico amps but I get the same 4.5 micro amp load that you do. If I use fresh AAA batteries one chart on the web says I have 1000 ma hours available. Another web site says this equals over 58,000 hours of power at 12 microamps. Figuring in the additional power consumption of the RM69 transmissions is more difficult (at least for me). Getting the battery voltage seems like such a great feature that if it costs an additional 4.5 microamps 24 hours a day then I may give it a try. I would be happy with a 2 year battery life. I bought 3 3.7 volt rechargeable batteries as a test, they had 3000 maH but then I got concerned by the news about LiPo battery fires. AA batteries have about 2400 maH and I could probably fit them into the small box I am using (2 1/4 x 3 3/4). BTW - I tried using two 1 meg resistors but the ADC reading was very inconsistent.

I am still getting about a 1% packet loss. Not using the "auto retry" feature so I can get the real packet loss numbers. Latest web page attached. Now reading 2 digital inputs on each device. Unit 6 just added. Unit 7 does not exist yet.