Exploring soil moisture sensors: Difference between revisions

From Sensors in Schools
Jump to navigation Jump to search
No edit summary
Line 49: Line 49:


[[File:Screen Shot 2022-01-01 at 4.24.51 pm.png]]
[[File:Screen Shot 2022-01-01 at 4.24.51 pm.png]]
* 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)
[[File:Screen Shot 2022-01-01 at 4.26.37 pm.png]]
* 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'''.
[[File:Screen Shot 2022-01-01 at 4.28.01 pm.png]]
=== 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.
[[File:Screen Shot 2022-01-01 at 4.29.55 pm.png]]
* 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.
[[File:Screen Shot 2022-01-01 at 4.30.55 pm.png]]
* 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.
[[File:Screen Shot 2022-01-01 at 4.32.24 pm.png]]
* 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

Revision as of 05:33, 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