Introduction
Forewords
Register ATIM ACW-DUINO on TTN
Configure RTU mode
Wire sensor to ACW-DUINO
Integration to AllThingsTalk
Decode payloads on AllThingsTalk
View measures
Introduction
In this story, we visualize measures provided by a cheap soil moisure sensor.
Measures are acquired by an ATIM ARM-N8-LW LoRaWAN module without any additionnal arduino, nor raspberry,...
Payloads are periodically uplinked by the device to AllThingsTalk via The Things Network, to be decoded and viewed.
Forewords
We use a cheap capacitive soil moisture sensor.
Its electrical conductivity depends of humidity of the soil.
The french ATIM LoRaWAN module ARM-N8-LW can be controled :
- either by AT commands throw RX and TX pins (from an external CPU card)
- or in a standalone mode, named "Ready To Use" (without any additionnal CPU).
This "Ready To Use" mode is used to monitor our sensor.
In this mode, the ATIM ARM-N8-LW sends frames either on input event or timer event.
3 digital inputs, 1 analog input, and 1 counter input are available on the ATIM module.
In RTU mode, each uplink payload contains input values (digital inputs, analog input, and counter value).
NB : Analog voltage is converted to word value throw an internal 12 bit ADC
ATIM provides shields that include this ARM-N8-LW module : ACW-MANGOH, ACW-SDK, ACW-MPCIE, ACW-USB, ACW-XBEE, ACW-DUINO (for arduino), ACW-RPI (for Raspberry),...
We use a ACW-DUINO shied, because some ACW-DUINO pins are wired to inputs of the ARM-N8-LW module (on connector P7).
Have a look at ATIM website.
ACW-DUINO shield : http://www.atim.com/en/produits/catalogue/shields-modules/radio-module-arduino-acw-duino/
ARM-N8-LW module, embedded on the shield : http://www.atim.com/en/produits/catalogue/rf-modules/radio-module-lorawan-arm-n8-lw
NB : in another story, we use ATIM ACW-XB with Raspberry Pi : https://www.thethingsnetwork.org/labs/story/using-codesys-on-raspberry-pi-to-poll-modbustcp-slave-datas-and-uplink-them-by-using-lorawan-atim-acw-xb
Our Soil Moisture Sensor is connected to the analog input ADC0 of the ACW-duino shield.
Uplink frames are forwarded to AllThingsTalk to be decoded and visalized.
AllThingsTalk website : https://maker.allthingstalk.com
Register ATIM ACW-DUINO on TTN
With recently built ATIM device, EUI and Key are written on a paper provided with the device. On these devices, Keys cannot be read by AT commands
On older ATIM firmwares, EUI and Key can be read by AT commands :
Connect an FTDI to ACW-DUINO shield (VCC, GND, TX, RX) as shown on the following Fritzing breadboard view.
Connect FTDI to USB port of your computer.
On windows, open the device manager, and get the COM number used by the FTDI.
Start putty and open connection (speed 19200 bauds).
Press '+' key three times quickly to enter AT mode. Use commands to get LoRaWAN EUI and keys :
- ATO70 : DevEUI (Little Endian)
- ATO71 : AppEUI (Little Endian)
- ATO72 : AppKey (Big endian)
Warning : EUI are stored in Little Endian, but Keys are stored in Big Endian.
NB : there is a mistake on official documentation ATIM_ARM-N8-LW_UG_EN v0.4 p33
Connect to your TTN account
On your TTN account, create a new AppEUI : menu Application / your application / Settings
NB : don't forget to reverse bytes order on DevEUI and AppEUI, as they must be entered in big endian order.
For example : O071=040000A09BD5B370 => AppEUI=70B3D59BA0000004
Register your device on your TTN account.
On "App EUI", choose ATIM AppEUI : 70B3D59BA0000004
Power Off and On the shield (or send ATR command) to reset the module
Module performs an OTAA Join to TTN at boot
In order to test uplink to TTN, write the command AT$SF=123456 (for example)
NB : When pressing '+' key on putty (to enter AT mode), some payloads containing one byte 2B could be uplinked and appear on TTN
Configure RTU mode
Use ATO100=10 command to enable ADC0 and disable other unused inputs
Configure periodicity (for example 1') : ATO120=1
Save ATO parameters to EEPROM : ATOS
Enable RTU : ATM1=13
Save ATM parameters to EEPROM : ATMS
Restart the device. Frames should be automatically uplinked to TTN
An RTU payload contains at least 9 bytes. Ex : 3210FFFFFF000003C8
- Byte n°0 must be 32(h)
- Byte n°1, when set to 10(h) means "periodic emission"
- Three bytes FF(h) means that digital inputs DI0 to DI2 are disabled
- Word 0000 is the counter value
- Last word is our analog input value (12 bits) : 03C8
Wire sensor to ACW-DUINO
Connect Soil Moisture Sensor to ADC input, and add a 1M resistor, and a power source (3.3 V to 3.7 V) as shown on the following Fritzing breadboard view.
Connect RX to GND, and Sleep (active at low level) to VCC.
Insert the sensor into the soil. Measured values should be uplinked.
Integration to AllThingsTalk
On TTN, click on "Add integration", and choose "AllThingsTalk Maker"
Write your "Process ID" name, and choose one of your access keys.
Create an account on https://maker.allthingstalk.com
On your account, create a "ground". This "ground" contains your project on AllThingsTalk.
Create a device in your "ground" by clicking on "Connect a device".
Choose "Your own LoRa".
Choose "The Things Network"
Enter your Device name.
Enter your TTN Application ID and Device EUI
NB : Keys are not required
Decode payloads on AllThingsTalk
On your device, click on "settings" and then "Payload formats"
Check the box "Use ABCL to convert custom binary data" and copy the following JSON ABCL code into the textbox :
{
"name": "RTU",
"comment": "Decode RTU ATIM Uplink Frames",
"version": "1.0",
"author": "BQ",
"sense": [
{
"switch": {
"byte": 0
},
"on": [
{
"case": 50,
"do": [
{
"asset": "RTUheader",
"value": {
"byte": 1
}
},
{
"asset": "triggerDI0",
"value": {
"byte": 1,
"bit": 7,
"type": "boolean"
}
},
{
"asset": "triggerDI1",
"value": {
"byte": 1,
"bit": 6,
"type": "boolean"
}
},
{
"asset": "triggerDI2",
"value": {
"byte": 1,
"bit": 5,
"type": "boolean"
}
},
{
"asset": "triggerCPT0",
"value": {
"byte": 1,
"bit": 4,
"type": "boolean"
}
},
{
"asset": "periodic",
"value": {
"byte": 1,
"bit": 3,
"type": "boolean"
}
},
{
"asset": "error",
"value": {
"byte": 1,
"bit": 0,
"type": "boolean"
}
},
{
"switch": {
"byte": 2
},
"on": [
{
"case": 0,
"do": [{
"asset": "DI0",
"value": "false"
}]
},
{
"case": 1,
"do": [{
"asset": "DI0",
"value": "true"
}]
}
]
},
{
"switch": {
"byte": 3
},
"on": [
{
"case": 0,
"do": [{
"asset": "DI1",
"value": "false"
}]
},
{
"case": 1,
"do": [{
"asset": "DI1",
"value": "true"
}]
}
]
},
{
"switch": {
"byte": 4
},
"on": [
{
"case": 0,
"do": [{
"asset": "DI2",
"value": "false"
}]
},
{
"case": 1,
"do": [{
"asset": "DI2",
"value": "true"
}]
}
]
},
{
"asset": "CPT0",
"value": {
"byte": 5,
"bytelength": 2,
"type": "integer"
}
},
{
"asset": "ADC0",
"value": {
"byte": 7,
"bytelength": 2,
"type": "integer"
}
}
]
}
]
}
]
}
For our purpose, the most important part is at the end of the JSON code :
{
"asset": "ADC0",
"value": {
"byte": 7,
"bytelength": 2,
"type": "integer"
}
}
In this code, asset "ADC0" is defined as the last word of the payload (bytes 7 and 8)
NB : ABCL language is described on AllThingsTalk web site : http://docs.allthingstalk.com/developers/data/custom-payload-conversion/
Click on the "Save" button below the the textbox and close the settings frame.
Click on "Create asset" button.
Enter "ADC0" (analog input value in the payload), and choose type "Integer"
On the next uplink, value of the asset is updated.
As ATIM device uses a 12 bits ADC, the value is between 0 and 4095.
Lowest is the value, dryer is the soil.
Click on "debug" to check ABCL decoding.
View measures
Choose "Chart" menu, and click on "Turn on" button to enable storage.
On "Assets" tab, click on and choose "View asset details".
Click on the pen and replace "ADC0" by another title for the asset. For example : Soil moisture value.
On Thursday, Soil Moisture Sensor was inserted in very dry soil.
On Friday morning, soil sensor was extracted from the first soil, and inserted in a wet soil.
Chart highlights charging curves of our capacicitive sensor which depends of humidity of the soil.