Home Automation with Node Red, JeeNodes and Open Energy Monitor
BRAMLEYD 100000UYS6 Comments (3) Visits (35332)
I discovered JeeNodes whilst searching for an easy and low cost way to implement a wireless arduino sensor network. The JeeNode is an open source arduino with a built-in 433 RFM12B radio. The radio is both cheaper than a Wifi shield, easier on batttery life and there are numerous of coding examples from Jeelabs and others to make them work.
The RFM12B radio is relatively sophisticated with CRC checking, and acknowledgement mechanism and the ability to give Node's their own ID
The JeeNode's default sketch is a test utility for the wireless radio - which allows commands to be sent via serial port and It is this mechanism I have used for the Node Red base station.
The Open Energy Monitor project also uses the Jee Node libraries as the foundation - so their sensors will also connect to the network straight out the box.
My home network is comprised of the following;
Base Station Hardware:
Base Station Software
JeeNode Micro + DS18B20 Temperature
The Raspberry Pi makes the perfect base station as it is is very quiet,and efficient and can be left on without worrying about power consumption. A PC or Mac can also be used for the purpose.
For these instructions it will be assumed that the Jeelink is the first USB device plugged into the Pi and is assigned Serial Port: /dev/ttyUSB0
Setting up the Jeelink
The Jeelink needs to be setup by connecting a terminal application program such as Tera Term to it Baud 57600. This can be done from on your PC or Mac.
The following commands need to be issued:
4b <---sets the frequency to 433Mhz (default is 898)
Node Red setup
To use the serial port it is necessary to install the serialport Node.js library by issuingthe following npm command from the node-red installation directory:
sudo npm install serialport
N.B. If you are using a Windows or Mac base station you will need to install the appropriate build tools (Visual Studio Expresss or XCode Command Line tools) as the serialport Node requires compilation. Fortunately the Pi has a compiler by default.
Once the serialport is installed we will build a Node Red flow to parse inbound and outbound Radio messages onto mqtt topics.
Here is a picture of the overall flow before we discuss each of the nodes in more detail:
Serial Input / Output Nodes
Set the serialport node up with Baud 57600 and \r\n for new line characters:
Parse the input
Good data from the RFM12 radio will begin with the characters "OK" .
If we find these characters we send the message content to the mqtt topic
(The Node Id is bit masked as the int data also carries an additional bit indicating if an ack is required or not)
The outbound message flow subscribes to the mqtt topic rfm12b/out/# and sends the msg.payload data to the node identified by the last part of the topic. For example messages sent to the topic rfm12b/out/12 will be delivered to Node 12 on the JeeNode network.
Rather than using the rfm12 in and out topics directly, I prefer to map the the rfm12 node topic to the logical device it is connected to. This makes things more self explanatory later on (you don't have to remeber what node ids you gave your sensors) and allows you to "plug" and "unplug" sensors and move nodes later on without having to change anything else in the flow:
In the next post we will look at integrating sensor data:
The Node-red code: (use the Node Red imoprt from Clipboard feature to copy and paste this in)