Home Internet of Things

ESP8266 Building Block #2

The Center of Things (continued)


OK, we now have a monitor device that not only announces the status of the refrigerator locally (with LEDs), but broadcasts that status to any device that is listening. Now we need a listening device that can do something useful with that information.


Click here to get a copy of the sketch for BUILDING BLOCK #2.

http://firebottleradio.com/iot/block2.ino


The hardware for this block is VERY easy. There are no connections other than power to a NODEMCU board. Initially you will want to connect it to your PC with USB, but after it is flashed you can just power it up and talk to it with OTA and TELNET. The block2 sketch will listen for UDP broadcast messages from any number of temperature monitors, check to see if the temperatures are acceptable and send a TEXT message to a mobile phone if they are not.


The usual suspects


You will find that this sketch has the usual UDP, OTA and TELNET code. The UDP code is now listening for broadcasts instead of sending them. These messages are parsed and the strings turned into floats to make it possible to check for high temperatures. When we find that a refrigerator is out of spec the fun really begins. To figure out how it works, just read the code. It is actually very simple and straight forward.


You will find that the TELNET debug is used in a different way. Actually the way that the author intended. Play with it to see how it works.



Thingspeak and Twilio


There is probably a way to send TEXT messages directly from the ESP8266, but I find that it is easy to do using a couple of IoT cloud services: thingspeak.com and twillio.com. The procedure that I used is explained at: http://www.instructables.com/id/Send-SMS-from-Arduino-over-the-Internet-using-ENC2/


Take a look at his third option (thingspeak). The description is for a different processor, but the basics are the same. There is a thingspeak library that works with the ESP8266, but I prefer to roll my own. It is actually very simple and it gives me more visibility to what is happening.


When an event occurs (temperature problem, loss of connection, etc) a message to thingspeak.com will be posted. This will trigger thingspeak to send a message to twilio and twilio will send a TEXT to my phone. Since I already had accounts with both of these services it was a relatively simple process for me.


I left as much information in the sketch as possible, just changing it enough to protect my accounts. This example plus the write-up shown above should allow you to get it going.


You will need to put the thingspeak api key into the code modify the line:


const String apiKey = "your thingspeak api key";


you will also have to put in the mobile phone number that will receive the TEXT messages. Just replace the dummy number with your number:


const String sendNumber = "4345555678";


All of this works great. A text message is sent every 24 hours to verify that things are working. If you want to disable this, just remove (or comment out) the line:


#define DAILY 1


When you first set it all up, enable (remove the //) line:


//#define TESTENABLED 1


and it will send a text every 60 seconds.


As written the code expects to see messages from three temperature monitors. Two refrigerator/freezers and one stand alone freezer. You can have more or less of the monitors (just remember to make the UDP messages unique in the first letter.


The same technique could be used to monitor almost anything and to broadcast if for the central monitor to analyze and post text messages. I have a lot of plans and will post the sketches when I have something working.


I also use thigspeak.com to record and display the refrigerator temperature information. This makes the current temperature, the trends and history available on the internet. I have not yet even started documenting this part of the IoT project, but will get to it eventually.