Exploring soil moisture sensors: Difference between revisions
Jump to navigation
Jump to search
| Line 99: | Line 99: | ||
[[File:Screen Shot 2022-01-01 at 4.34.30 pm.png]] | [[File:Screen Shot 2022-01-01 at 4.34.30 pm.png]] | ||
* Enter the following details in the Security tab: | |||
** Username – '''whi-soil-7-moisture-mkr-1300@ttn''' (the username is simply a unique name given to the soil moisture sensor on The Things Network. The name is short for Whittlesea soil moisture sensor #7 running on an Arduino MKR 1300 microcontroller) | |||
** Password - '''NNSXS.WL5EA6KF6TWUZCALAIIEWNX7YED4ADI5QQOTK7A.XYRLCUHY6WGY5Z5O6TS7A7UFAACBNY72WIZPAITY6K3LTYLOVZXA''' (Enter this passwork exactly as shown. This key is generated on The Things Network Console. We will demonstrate this in an upcoming lesson) | |||
* Click on Update to commit these changes. | |||
[[File:Screen Shot 2022-01-01 at 4.40.56 pm.png]] | |||
* Once the Server has been configured there are some other minor configurations in the mqtt in node: | |||
** Topic - '''#''' (the hash symbol # indicates that we are subscribing to all topics) | |||
** QoS (Quality of Service) – '''0''' (only zero is supported by Node-RED. Normally higher numbers reflect better error detection) | |||
** Output – '''a parsed JSON object''' (all the data sent from the mqtt in node will be in JSON format. JSON format is similar to a dictionary. There is always an attribute and value pair. For example {colour:blue}. JSON objects are enclosed in curly brackets). | |||
** Name – '''soil-7''' (this node will be subscribing to data from soil moisture sensor #7) | |||
* Click on Done when finished. | |||
[[File:Screen Shot 2022-01-01 at 4.42.59 pm.png]] | |||
Revision as of 05:43, 1 January 2022
Connecting to a soil moisture sensor via The Things Network (TTN)
Overview
- In this lesson we are going to connect to a soil moisture sensor.
- The soil moisture sensor is connected to an Arduino MKR 1300 microcontroller (a small computer).
- The data will be transmitted to the LoRa network.
- LoRa is short for Long Range radio communication.
- The data is then sent to The Things Network, which is a community run server that collects data from sensors and makes the data available for download.
- We will download the data to our Raspberry Pi, and in future lessons display that data in a Dashboard using Node-RED.
- All these skills are very important in helping to address Climate Change and general Environmental Sustainability issues the world faces.
Learning Objectives
- Learn how to connect to The Things Network using MQTT using Node-Red
- Learn how to extract specific data from JSON formatted data packets
Connecting to the Things network using Node-RED
- In this lesson we are going to use Node-RED as our main programming tool.
- Node-RED is a block or node based programming language.
- Each block has a discrete function and some blocks can contain Javascript code or be configured in different ways.
- Blocks are connected together using wires.
- Node-RED and the programs on the Raspberry Pi are always being updated, so it’s normally good practise to update our Raspberry Pi on a regular basis.
Updating and Upgrading the Raspberry Pi
- Open the Raspberry Pi Terminal.
- Enter the command sudo apt-get update
- This command will update all the software libraries on the Raspberry Pi, so that if we need to install software the Pi will install the latest software packages.
- Enter the command sudo apt-get full-upgrade -y
- This command will upgrade the entire operating system on the Raspberry Pi.
- The -y option tells the computer to answer Yes to any questions.
- The upgrade will take between 5 and 30 minutes to complete.
- It is always to do this once every month.
Running Node-RED on the Raspberry Pi
- Open the Terminal.
- To start Node-RED enter the command node-red
- The display on your Raspberry Pi will be different, but similar enough.
- When using Node-RED it is important to stop Node-RED when you are shutting down your computer.
- To close Node-RED open a new Terminal window and enter the command node-red-stop
- To re-start Node-RED enter either node-red or node-red-start
- It takes Node-RED approximately 20 seconds to boot up.
- To see the Node-RED interface we need to use a Web Browser.
- Open the default Web Browser on the Raspberry Pi.
- In the Search Bar enter localhost:1880 (or http://localhost:1880)
- The number 1880 represents a Port. Your computer listens and talks on different ports to make communication between devices and systems easier.
- Localhost is an abbreviation for 127.0.0.1 which is a address reserved for the host computer (the Raspberry Pi)
- Node-RED can be installed on Windows, Mac or other Linux machines.
- In a few moments the Node-RED programming environment will be displayed.
- One the left is the Node-RED Pallet containing an assortment of Nodes.
- In the middle is the Node-RED Flow Editor
- On the right are different debugging and system related tools.
Connecting to The Things Network using MQTT
- To download the data generated by our sensor we can use MQTT.
- MQTT is short for Message Queuing Telemetry Transport.
- Using this protocol we can subscribe to newly published data. As soon as new data arrived it is delivered to our device, just like a daily news feed or other subscription.
- To subscribe to our sensor data we need to use a mqtt in node
- Search for the mqtt in node in the pallet on the left and drag it into the Editor Window.
- If the mqtt in node is difficult to find you can enter mqtt in the search bar at the top of the pallet.
- In this example we can see that two results are returned, one for mqtt in and one for mqtt out.
- Note that the mqtt in node has two coloured shapes attached to the node:
- the red triangle means that the node still needs to be configured
- the blue circle means that the node need to be Deployed before it will work
- To configure the node, double click on it.
- This will open a Sidebar that will pop out from the right hand side.
- For the Server parameter, we will select Add new mqtt-broker and then click on the Edit tool, which looks like a pencil icon.
- The Edit tool will open up another Sidebar listing the Properties for the mqtt-broker node.
- Enter the following details under the Connection tab:
- Name – soil-7
- Server – au1.cloud.thethings.network
- Port – 1883
- Protocol – MQTT V3.1.1 (if you don’t see the Protocol parameter you don’t need to change any other settings)
- Now click on the Security tab.
- Enter the following details in the Security tab:
- Username – whi-soil-7-moisture-mkr-1300@ttn (the username is simply a unique name given to the soil moisture sensor on The Things Network. The name is short for Whittlesea soil moisture sensor #7 running on an Arduino MKR 1300 microcontroller)
- Password - NNSXS.WL5EA6KF6TWUZCALAIIEWNX7YED4ADI5QQOTK7A.XYRLCUHY6WGY5Z5O6TS7A7UFAACBNY72WIZPAITY6K3LTYLOVZXA (Enter this passwork exactly as shown. This key is generated on The Things Network Console. We will demonstrate this in an upcoming lesson)
- Click on Update to commit these changes.
- Once the Server has been configured there are some other minor configurations in the mqtt in node:
- Topic - # (the hash symbol # indicates that we are subscribing to all topics)
- QoS (Quality of Service) – 0 (only zero is supported by Node-RED. Normally higher numbers reflect better error detection)
- Output – a parsed JSON object (all the data sent from the mqtt in node will be in JSON format. JSON format is similar to a dictionary. There is always an attribute and value pair. For example {colour:blue}. JSON objects are enclosed in curly brackets).
- Name – soil-7 (this node will be subscribing to data from soil moisture sensor #7)
- Click on Done when finished.










