Siemens IOT2020 - installing and testing Node-Red, MQTT and SQLITE3
Time to install some software to allow us to build a real open source industrial Gateway. This to me means: Node-Red for control flows to be designed and managed graphically MQTT for publishing commands and data to upstream systems and also for subscribing and publishing to and from Edge nodes controlling relays and power devices, reading temperature, humidity, pressure, you name it. SQLITE3 to allow historical data to be stored and retrieved for trending and analysis.
Now before we can install any of this, you will have to follow the first few videos: Creating SD CardExpanding File system to make full use of SD card.
Health Warning: This is a very technical post and it will take a while to complete the process (over an hour or more, making the video while I was at it, meant it took me way more). I have tried to document everything correctly but there may be the odd mistake. Please let me know if there are improvements to be made and/or corrections.
Configuring Data Sources and ArchitectureNow its time to configure Data Sources, Architecture and then install Node-Red, MQTT in the form of Mosquitto and SQLITE3 for database functionality Then we will add many Node-Red modules allowing Node-Red to use them. We will also add nodes for Modbus, GPIO, Serial and other features.
Configure repository sources and architecture parameters Update Architecture by adding the following lines to /etc/opkg/arch.conf, adding the bolded lines below
arch all 1
arch any 6
arch noarch 11
arch i586 12
arch quark 13
arch x86 14
arch i586-nlp-32 16
arch i586-nlp-32-intel-common 21
arch iot2000 26
Add a file called /etc/opkg/iotdk.conf. Insert the following content into the file:
src iotdk-all http://iotdk.intel.com/repos/2.0/iotdk/all
src iotdk-i586 http://iotdk.intel.com/repos/2.0/iotdk/i586
src iotdk-quark http://iotdk.intel.com/repos/2.0/iotdk/quark
src iotdk-x86 http://iotdk.intel.com/repos/2.0/iotdk/x86
Run opkg update to update the local lists for repositories.
Installing Node.js, SQLite3Now time to install nodejs
, sqlite3
and a bug fix for sshd
(It gets broken when installing nodejs?). Execute the following commands:
opkg install nodejs
opkg install sqlite3
opkg install sshd>
Now to install node-red and node modules, execute the following commands (You can copy and past all this in one go to the command prompt, it will work through them automatically):
npm install -g --unsafe-perm node-red
cd
mkdir .node-red
cd .node-red
npm install node-red-dashboard
npm install node-red-contrib-modbus
npm install mraa
npm install galileo-io>
npm install node-red-contrib-gpio
npm install node-red-contrib-upm
npm install node-red-contrib-modbustcp
npm install moment
npm install node-red-admin
npm install node-red-contrib-bigtimer
npm install node-red-contrib-esplogin
npm install node-red-node-sqlite
npm install node-red-contrib-timeout
npm install node-red-node-openweathermap>
Now if you don't want all of the modules, then simply remove the line. This may take a while (maybe over half an hour) but it will get there and you may see warnings as well. This is expected with the current version of the OS and these modules. They do however work.
Installing MosquittoNow we are ready to install Mosquitto, use the following commands, if you have an issue with the wget
not finding the file, it may be possible a later version has been released, check repository and update your script to compensate. Again this process can take a while but it will get there.
cd
wget http://mosquitto.org/files/source/mosquitto-1.4.10.tar.gz
tar xzf mosquitto-1.4.10.tar.gz
cd mosquitto-1.4.10
# this next step takes a while
adduser mosquitto
make WITH_SRV=no
cd test/broker
make test
cd ../../
cp client/mosquitto_pub /usr/bin
cp client/mosquitto_sub /usr/bin
cp lib/libmosquitto.so.1 /usr/lib
cp src/mosquitto /usr/bin
Setting Node-Red and Mosquitto to auto start on power up or reboot. Node-red, make a file and paste in the following text. File Path:
/etc/init.d/autostart_node_red.sh>
#! /bin/sh
# for example:
/usr/bin/node-red -u /home/root/.node-red -v &
exit 0
Mosquitto make a file and paste in the following text. File Path:
/etc/init.d/autostart_mosquitto.sh >
#! /bin/sh
# for example:
/usr/bin/mosquitto &
exit 0
Now add permissions and set the auto start demon to work:
chmod +x /etc/init.d/autostart_node_red.sh
update-rc.d autostart_node_red.sh defaults
chmod +x /etc/init.d//autostart_mosquitto.sh
update-rc.d autostart_mosquitto.sh defaults
Run the following for adding a repository for MRAA:
echo "src mraa-upm http://iotdk.intel.com/repos/3.5/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf>
Now we have everything installed we can reboot and see if everything works.
NOTE: For the testing of SQLITE3, the following script can be run to create a data base with tables and set permissions. It will also add a few rows to some tables. If you don't want this, you can simply not use it or just delete it after the test.
cdmkdir dbssqlite3 ~/dbs/iot.db CREATE TABLE IF NOT EXISTS \`pinDescription\` ( \`pinID\` INTEGER PRIMARY KEY NOT NULL, \`pinNumber\` varchar(2) NOT NULL, \`pinDescription\` varchar(255) NOT NULL);CREATE TABLE IF NOT EXISTS \`pinDirection\` ( \`pinID\` INTEGER PRIMARY KEY NOT NULL, \`pinNumber\` varchar(2) NOT NULL, \`pinDirection\` varchar(3) NOT NULL);CREATE TABLE IF NOT EXISTS \`pinStatus\` ( \`pinID\` INTEGER PRIMARY KEY NOT NULL, \`pinNumber\` varchar(2) NOT NULL, \`pinStatus\` varchar(1) NOT NULL);CREATE TABLE IF NOT EXISTS \`users\` ( \`userID\` INTEGER PRIMARY KEY NOT NULL, \`username\` varchar(28) NOT NULL, \`password\` varchar(64) NOT NULL, \`salt\` varchar(8) NOT NULL);CREATE TABLE IF NOT EXISTS \`device_list\` ( \`device_name\` varchar(80) NOT NULL DEFAULT '', \`device_description\` varchar(80) DEFAULT NULL, \`device_attribute\` varchar(80) DEFAULT NULL, \`logins\` int(11) DEFAULT NULL, \`creation_date\` datetime DEFAULT NULL, \`last_update\` datetime DEFAULT NULL, PRIMARY KEY (\`device_name\`));CREATE TABLE IF NOT EXISTS \`readings\` ( \`location\` varchar(20) NOT NULL, \`value\` int(11) NOT NULL, \`logged\` timestamp NULL DEFAULT CURRENT_TIMESTAMP);CREATE TABLE IF NOT EXISTS \`pins\` ( \`gpio0\` int(11) NOT NULL DEFAULT '0', \`gpio1\` int(11) NOT NULL DEFAULT '0', \`gpio2\` int(11) NOT NULL DEFAULT '0', \`gpio3\` int(11) NOT NULL DEFAULT '0');INSERT INTO PINS VALUES(0,0,0,0);CREATE TABLE IF NOT EXISTS \`temperature_record\` ( \`device_name\` varchar(64) NOT NULL, \`rec_num\` INTEGER PRIMARY KEY, \`temperature\` float NOT NULL, \`date_time\` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP);CREATE TABLE IF NOT EXISTS \`Device\` ( \`DeviceID\` INTEGER PRIMARY KEY, \`DeviceName\` TEXT NOT NULL);CREATE TABLE IF NOT EXISTS \`DeviceData\` ( \`DataID\` INTEGER PRIMARY KEY, DeviceID INTEGER, \`DataName\` TEXT, FOREIGN KEY(DeviceID ) REFERENCES Device(DeviceID) );CREATE TABLE IF NOT EXISTS \`Data\` ( SequenceID INTEGER PRIMARY KEY, \`DeviceID\` INTEGER NOT NULL, \`DataID\` INTEGER NOT NULL, \`DataValue\` NUMERIC NOT NULL, \`epoch\` NUMERIC NOT NULL, \`timestamp\` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP , FOREIGN KEY(DataID, DeviceID ) REFERENCES DeviceData(DAtaID, DeviceID ) );.exitEOF
cdchmod 777 ~/dbschmod 666 ~/dbs/iot.dbcd
Configuring Node-RedNow lets configure Node-Red for some tests.
The MQTT configuration is as follows, your IP address of course may be different, use ifconfig
at the Linux ssh
command prompt to find what it is.
Now the ModBus node, if you don't have a TCP ModBus device then you will not be able to test this one, this is also device dependent. I was requesting data from a FLIR AX8 Industrial Thermal Imaging Camera.
The command used for the sqlite3
select statement in node red is this "select * from pins;". The database path is "/home/root/dbs/iot.db".
When you click the button you should see the debug output as shown below:
The Dashboard elements are simply entered into and then exited with the done button to set defaults. This will allow them to appear on a web browser. A later video will cover this in more detail.
Browse to the same address as the one you're using now and add /ui
at the end, so it will look like this: http://192.168.1.178:1880/ui/#/0 but with your IP address.
You should be able to use a browser from any smart device, phone through to desktop. I prefer Chrome but all I tried did work.
MQTTThe final testing is MQTT, configure MQTT Lense (a Chrome add-on) as shown, adjusting for your IP Address.
I know this is all quite long but necessary. I am hoping that Siemens will add a few of these applications into the base code to make life easier, but at this time its not there and therefore the steps are necessary to get to this point.
If you try this and run into difficulties then please post a command and i'll try to help.
Comments