HackSpace – September 2019

(Wang) #1
FORGE

bottom of this page, we should see a box called
‘Example Code’.


IT’S ALL IN THE CODE
Rather wonderfully, this is a snippet of code
containing the two key pieces of information an
Arduino sketch on our The Things Uno needs to
connect it to our application on The Things Network.
Copy these (either select and right-click and select
‘copy’, or press the copy button in the upper right-
hand side of the box) and paste them into a text
document or a blank Arduino sketch. Before we
move on to the next part of the tutorial, we are
going to make one last change to the application
we have made on The Things Network. Return to
the Application Overview page – navigate here by
clicking ‘Applications’ in the upper right-hand side
of the page near your profile name – then select
the application we just created. Once back in the
Application Overview, click the ‘Payload Formats’ tab
on the upper right-hand side. On the resulting page,
you should see a box called Payload Format, and it
should show ‘Custom’ in it. Click on this box. In the
drop-down menu, there should only be one other
option, which is CayenneLPP; select this and then
make sure to click the Save button in the lower right-
hand corner of the page.


LET’S GET CONNECTED
Connecting our DHT11/22 sensor board to The
Things Uno is pretty straightforward. Connect
breadboard wires between the DHT11/22 and The
Things Uno 5 V and GND pin sockets. The data pin on
the DHT11 sensor needs to be connected to pin A0
on The Things Uno (as seen in Figure 1).
Returning to the Arduino IDE, we will now upload
the sketch for our sensor to The Things Uno; having


Remember, an
application on The
Things Network can
support multiple
devices – perfect for
large, remote sensor
array projects!

QUICK TIP


SPICY MESSAGES


Cayenne is an IoT platform by a company called
myDevices. CayenneLPP (Cayenne Low Power
Payload) is a format for data packages over LoRa that
allows for some key types of sensors to be integrated
into the Cayenne IoT platform simply via The Things
Network. Put simply, if we can send sensor data in a
CayenneLPP format, a lot of the work to unpack this
data and present it in a straightforward and readable
way is done for us in The Things Network and the
Cayenne myDevices environment.

made some changes and added the keys, we need
to allow it to communicate with the application on
The Things Network. Download the sketch from
hsmag.cc/issue22 and open it in the Arduino IDE.
There are only a couple of changes we need to

make. The first is to check the frequency plan is
correct for our The Things Uno; this is the same
bit of code we replaced earlier in the device info
sketch. In our code, it is set as the ‘TTN_FP_EU868’
European version and will only need changing if you
are using the US frequency plan.
The second change is that you will see a section
in the code which is similar to the code we copied
from the ‘Example Code’ box on the Device
Overview page on The Things Network earlier. (It’s

Figure 5
Success! Data
from our device
successfully being
received by our
application on The
Things Network

The data pin on the
DHT11 sensor needs to be
connected to pin A0 on The
Things Uno


Free download pdf