1. Learning Centre
  2. Get Started
  3. 3️⃣ Connect to networks

Use The Things Network V3 with AllThingsTalk

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.

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.

Set up the integration

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:

  • Create a new device resource in Maker
  • Add AllThingsTalk Maker webhook in TTN
  • Create an End device in TTN

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.

Create a new device in Maker

Go to Maker and create a new device:

  • Go to Devices
  • Choose + NEW DEVICE
  • Choose Your own LoRa™ device from the catalog; you can click on the lora tag to filter the catalog
  • Choose The Things Network V3 tile
  • Choose a Device name
  • Provide Device EUI of your end device
  • Copy Network token so you can paste it while creating a webhook integartion in TTN console
  • Click CONNECT button

Add AllThingsTalk Maker webhook in TTN

Integartion 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:

  • Go to your chosen application in TTN console
  • From the left sidemenu select Integrations > Webhooks
  • Click + Add webhook
  • Select the AllThingsTalk Maker tile
  • Set Webhook ID, e.g, talk-to-attalk
  • Provide Network token - paste the token you have copied in the previous step (while creating a device resource in Maker)
  • Click Create AllThingsTalk Maker webhook

Create an end device in TTN

  • Select End devices from the sidemenu
  • Click + Add end device
  • Follow their flow to create an end device

Receive your sensor data

If your device reads temperature sensor’s value it can send it over TTN to your account in Maker.

Create a sensor in Maker

In your new created device in Maker, create a new sensor asset:

  • Choose + NEW ASSET
  • Create a Sensor with name temperature and profile type number

TTN New sensor

Send data from TTN console and receive it in Maker

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:

  • In TTN console, go to End devices tab
  • Select your end device
  • Go to Messaging > Uplink and use Simulate uplink to send a payload:
    • Enter A1 6B 74 65 6D 70 65 72 61 74 75 72 65 17
    • Click Simulate upink
  • In Maker you will see temperature state updated to 23

TTN Maker state update

​​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.

Actuate your device

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 an actuator asset

Create a LED asset which you’ll use to send a command.

  • Choose + NEW ASSET
  • Create an Actuator with name LED and profile type boolean

TTN new actuator

Actuate your device with CBOR

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:

TTN Actuate via CBOR

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 asset LED your code will set LED state to HIGH and the LED on your device would light up.

Actuate your device with ABCL

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:

  1. {"actuate": [{"asset": "mode", "field": {"byte": 0, "type": "boolean"}}]}

TTN Payload formats

Click on the asset LED, and from Command field send the command true:

TTN Actuate via CBOR

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.