Tiny House temperature monitoring using Node-RED and LoRa

From Sensors in Schools
Jump to navigation Jump to search

Overview

  • In this lesson - temperature and humidity data from a Tiny House was collected using a Pycom LoPy4 and transmitted to a local LoRa WAN Gateway
  • The data was processed in The Things Network
  • The data was subscribed to using MQTT using Node-RED
  • A time stamp was added simple time node
  • The data was processed using a process node to extract out temperature data
  • The data was then packaged so that it cold be dweeted.
  • The data will be available to students as a Dweet so that they can monitor the performance of their tiny house
  • Students will use Python to process the dweeted data (Dweepy module)

Node-RED Configuration

mqqt-in Node

mqqt-in edit Node - Connection

  • Follow the example below to configure the connection to the MQQT broker on The Things Network

mqqt-in edit Node - Security

  • Follow the example below for the security configuration.
  • Note that the username is whi-tinyhouse-12-temperature-pycom@ttn
  • Whereas the password is a very long chanracter set (40+ characters) obtained from the The Things Network Application page.
  • For security reasons, Node-RED will not retain any passwords if the node is copied.

simpletime Node

  • simpletime adds time and date stamps to the data flow within Node-RED.
  • The simpletime node needs to be added to Node-RED using the Manage pallet function.

  • Example of default configuration of simpletime node.

function Node

  • The function node is used to process data flows in Node-RED.

  • In this example the function node is used to:
    • Extract temperature, humidity and battery data from the mqtt in data feed
    • Then assign the data to variables
    • And finally, dweet the data so that the data is available to students on the internet.

  • Code reproduced below.
  • Add your own unique dweet address to the code.
  • The dweet address also requires the question mark symbol at the end - <My_Dweet_address>?
var battery; // battery voltage data
var int_humidity; // humidity data from within the sensor housing
var ext_temp; // external temperature data
var int_temp; // temperature data from within the sensor housing

battery = msg.payload.uplink_message.decoded_payload.bat;
int_humidity = msg.payload.uplink_message.decoded_payload.humid;
ext_temp = msg.payload.uplink_message.decoded_payload.onewire_temp;
int_temp = msg.payload.uplink_message.decoded_payload.temp;

msg.payload = "bat=" + String(battery) + "&"
    + "intHumid=" + String(int_humidity) + "&"
    + "extTemp=" + String(ext_temp) + "&"
    + "intTemp=" + String(int_temp) + "&"
    + "date=" + String(msg.myymd) + " " + String(msg.mytimes);

msg.url = "https://dweet.io/dweet/for/<My_Dweet_address>?" + msg.payload;

// check dweet with - https://dweet.io/get/latest/dweet/for/<My_Dweet_address>
return msg;

http request Node

  • The http request node is able to Dweet the data package using the POST http operation.

  • The configuration of the http request node is shown below.
  • The node has been named dweet tiny house 12 data (name is lower down in node edit window - not shown).

Node-RED code for flow

[
    {
        "id": "4a48c27d77b24951",
        "type": "tab",
        "label": "Tiny house 12",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "9eb5f086aba506f2",
        "type": "mqtt in",
        "z": "4a48c27d77b24951",
        "name": "whi-tinyhouse-12",
        "topic": "#",
        "qos": "0",
        "datatype": "json",
        "broker": "770475c1.8593ac",
        "nl": false,
        "rap": true,
        "rh": 0,
        "inputs": 0,
        "x": 100,
        "y": 60,
        "wires": [
            [
                "611459927e315292"
            ]
        ]
    },
    {
        "id": "1b6fa839582e5f27",
        "type": "debug",
        "z": "4a48c27d77b24951",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "",
        "statusType": "auto",
        "x": 660,
        "y": 200,
        "wires": []
    },
    {
        "id": "42efdbdb620f1c41",
        "type": "function",
        "z": "4a48c27d77b24951",
        "name": "process tiny house 12 data",
        "func": "var battery; // battery voltage data\nvar int_humidity; // humidity data from within the sensor housing\nvar ext_temp; // external temperature data\nvar int_temp; // temperature data from within the sensor housing\n\nbattery = msg.payload.uplink_message.decoded_payload.bat;\nint_humidity = msg.payload.uplink_message.decoded_payload.humid;\next_temp = msg.payload.uplink_message.decoded_payload.onewire_temp;\nint_temp = msg.payload.uplink_message.decoded_payload.temp;\n\nmsg.payload = \"bat=\" + String(battery) + \"&\"\n    + \"intHumid=\" + String(int_humidity) + \"&\"\n    + \"extTemp=\" + String(ext_temp) + \"&\"\n    + \"intTemp=\" + String(int_temp) + \"&\"\n    + \"date=\" + String(msg.myymd) + \" \" + String(msg.mytimes);\n\nmsg.url = \"https://dweet.io/dweet/for/SMC-Tiny-House-12-bundoora?\" + msg.payload;\n\n// check dweet with - https://dweet.io/get/latest/dweet/for/<My_Dweet_address>\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 520,
        "y": 120,
        "wires": [
            [
                "510be4e1f5acfe72"
            ]
        ]
    },
    {
        "id": "611459927e315292",
        "type": "simpletime",
        "z": "4a48c27d77b24951",
        "name": "",
        "mydate": true,
        "myymd": true,
        "myyear": true,
        "mymonth": true,
        "mymonthn": true,
        "mydom": true,
        "mydoy": true,
        "myday": true,
        "myhourpm": true,
        "myhour": true,
        "mytime": true,
        "mytimes": true,
        "myminute": true,
        "myminutes": true,
        "mysecond": true,
        "mymillis": true,
        "myepoch": true,
        "myrawdate": true,
        "mypm": true,
        "x": 290,
        "y": 60,
        "wires": [
            [
                "42efdbdb620f1c41",
                "98d5072b7123bd5f"
            ]
        ]
    },
    {
        "id": "98d5072b7123bd5f",
        "type": "debug",
        "z": "4a48c27d77b24951",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "false",
        "statusVal": "",
        "statusType": "auto",
        "x": 680,
        "y": 60,
        "wires": []
    },
    {
        "id": "510be4e1f5acfe72",
        "type": "http request",
        "z": "4a48c27d77b24951",
        "name": "dweet tiny house 12 data",
        "method": "POST",
        "ret": "obj",
        "paytoqs": "body",
        "url": "",
        "tls": "",
        "persist": false,
        "proxy": "",
        "insecureHTTPParser": false,
        "authType": "",
        "senderr": false,
        "headers": [],
        "x": 410,
        "y": 200,
        "wires": [
            [
                "1b6fa839582e5f27"
            ]
        ]
    },
    {
        "id": "770475c1.8593ac",
        "type": "mqtt-broker",
        "name": "whi-tinyhouse-12",
        "broker": "au1.cloud.thethings.network",
        "port": "1883",
        "clientid": "",
        "autoConnect": true,
        "usetls": false,
        "protocolVersion": "4",
        "keepalive": "60",
        "cleansession": true,
        "birthTopic": "",
        "birthQos": "0",
        "birthPayload": "",
        "birthMsg": {},
        "closeTopic": "",
        "closeQos": "0",
        "closePayload": "",
        "closeMsg": {},
        "willTopic": "",
        "willQos": "0",
        "willPayload": "",
        "willMsg": {},
        "userProps": "",
        "sessionExpiry": ""
    }
]