Developed by Mathworks (best known as the creators of MATLAB®), ThingSpeak is “an Internet of Things (IoT) platform that lets you collect and store sensor data in the cloud and develop IoT applications.”
A lot of IoT devices can push data to Thingspeak (including but not limited to Arduino, Raspberry Pi). The gathered data can be analyzed online, using MATLAB ®.
Unfortunately, this doesn’t come free. There’s the option of a free account for testing and small non-commercial projects. A student license starts from 55 EUR. Home use licenses start from 75 EUR. Academic and commercial licenses are also available.
In this blog post, I will use a free license, as for the given moment I have no further plans to use ThingSpeak.
If you already own a MathWorks account, you can use it to connect also to ThingSpeak. Otherwise, create an account first..
Once you log in, you can check your account settings. Mine is a free account.
To publish data to ThingSpeak, one must create a channel. To do so, go to Channels — My channels and create a new channel.
The new channel is named Dragino_LoRa and has two fields, for temperature and humidity. I didn’t fill any additional data (position and such) as this is for testing purposes only. I’ve left the channel private, for the given moment.
Once the new channel is created, we have the API keys:
Write down the Channel ID and the Write API Key. You will need it later when you configure the gateway.
Configuring the LG01-S LoRa gateway
The second part of this tutorial is dedicated to the configuration of the LG01-S gateway. Here I will configure the gateway to work with my local WiFi network, and I will upload the Arduino sketch for the ThingSpeak server.
When powered on for the first time, the LG01-S starts as an unsecured WiFi access point. Connection to LAN port is also possible. In either case, the gateway acts as a DHCP server, with its IP set to 10.130.1.1. To connect use user: root and password: dragino.
To configure it to run as a WiFi client I had to go to Network the — Internet Access menu. Then I’ve set it as a WiFi client, and I’ve configured it to use a static IP address.
Please observe that, regardless of the WiFi settings, the LAN settings remain the same, as in the picture below. so, if we mess up with the WiFi settings, there’s always an easy way to recover the gateway.
If everything is OK, the LG01-S will connect to the WiFi network, and we can see a status screen link this:
Once we are connected to WiFi, we have to load the LoRa server Arduino code. As a prerequisite, go to Arduino — Preferences — Additional Boards Manager URLs and install the LG01S board definitions from http://www.dragino.com/downloads/downloads/YunShield/package_dragino_yun_test_index.json. Go to Sketch — Include library — Manage libraries and install the ThingSpeak library. Download the RadioHead LoRa library and extract it to your libraries folder.
In Arduino Ide, select Arduino Uno — Dragino Yun board. Select your board IP for the communication port (all code uploads are made via OTA).
Load the LoRa_Simple_Server_Yun code example. In the code, replace your channel ID and API Key data. Compile and upload the code.
If everything goes OK and we have no errors, then we can proceed with the node.
Lora node using Dragino Lora shield
The node (client) is made using one Arduino Uno, the Lora shield from Dragino, and one DHT11 sensor. I’ve found the code example to work only with DHT11, and not with DHT22. I left it like this, as I have a DHT11 in my part collection. However, as future work, I might change the code to work with the more precise DHT2.
The node looks just like this:
As for programming, in Arduino IDE just select Arduino Uno as your board, then select the appropriate COM port. Take the code example, compile and upload it. You’re ready to go. If you open the serial monitor, you should see something like this:
Humidity and temperature
Current humdity = 33.0% temperature = 22.0C
got reply: Server ACK
Current humdity = 34.0% temperature = 22.0C
got reply: Server ACK
At this point I the gathered data can be displayed on ThingSpeak, and it can be further analyzed using Matlab:
A few final thoughts
The LG01-S LoRa gateway comes with a very good documentation. I was able to set the whole thing (gateway and node) in less than an hour.
The code is quite simple, thanks to the well-written libraries. It’s easy to understand it, and also to change it to accommodate other sensors.
ThingSpeak looks nice, and if you wish to go beyond displaying your data and you want to analyze it using Matlab, then paying for a license might worth it.
Future work? There are many things I wish to do. First, I want to see if I can make my LoRa click boards work with the DG01-S gateway. Second, I plan to see if I can publish data to other services. Maybe even logging data in my own MYSQL database…
[Update — April 12, 2019] When using firmware version IoT-4.3.6 with the LG01-S gateway, sometimes the packet forwarder service is not enabled.
This affects both Thingspeak and TTN services.
You can check this by going to the Status -> Processes page. If you don’t see the /etc/iot/scripts/lg01_pkt_fwd process running, then you will have to configure it manually.
You do so by going to the System -> Startup page, scroll down until you reach Local startup, and make the following changes:
# Put your custom commands here that should be executed once
# the system init finished. By default this file does nothing.
Save the settings and restart the gateway, and you should have the packet forwarder running.
Originally published at https://electronza.com on April 7, 2017. Moved to Medium on MAy 3, 2020.