The Things Network is being migrated to The Things Stack Community edition (also known as V3). If you’re still using V2 you can check the legacy support here.
The Things Network (TTN) is a LoRaWAN network for the Internet of Things. It offers data connectivity, so users can create their applications on top of it. This article highlights how you can send and receive LoRa data through TTN to AllThingsTalk.
Let’s say that you have a LoRaWAN device with temperature sensor and LED actuator and you want to connect it to Maker.
Good example is our LoRaWAN Rapid Development Kit with Grove sensors.
To enable your data to arrive in Maker, you’ll need to:
The next 3 sections are done at the same time; you might need to switch contexts back and forth a few times. Please make sure you have TTN and Maker open in seperate browser tabs.
Go to Maker and create a new device:
+ NEW DEVICE
lora
tag to filter the catalogCONNECT
buttonIntegartion between TTN and AllThingsTalk Maker makes sure that whenever the data from your LoRa device lands in TTN, it is immediatelly forwarded to AllThingsTalk Maker, routed to your device resource, and ready for you to use.
Integartions are implemented as webhooks in TTN. Here’s how to set that up:
+ Add webhook
talk-to-attalk
Create AllThingsTalk Maker webhook
+ Add end device
If your device reads temperature sensor’s value it can send it over TTN to your account in Maker.
In your new created device in Maker, create a new sensor asset:
+ NEW ASSET
temperature
and profile type number
Before your end device starts sending the real data, you can test if your LoRa data arrives in Maker by simulating it from TTN console.
You typically want to use a binary data format because of the limited payload size which are inherent to LPWAN networks such as LoRaWAN.
One of the payload formats Maker understands is CBOR. The message format which AllThingsTalk uses for CBOR is{"<asset name>": <value>}
.
In RDK example, your temperature sensor reads 23 degrees Celsius, and you’d like to see that value in Maker. You can use cbor.me to convert the payload to CBOR, e.g,
{"temperature": 23}
translates to A1 6B 74 65 6D 70 65 72 61 74 75 72 65 17
Read more about data formats.
Now you can send the payload from TTN console and verify that it arrives in Maker:
A1 6B 74 65 6D 70 65 72 61 74 75 72 65 17
Simulate upink
temperature
state updated to 23
Important: LoRaWAN class ‘A’ devices can only receive payload data (downlink messages) as a response on an uplink message. The network uses the receiving slot of an uplink message to send data towards the device as typically the device will go to sleep mode to conserve energy.
Now that you’ve received your data in Maker, you can command your device from Maker, and turn on the LED. Before you do so, you can test by sending a command from Maker and receiving it in TTN console.
Create a LED
asset which you’ll use to send a command.
+ NEW ASSET
LED
and profile type boolean
The easiest way to test the actuations is by using CBOR. The message format which AllThingsTalk uses for CBOR is{"<asset name>": <value>}
.
You can use cbor.me to convert your payload to CBOR, e.g,
{"LED": true}
translates to A1 63 4C 45 44 F5
In Maker, click on the asset LED
, and from Command
field send the command true
:
Back in TTN console go to Live data screen, and you’ll see your payload being scheduled for downlink.
For your RDK device, you’d need to implement a logic which would turn on the LED when a value comes from Maker. For example, when value
true
comes from the assetLED
your code will set LED state toHIGH
and the LED on your device would light up.
ABCL stands for AllThingsTalk Binary Conversion Language , and it’s a JSON-based, domain specific language, used for encoding and decoding of AllThingsTalk asset data to and from binary payloads. It gives you the freedom to specify your own decoding scheme on a per device level.
As opposed to CBOR, which sends A1 63 4C 45 44 F5
when you send true
command from LED
asset in Maker, with ABCL you can set a conversion which sends only FF
for the same command. This results in much less data being used to achieve the same goal.
To set up a conversion in Maker, go to SETTINGS > Payload formats
and check ☑️ Use ABCL to convert custom binary data.
Add a conversation which will translate the boolean state of LED
actuator into the first byte of your binary payload:
{"actuate": [{"asset": "mode", "field": {"byte": 0, "type": "boolean"}}]}
Click on the asset LED
, and from Command
field send the command true
:
Back in TTN console go to Live data screen, and you’ll see your payload being scheduled for downlink.
You can now use Maker to collect your temperature readings, and turn on the LED on your device.
Go ahead and make your idea happen using AllThingsTalk LoRaWAN Rapid Development Kit.