Introduction
Set up your environment
Create your TTN application and register your device to it
Write and run the Hello LoRa world sketch
Add a sensor to your node
Decode your message in the TTN console
Set up All Things Talk
Create a Pinboard in All Things Talk Maker
Introduction
For a joint Sensemakers Amsterdam / TTN workshop we have obtained some uNode boards from TLab.gr. See https://www.tlab.gr/projects/%CE%BCnode-project/ for details.
The boards we will be using have an MCP23S08 expansion GPIO fitted.
We will set up the Arduino environment, install the library that comes with the uNode which already contains the LMIC LoRaWan library. Then we will set up an aplication on TTN and register the device to the application. Then we will create a sketch to connect to the application.
Next we will fit the board with an DTH11 sensor and send the data to TTN. Finally we will integrate our TTN application to a dashboard we will ceate on All Things Talk maker.
Set up your environment
Specifically for the workshop in the OBA on January 16th, 2019
- The WiFi SSID is OBA Wifree. No password is required here.
- But then your browser will open, or you have to open it yourself. It may show the OBA logon screen. If not, just browse to any location and you will be redirected to a logon page in your browser. Here you need to enter a username and a password. On the tables are light-blue flyers with the current credentials
- We are with a large group which may swamp the WiFi. We hope that many of you already did the downloads and installs at home. And we have prepared some memory sticks. Ask for a stick if your download is going too slow.
What will happen
In this step you will check your hardware, set up the software development environment and do a quick verification.
Check your hardware
Unpack the uNode board and the things that come with it. We have prepared kits for you containing:
- A uNode board. See https://www.tlab.gr/projects/%CE%BCnode-project/. The board contains the ESP8266 processor, 4M flash and the RFM95 LoRa module. It is pre-fitted with a connector for an FTDI asynchronous interface to your notebook, and also has the MCP23S08 8 port GPIO expander chip installed. There are also male pin-headers to connect sensors to the GPIO.
- An FTDI USB/async interface to upload sketches and connect the serial port to your notebook.
- A USB cable.
- A pigtail-coil antenna for the EU868 LoRa band.
- A DTH-11 temperature/humidity sensor with some wires.
Setup your development environment
-- Install the Arduino IDE
Now it is time to set-up the Arduino development environment on your notebook.
If you already have the Arduino IDE please check the version in the Help screen. You will need a fairly recent version. We have tested with version 1.8.7 and up. So if you have a lower version, it would be best to upgrade. Just follow the steps for a fresh install. The Arduino installer will offer to de-install your current IDE first. If you already have the proper version go to "Install the board file" below.
First we need to donwnload the Arduino IDE installer. You will find it on https://www.arduino.cc/en/Main/Software . Look for this pane:
There are installers for Windows, Mac OS X and Linux. Download the one that matches your notebook's OS and follow the install procedure. Make sure that the USB drivers are installed too.
-- Install the board file
The Arduino IDE needs a plugin to work with your ESP8266 processor. First we tell it where to look and the we will install the right version with the built in board manager. The procedure is:
- Open File->Preferences and press the wee icon at the right hand side of: "Additional Board Manager URLs"
- Check if http://arduino.esp8266.com/stable/package_esp8266com_index.json is in the list. If not please add it.
- Close the dialog boxes by pressing OK and go to Tools->Board "some text"->Boards Manager... It may take a bit of time to load.
- Enter "ESP8266" into the search box. It will show an entry "esp8266 by ESP8266 Community". We need version 2,4,2. If you already have this version installed, you are done and can close the dialog. If you have a different version installed or nothing installed, click the pane once. A version drop down will appear. Select 2.4.2 and install or update to this version.
- When done, close the board manager.
-- Install the uNode library
The uNode comes with a comprehensive library in a .ZIP file. For the workshop we will be using version 0.8.1. You only need the closed source .ZIP file (which also contains the open source stuff). The direct download is https://github.com/Tlabio/arduino-unode/releases/download/0.8.1/uNode-0.8.1cs.zip . If your browser opens the ZIP file, just close it. It will be in your Downloads folder.
The Arduino IDE knows how to install a zipped library. Open the Sketch->Include Library->Add .ZIP Library... dialog. A file open dialog will show. Select the .ZIP file you just uploaded, click OK and in a jiffy you'll be done.
The library, documentation and source code is maintained on Github, You can find all releases here: https://github.com/Tlabio/arduino-unode/releases .
The manual for the device is also available in a comprehensive WiKi. Go to https://github.com/Tlabio/arduino-unode/wiki .
Later it is also recommended to look at the Getting Started pdf in the release folder. It contains lots of background information, API manuals etcetera. No direct download, as it is still being updated at the time of writing this. Just go to the .../releases link above and look for it.
-- Do a quick verification
- Connect the USB cable to your notebook and open the Arduino IDE
- Select Tools->Board "xxxx"->Generic ESP8266 Module and wait a couple of seconds for the IDE to switch to this board.
- The menu should now look like Tools>Board "Generic ESP8266 Module".
- Just below there in the Tools menu, select Flash Mode: "DIO".
- Then again in Tools select Flash Size "4M (1M SPIFFS)".
- Now plug the FTDI programmer into your uNode exactly as on the picture below. Do not yet connect it to your notebook with the supplied USB cable. But before you do, look at the photos below and alsop make sure that the jumper on the FTDI board is in the 3.3 Volt position. If the FTDI board is positioned as on the photo below it should be on the two leftmost pins.
- When you are sure everything has been connected properly, plug in the USB cable into your notebook. If you get USB errors you did not install the Arduino IDE properly. Remember the note about the USB drivers. If it happens call for help an we'll try to fix it for you.
- Then again go to the Tools menu. And select Port: "something". Now the "something" can be a bit of a problem. If there is only one entry in the drop down list, you're in luck. Just use this one. But if there are more you'll need to figure out which one to use. The easiest way is to unplug your programmer. And go back to the menu again. The one that has disappeared is the one you are looking for. Note that on Windows the entries look like COMnnn and on Linux and MacOS they will look like /dev/something.
- Then go to File->Examples->uNode->Blink. A new IDEwindow will open. with the Blink sample sketch. Be aware that there are many Blink examples in the Examples. You'll be looking for the one that comes with uNode!
- Now compile and upload. You can use Sketch->Upload. But Control-U or the right arrow in the Ribbon will do the same. The IDE compiles the stuff first which may take one or more minutes.
- When everything is done, and the IDE reports "Uploaded" somewhere near the bottom left your sketch should work. Straight from the bag the blue LED on your board blinks with half second intervals. Now it will blink slower, once per second.
- You can also open the debug window in the IDE. Tools->Serial Monitor, or Cntl-Shift-M will do the job. Or the looking glass icon at the right hand side of the ribbon.
- Please check now that you have 115200 baud selected at the right bottom side of the debug window. If there is any other value, change it to 115200.
- Now press the reset button at the uNode board. There is only one button. Looks like a metal rectangle with a wee round "dot" on it. The dot is the button you are looking for. Some text should appear in the debug window. Not very interesting at the moment, but that will change when we get further.
Create your TTN application and register your device to it
What will happen
Here we are going to set you and your device up on The Things Network.
Register to TTN and log on
If you already have a TTN account, just log on to the TTN console at https://console.thethingsnetwork.org/. Then you are done with this step.
If you do not have an account you have to register first. This can be done here: https://account.thethingsnetwork.org/register .
Create an Aplication
On the TTN you can create an application. One or more devices can be registered to this application, and the application can send your data to back-ends using an " integration". For this workshop we will:
- create an application;
- register the uNode device to it;
- link the TTN application to a back-end we will create on AllThingsTalk Maker.
So let's do the application. After your log-on to the console you choose Application. The button is hard to miss, but this link will bring you there directly: https://console.thethingsnetwork.org/applications.
You will see a list of your applications, if this is your first one the list will of course be empty. On the top right hand side of the pane you can press the "+ Add application" to open the Add Application dialog.
Application ID: First you need to choose a ID for your application. This ID must not yet exist on the TTN and it can only exist of lowercase alphanumeric characters, nonconsecutive - and _ and it cannot start or end with a - or a _. While writing this I have used demo-for-tutorial.
Description: Optionally you can do a short text, just as a reminder for yourself.
Application EUI: nothing to enter here. TTN will pick one for you.
Handler registration: assuming you are in the EU, leave this to ttn-handler-eu.
Now press the Add Application button and ...
So, we have an application now as you can see in the overview that has appeared. There is interesting stuff here we will need later. We will pick it up when we do.
Adding your device
The 3rd pane from the top is labelled "Devices". And it will show 0, since we just created a new application. So let's add the uNode. On the right-top of the pane you'll find: "register device". Please click on it. More to fill out:
Device ID: is a unique ID for your device. It follows the same strict naming rules as the Application ID. And you cannot change it later. I have called mine demo-node-1.
Device EUI: Some nodes come with a built in Device EUI, but not so the uNode. So we let the TTN generate one for us. On the left hand side of the input box there is an intertwined arrow icon. Press it once and the box content will go to "this field will be generated". Exactly what we want.
App Key: This one is already on "this field will be generated". And that is what we want too.
So time to press "Register"at the bottom right.
So, thats all there is to it. Time to try to send some stuff to the TTN from our uNode. Which will be worked out in the next step.
Write and run the Hello LoRa world sketch
What will happen
Here we are going to write our first sketch for the uNode board. It will do an OTAA (Over The Air Activation) of your uNode device and connect to tha application we have created in the previous step. And obviously we will send "Hello world of LoRa" to the TTN.
Get the sketch template
In your Arduino IDE go to File->Examples->Unode->TTNSend_OTAA. A new window will open containing a default sketch. Somewhere on the middle (line 40) you will find this:
uNodeConfig unode_config = { .lora = { .mode = LORA_TTN_OTAA, .activation = { .otaa = { // This key should be in big endian format (or, since it is not really a // number but a block of memory, endianness does not really apply). In // practice, a key taken from ttnctl can be copied as-is. .appKey = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // Both EUI must be in little-endian format, so least-significant-byte // first. When copying an EUI from ttnctl output, this means to reverse // the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, // 0x70. .appEui = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, .devEui = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } } } };
Get the keys and EUIs from the TTN console
So we need to populate the dummy appKey, appEui and devEui with some real data we pick from the TTN console. By the way, in the TTN console these are called Application Key, Application EUI and Device EUI. Programmers just like occasionally to do the odd keystroke less.
Unfortunately there are several formats used for these parameters and you have to pick exactly the right one. If you have left the device console screen open, you are good to go. If not:
- opent the console.
- Pick applications. Select the one you have created in the previous step. You'll see the Application ID you have used.
- Go to the Devices pane and click it.
- And select the Device ID you have given.
You'll see something like:
Let start with the App key. It looks like:
but then of course with different data.
For the device EUI we need to pick little-endian curly bracket format. So press once on the <> icon and once on the icon with the arrows until it looks like:
The blue circle are around the icons you'll need to click. You want the format with the digits between curly braces. And the text marked yellow should read lsb. If it looks different, just experiment with the icons matked in blue until it looks like the above. Obviously the numnbers will be different, since this is the EUI of my demo device.
To copy the lot, no need to select. Just press the red marked icon and you are good to go.
Then go to the Arduino IDE and paste the copied key over the dummy one. So,
.devEui = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
will then change into
.devEui = { 0xB1, 0xE0, 0x47, 0x85, 0xD8, 0xC0, 0x9B, 0x00 }
For the Application EUI the procedure is exactly the same. So in the IDE it will look like
.appEui = { 0x3A, 0x69, 0x01, 0xD0, 0x7E, 0xD5, 0xB3, 0x70 },
.devEui = { 0xB1, 0xE0, 0x47, 0x85, 0xD8, 0xC0, 0x9B, 0x00 }
this when you are finished.
Next the App Key. As the word Key in the name implies, this one opens the door to your device. So it is masked in the GUI. Nice touch, but the Arduino IDE is not so prudent, so first tap the Eye icon to see what you do. The format needs to be with the curly braces, so you need to press the <> icon once. But this time we want msb format. It will look like
So again the curly braces format, but this time the yellow marked text should be msb, You can copy the text with by pressing the copy icon and then paste it in the .appKey fiekld in the Arduino IDE. This will look like
.appKey = { 0x??, 0x??, 0x??, 0x??, 0x??, 0x32, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x??, 0x?? },
With this settings the TTN should recognise your device. Perhaps time to save your sketch.
Leave the console open. We will come back here.
Some data to send
A bit further down on line 83 you'll find a block of code like
void setup() {
uNode.setup();
// Make the GPIO a general purpose input
pinMode(D0, INPUT_PULLUP);
// IMPORTANT : When you are testing this sketch, remember to connect D0 to
// the DTR pin instead of the GND. Connecting it to GND will make
// the device boot into an invalid mode! DTR is pulled LOW after
// boot and therefore behaves as a safer alternative to GND.
// Send the value of the GPIO pin as a LoRaWAN packet
if (digitalRead(D0) == HIGH) {
uNode.sendLoRa("pin=1", 5, packetSent);
} else {
uNode.sendLoRa("pin=0", 5, packetSent);
}
}
This assumes that you have a switch connected to the board. Well, there is no switch and because we are using the GPIO expanded version it would work differently anyway.
So just replace the lot by:
void setup() {
uNode.setup();
uNode.sendLoRa("Hello world of LoRa", 19, packetSent);
}
You can use a different text. Maximum length is 51 characters. And the "19" in the above is the length of the text string.
Compile, upload and run
Just like when we did the blink sketch in a previous step we want to compile the sketch and upload it to the uNode. But before you do we should fit the antenna to the board. The LoRa transmitter will get activated by this sketch and it may get damaged if the antenna is not fitted.
On the back side of the board in a corner there is this tiny uFl connector. The one on the antenna will fit over the one on the board. Be carefull please, they damage easily and are too small to see properly. Don't force please and ask for help if it won't go.
Then without further ado, press the upload button and wait....
Check the result
If all goes well on the Arduino console you will find a log.
There should be something like the below in the text.
[LoRa] Joined
[LoRa] Persisting OTAA session
[LoRa] Marking device as OTAA-Joined
[LoRa] Tx Completed
Packet Sent
[Power] Disabling LoRa
[LoRa] Shut down
[Power] Disabling VBus
[uNode] Sleeping for 30 sec
But this is only the receiving side. So let's go back to the TTN console. There you will find on the device page:
The status shows green, meaning the device has been seen. Frames Up shows the amount of transmissions towards the TTN. Time to look at the actual data.
On the right hand top side of the screen there is a button labelled data. Lets go there.
You will see all the messages that have been exchanged. Starting with the Join resulting from the OTAA. But no text. This is because the TTN does not have the foggiest what kind of data you are sending. So it defaults to a hex dump of the bytes. Let's fix that.
Show the data
We will need to define a decoder for the data in the application. So we go to the application page. There are multiple ways to get there. You can use the breadcrumbs at the top of the page. Or press applications in the header and then select yours. You will be looking for the following
Now press payload formats, and you will see
This decoder does nothing. But we know we are looking for a text string, so we will paste the following code into the text box
function Decoder(bytes, port) {
var decoded = {
message: String.fromCharCode.apply(null, bytes)
};
return decoded;
}
This code tells the network to convert the bytes it receives from your node into a text string.
If you have done it right there should be no warning icons in the left hand margin. You can save the decoder by pressing "Save payload functions" at the bottom.
At the top of the page you can go back to the Data display for the device. Now wait for the next one to come in and see the translated text. You may need the bottom scroll bar to get the text visible.
Add a sensor to your node
What will happen
In this step we get serious. We will connect a DHT-11 sensor to your board. It can measure temperature and humidity. And there is also a sensor already on board. It measures the voltage of the power applied to the board. First we will print the results on the debug console on your notebook. And when it works it is time to encode the results and send them to the TTN.
Connect the sensor
We need to connect the sensor to the uNode. We use sensors from various vendors, unfortunately with different pin orders. So we need to look at the markings on the sensor board. We need to connect:
- The pin marked + or VCC to the 3.3 power supply of the board. This is the pink wire on the picture.
- The pin marked data to one a data pin on the uNode. The data pin is the middle one on all boards. This is the blue wire.
- And the pin marked - or GND to the ground of the board. This is the green wire.
Please look carefully at the photo's below. The colors of the wires in your kit will be different, but do not matter. Just tie +/VCC to 3.3 , connect data to data and -/GND to GND.
On the next photo the RED box is the +3.3 pin. This one has to go to + or VCC of the sensor.
Likewise the two pins in the BLUE box are Ground. One of them needs to go to - or GND on the sensor.
And the YELLOW ones are 8 data pins. In the sketch they have names from D2 to D9. D2 is the left most one in the yellow box. D9 the rightmost one.
The sketch we will use assumes D3, which is the 4th from the edge of the board. See also the photo's above (blue wire).
When in any doubt ask for help please. Much better then frying the sensor or the power switch on the board.
Proof of the pudding
is the eating...
So lets try the following sketch:
#include <uNode.hpp> #include "vendor/DHT_sensor_library/uNodeDHT.hpp" uNodeConfig unode_config = { .lora = { .mode = LORA_DISABLED // No LoRa needed for now }, }; #define DHTPIN D3 // <-- This is the pin where the sensor connects to #define DHTTYPE DHT11 // <-- This is the type of sensor. uNode will also handle the DHT21 and the DHT22 DHT dht(DHTPIN, DHTTYPE); /** Sketch setup */ void setup() { uNode.setup(); dht.begin(); // Start the sensor } /** Sketch loop */ unsigned long startTime = 0; void loop() { uNode.step(); if (millis() - startTime > 10000) { // 10 seconds have passed startTime = millis(); float h = dht.readHumidity(); // Read temperature as Celsius (the default) float t = dht.readTemperature(); Serial.print("Humidity: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temperature: "); Serial.print(t); Serial.println(" *C "); } }
It is handiest to press File->New in the Arduino IDE and paste the above sketch in the new window.
After uploading it should print the humidity and temperature every 10 seconds to the Arduino console window.
And then LoRa
Basically we just combine the above DHT11 reading sketch with the Hello world.. example we did before. But instead of sending a static text string we will send the binary sensor data from the DHT. And as a bonus we will send the board supply voltage. Sending the voltage is vital if you operate on battery. It will warn you when to retrieve your device for a battery recharge.
Being a LoRa enabled sketch you will need to add your own EUIs anf Key again. If you have saved your Hello world... example, just copy them from there. And f yoiu didn't, get them from the TTN console as described in the Hello world... step.
When you have uploaded the sketch, it will immediately start measuring and send the measurements to the TTN every 30 seconds. You can inspect the data on the console. The translation will look weird, because TTN will still assume it is a text string. But we can fix that later.
So here is the sketch to use...
#include <uNode.hpp> #include "vendor/DHT_sensor_library/uNodeDHT.hpp" /** We are using the ADC to measure the battery voltage. If you are using the ADC in your project, comment-out the following line. */ ADC_MODE(ADC_VCC); /** uNode library configuration */ uNodeConfig unode_config = { .lora = { .mode = LORA_TTN_OTAA, .activation = { .otaa = { // This key should be in big endian format (or, since it is not really a // number but a block of memory, endianness does not really apply). In // practice, a key taken from ttnctl can be copied as-is. .appKey = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, // Both EUI must be in little-endian format, so least-significant-byte // first. When copying an EUI from ttnctl output, this means to reverse // the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3, // 0x70. .appEui = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, .devEui = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } } } }; /** Helper function to shut down the chip when the packet is sent */ void packetSent(int status, uint8_t * downstream_data, uint8_t size) { Serial.println("Packet Sent"); // Go to deep sleep for 30 seconds. This will power down everything but the clock and a small amount of RAM. // After the sleep time an interrupt will be generated which resets the sketch to do another pass. // // Warning: when conditions are good you will use Spreading Factor 7 (SF7). With the short payload we // use you will stay within the EU868 duty cycle limit if you transmit every 30 seconds. // Actually, you cannot go above it, since the LMIC LoRa library we use will prevent this. // So if you happen to connect on SF12 (causing way longer airtime for your messages), it may well happen // that your node will introduce extra delays to keep you within the legal limits. // But there is also a TTN Fair Use Policy. And continuous sending every 30 seconds goes // well over the TTN FUP. This is ok for a test and a demo, but not for production applications. uNode.deepSleep(30); } #define DHTPIN D3 #define DHTTYPE DHT11 DHT dht(DHTPIN, DHTTYPE); // This is the binary struct we are using to assemble the struct { uint16_t vcc; uint16_t temperature; uint16_t humidity; } loraData; /** Sketch setup */ void setup() { uNode.setup(); dht.begin(); delay(2000); // Delay for the DHT11 sensor to stabilise. Serial.println("Measuring..."); loraData.vcc = ESP.getVcc(); loraData.temperature = dht.readTemperature() * 100; loraData.humidity = dht.readHumidity() * 100; Serial.println(loraData.vcc); Serial.println(loraData.temperature / 100.0); Serial.println(loraData.humidity / 100.0); uNode.sendLoRa((char *) &loraData, sizeof(loraData), packetSent); } /** Sketch loop */ void loop() { uNode.step(); }
Decode your message in the TTN console
What will happen
The message from your sensor will arrive in binary in the TTN. We will write a bit of Javascript in the TTN console to decode the payload and make it visible in the console.
Optionally you can add the "Data Storage" offered by the TTN. It will keep your data for 7 days and allow retrieval with Swagger.
Some explanation
In our sketch we have used a sketch to pack our data in binary form. It looks like
struct { uint16_t vcc; uint16_t temperature; uint16_t humidity; } loraData;We have three uint_16 in a row. Each is 2 bytes, so the total (the compiler will not ad padding on the ESP8266) of the message is 6 bytes.
The compiler will keep the same order as we declared the struct members. So the first and second byte will be vcc, the next two temperature, and so on.
And within the two bytes of a value, the first one will be the most significant. So to decode you will use: first_byte + second_byte * 256.
So or decoder needs to do something like: vcc = byte[1] * 256 + byte[0]; temp = byte[3] * 256 + byte[2]; and so on.
It junkies often use something like vcc = byte[1] << 8 | byte[0]; This can be done because we multiply with 256 which happens to be 2^8. And it may run one or two microseconds faster: ample reason to make it unreadable not?
Ok, putting this into Javascript in the TTN contect our decoder needs to be
function Decoder(bytes, port) { var decoded = {}; decoded.content = { vcc : bytes[1] * 256 + bytes[0], temperature : (bytes[3] * 256 + bytes[2])/100, humidity : (bytes[5] * 256 + bytes[4])/100 }; decoded.port = port; return decoded; }You see that I also divide the temperature and the humidity by 100. In our sketch we have stored the temperature in 1/100 degrees C and the humidity in 1/100 % increments. Here we van go back to a floating point number format.
A word of warning
Decoding binary values in a struct is easy to explain. But it is a bit dangerous. In the above I have used the term padding. This means that a compiler will insert dummy bytes to enforce alignment rules that some CPUs require.
And I used the term Little Endian. There is also Big Endian. And they use a different order for the bytes in a multi-byte variable.
So, if you compile the sketch for a CPU with different rules, or perhaps just after a compiler upgrade, your decoder will break.
If you want to write for portability or eternity, do the packing yourself or use nano Protocol Buffers.
Try it out
In the "Hello world" step you have learned how to install a decoder in your application. Just replace it by the above one and see if it works.
TTN's storage
TTN will optionally store your data for 7 days. It uses the decoded data. You can switch the storage on by going to your application page. In the menu
you select Integrations. Yu will be shown a comprehensive list of integrations with services where you can send your data. For storage use
And thats all rhere is to do.
But wait, how do you get to your stored data? Look at the Data Storage integration status. It looks like
THe go to platform link will get you to Swagger UI where you can try the GET REST services to retrieve your data. Press it and it will open in a new browset tab. But before you use it you need to go back to the console Application page. There you need to get your authorisation key first.
TTN will not give your data to anyone. The key you require can be retrieved at the bottom of the Application overview. Go there and look for the defaut access key at the end of the page. Just copy it by ressing the copy icon.
Now it is time to go to Swagger. But first check if your uNode has been running since you have added the Storage integration. If not, turn it on please. You would want to see some data, not?
Back in Swagger UI in the header there is a button called Authorize. Press it and paste your key in the window that will appear.
Now you can retrieve data. There are three services. The first on lists your devices. The second one list data for all devices. And the third one for one specific device. We can just use the second one. It will also take a duration parameter. Use 1h (one hour) or so. And look at your beautiful stored data...
Set up All Things Talk
- What will happen
In this step we will create a maker account for you in All Things Talk Maker (ATTM). Then we will make your TTN application and your uNode device known to ATTM.
Next we will check if data is actually coming into ATTM, and we will write a decoder for ATTM to understand your data.
Get your account and log on to All Things Talk Maker
- Go to https://maker.allthingstalk.com/ . If you already have an account Sign-In. And if you are new, Sign-up first. Nothing unusual here.
- Now go to the TTN console and open your Application overview. Again go to integrations. We will now add All Things Talk Maker
- Again you need to invent an ID. I have used workshop-demo.
- For the Access Key use the drop-down and select the default key and add the integration. This is all on the TTN side we need to do.
- So, next All Things Talk Maker. After logging in we need to create a Playground. You need to give it a name. After accepting your Playground will open, waiting to add a device.
- A long list pofoptions will show. You will need this one
- Then ATTM needs to know your nework provider. That's easy: the one and only TTN!
- Now ATTM needs to know how to get to your device. They need to know Device EUI, Application ID, Activation Method (use OTAA), Application EUI and Appliation Key. By now you should know where to get them: in the Appliction page and the Device page of the TTN console. This time you can use the default format. So no <> and arrow key pressing. Just copy them as they are when the page comes up and paste them in the ATTM dialog.
- Now you will end-up on the device page. Somewhere at the top there is a list of options. Press Debug. You should now see your device messages coming in from TTN. The debug window will complain that the messages cannot be decoded. We need to fix this later. For now we just want to see them coming in.
- So there are messages, but ATTM cannot decode them. Lets fix that. At the right to side there is a Settings icon. Press it and then go to the Payload Formats option.
- Tick on the selection box for Use ABCL to convert custom binary data.
- Next paste the data format definition into the window:
{ "sense": [ { "asset": "Vcc", "value": { "byte": 0, "bytelength": 2, "byteorder": "little", "type": "integer", "comment": "Device Vcc in mV" } }, { "asset": "temperature", "value": { "byte": 2, "bytelength": 2, "byteorder": "little", "type": "integer", "calculation": "val / 100" } }, { "asset": "humidity", "value": { "byte": 4, "bytelength": 2, "byteorder": "little", "type": "integer", "calculation": "val / 100" } } ] }
A bit of explanation: " sense" means we are defining incoming sensor data format, "asset" defines the name of one sensor, "value" tells where to get the data. This will be "bytelength" bytes starting at byte " byte". The " byteorder" defines little endian. And for the temperature and the humidity we divide by 100 again to go to floating point format.
Now go to the devices page again and add your assets. These are the sensors on your node. Use the create assets button for that. You can add three of them. Use the same names you have used in the decoder. So perhaps Vcc, temperature and humidity . Vcc is an integer and temperature and humidity are numbers.
Now the device page will show your incoming data. To gain some space you can close the setting pane by pressing the X. And play around a bit with the various data visualisation options.
Create a Pinboard in All Things Talk Maker
What will happen
All Things Talk Maker has some presentation features for your data. We will create a Pinboard showing the last readings from your device and a graph with temperature, humidity and board voltage over time.
Create a pinboard
A Pinbord is just an insrument panel for your data.
- Select Pinboard in the left menu. Give it a nice name.
- Press arrange Pinboard. A graphical editor will appear.
- We will now add some presentation options. Press the New Pin button at the top right.
- We will first use the Label control for the Vcc. So select Label in the pull-down, leave the color option alone and press next.
- Then select the asset to display. Use Vcc. Accept and see your control appearing on the Pinboard. You can drag it around.
- Now add a Chart for Vcc. Use the live chart type for 5 minutes of data.
- Likewise, you can do pins for Temperature and Humidity. Experiment with the options, and make a nice looking panel.