I recently go Texas Instruments Sensor Tag and thought I would try to build an IoT app. Occasionally we leave the house thinking we have left the stove on so wouldn't it be good to get a warning before we drove off? Also, there is that smart letter box - "you have snail mail" alert.
Snail Mail Alert
The snail mail alert works by you placing the sensor inside the letter box and it being knocked over when you get mail. When it senses it being knocked over, it gives you a standard "toaster" alert on your phone. You collect the mail and put the sensor back to re-arm it. You only need to setup the app when you restart the phone, so it could be weeks or months before needing to touch the phone app again. It automatically reconnects when you are in range and checks to see if it has fallen over. However, it does not notify you instantly, it could take up to 15 minutes. But given the use case, this should be OK.
Stove alert
The stove alert works by putting the sensor in a glass jar and the radiant heat of the stove (in operation) would warm the glass and then be picked up by the sensor. The phone would monitor the temperature and upon the sensor going out of range (i.e. you leaving the house), it checks the last recorded temperature. If the glass temperature is higher than the sensors temperature or the glass is greater than 30 degrees celsius, then it gives you an alert. Like with the mail, it is really important that the user doesn't need to do anything with the phone. Hence the phone will automatically reconnect when you get back in range of the sensor and begins the process of monitoring again. There could be false positives, but that would be OK given the use case.
Issues
I originally thought by biggest issue would be to customize the sensor tag firmware to change the sensor to be even more energy efficient and always on. However, it turned out to be getting my Windows phone to automatically reconnect to the sensor tag.
Sensor Tag Firmware
I wanted to do three things with the code.
- Change the advertisement interval to 1 second to save power.
- Stay on and keep advertising
- Increase the notification period range (allow it to be 10 seconds) rather than the limit of 2.3 seconds.
- Keep backwards compatibility
I managed to do this by adding in Gatt services 0xAA04, 0xAA14, 0xAA24, 0xAA34 0xAA45 and 0xAA54 that allows me to set a 16bit gatt notification period (up to 9 minutes of so).
I also added in service 0xCCC4 that allows you to set the advertisement interval. Setting the lowest bit puts the device into continual advertisement and sets GAPROLE_ADVERT_OFF_TIME to 3 seconds.
Then I ran out of program memory. I wanted it to be able to be installed via the phone so I had to support "over the air firmware" update.
Windows Phone Code
The phone code does three things. It set up the sensor, sets up background tasks to do the monitoring and programs the firmware. The background tasks to receive the Bluetooth's GATT notifications, monitor device connection (to get the disconnect to send the stove message) and run a time thread that periodically looks for the sensor and sets everything up when the device gets back in range.
Originally I wanted to run this on Windows 10 IoT as there are other features which I would love to use, such as the trigger you get when the Bluetooth device comes back into range.
The sensor tag should last a whole year on the one replaceable battery. However I think I would need to tweak more settings to get to that. I would possibly need to add in a sleep setting to put the device to sleep maybe at night or some off peak time.
I found that each ping (advertisement) consumes 0.00012 joules. This means at one advertisement per second, it would last 234 days. The maximum interval is 10.4 seconds.
Comments