Assuming that you got your node running. Otherwise please visit the Getting started page.
On the back side of the PCB you can connect several sensor modules like:
- Temperature
- Humidity
- Barometer
- GPS
- Dust sensor
- Gas sensor
- motion detection
- etc.
For this example we are going to use a simple DHT22 sensor Temperature/Humidity.
You can use the preconfigured pins on the back of the PCB for this sensor.
.
Editing the Script
Download the sketch from Github here
Download the DHT library DHT-sensor-library from Adafruit.
To use the Adafuit DHT library you also must install the Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
Add the library to the header of your script.
Select the pin where the DHT is connected. This is pin 6.
Select the type of DHT sensor you use: DHT11 (blue) or DHT22 (white).
Add dht.begin; to your setup section.
Now add a void PayLoad () to your script to get the data from the DHT, and convert it to a usable payload for the LoRa network.
The first section gets the data from the sensor, like in the example script from the DHT library. After this we must convert the sensor data to bytes. The max payload size for the TTN network is 51 bytes. First shift the decimal point of the result from the sensor 2 places to the right. For example 22.81*100 = 2281.
Then shift the bits and store the data in bytes.
For more information about Bytes and Payload format please read the tutorial here: TheThingsNetwork.org.
Add the end the data is sent to the network, and it prints a serial output so you can see your sensor working.
We only need to the void PayLoad to the void do_send.
Now upload the sketch to your board.
Check the serial monitor to see if the node works properly.
Now go to your TheThingsnetwork console.
Go to: Applications => Your-Applications => Data
Here you can see the data from your sensor received by the TTN network.
It is converted in bytes, we need to decode it to get readable data.
Go to: Applications => Your-Applications => Payload formats
And paste these lines in the editor:
function Decoder(bytes, port) {
var temp = (bytes[0] <<8) | bytes[1];
var humi = (bytes[2] <<8) | bytes[3];
return {
Temperature: temp / 100.0,
Humidity: humi /100
};
}
Click on save ad go back to: Applications => Your-Applications => Data
You wil see your decoded data.
Now you can send this data to your application or website. You can also choose from several platforms direct from TheThingsNetwork.
Go to: Applications => Your-Applications => Integrations and click add Integrations
More about Integrations later.
Assuming that you got your node running. Otherwise please visit the Getting started page. On the back side of the PCB you can connect several sensor modules like: Temperature Humidity Barometer GPS Dust sensor Gas sensor motion detection etc. For this example we are going to use a simple DHT22 sensor Temperature/Humidity. You can use the […]