Write Data from The Things Network
Use a ThingSpeak integration with The Things Network to write data from devices connected on a LoRa® network.
Long-range wireless communication (LoRa) enables the transfer of sensor data over large distances. The Things Network is a protocol and infrastructure that provides a link to cloud applications from LoRa gateways. The Things Network can automatically forward your collected sensor data to ThingSpeak™ when you set up a ThingSpeak integration.
Create Things Network Integration
Note
To use an integration, you must have an existing Things Network application. For instructions on setting up an application and registering a device with The Things Network, see Collect Agricultural Data over The Things Network.
To forward data to ThingSpeak, you must have an application on the Things Network with a registered device and a payload formatter. Create a ThingSpeak integration to forward the data.
Log in to The Things Network Console.
Select Applications, and then select the application you want to forward data to ThingSpeak from.
Click the Integrations tab.
Select ThingSpeak.
In the Process ID field, name your integration.
In the Authorization field, enter the write API key for the channel that you want to store your data in. The API key is available from the ‘API keys’ tab of your ThingSpeak channel.
In the Channel ID field, enter the channel ID for the ThingSpeak channel you want to forward data into. The channel ID is available on your ThingSpeak channel’s page.
Payload Format
Next, set up the payload formatter. The payload formatter converts bytes sent from your device into a data format that can be stored and visualized on ThingSpeak. The example payload format is for a payload of 20 bytes where the output variables are one, two, or three bytes. For an example of how to send a particular payload from a device and format it for the ThingSpeak integration, see Collect Agricultural Data over The Things Network.
Click Payload Formats.
Create a payload formatter for your integration. You can use the following sample payload format as a template.
function Decoder(b, port) { var var1 = b[0]; var var2 = b[1]; var var3 = b[2]; var var4 = b[3]; var var5 = b[4] | b[5] << 8; var var6 = b[6] | b[7] << 8; var var7 = b[8] | b[9] << 8; var var8 = ( b[10] | b[11] << 8 )/100; var lat = ( b[12] | b[13] << 8 | b[14] << 16 | ( b[14] & 0x80 ? 0xFF << 24 : 0 ) ) / 10000; var lon = ( b[15] | b[16] << 8 | b[17] << 16 | ( b[17] & 0x80 ? 0xFF << 24 : 0 ) ) / 10000; var elev = b[18] | b[19] << 8; return { field1: var1, field2: var2, field3: var3, field4: var4, field5: var5, field6: var6, field7: var7, field8: var8, latitude: lat, longitude: lon, elevation: elev } }
See Also
Collect Agricultural Data over The Things Network | Create Customized ThingSpeak Channel View