The Things Network, IFTTT, and BEYOND!

Stephen just shared a new tutorial: "The Things Network, IFTTT, and BEYOND!"



Connecting your Pycom Lopy4 or another LoRaWAN device to The Things Network is the first step toward fully realized IoT fun! You’ve connected your device to TTN, you’ve decoded your payloads and now you can see all that data right there i…

Read more

Hi Stephen,
Great tutorial! I have followed through but of course - it doesn’t work. I’m not getting data into adafruit.io
I have a few areas I suspect where things may be getting stuck, and would appreciate your thoughts or tips.
I have a RAK environment sensor sending barometer, humidity and temp.
Starting at TTN - I have payloads coming through fine;
I have a payload formatter that is displaying the values… here is the decoder;

// ttn application function to decode uplink data.

// Decode decodes an array of bytes into an object.
// - port contains the LoRaWAN fPort number
// - bytes is an array of bytes, e.g. [225, 230, 255, 0]
// The function must return an object
// for RAK, return {
// “DecodeDataHex”: {} // RAK5205 sensor data in Hex format
// “DecodeDataObj”: {} // RAK5205 sensor data object.
// }
// The function prototype cannot be modified.
function Decoder(bytes, port) {
var decoded = {“DecodeDataHex”: {}, “DecodeDataObj”: {}};
var hexString=bin2HexStr(bytes);
decoded.DecodeDataHex = hexString;
decoded.DecodeDataObj = rakSensorDataDecode(hexString);

return decoded;
}

// convert array of bytes to hex string.
// e.g: 0188053797109D5900DC140802017A0768580673256D0267011D040214AF0371FFFFFFDDFC2E
function bin2HexStr(bytesArr) {
var str = “”;
for(var i=0; i<bytesArr.length; i++) {
var tmp = (bytesArr[i] & 0xff).toString(16);
if(tmp.length == 1) {
tmp = “0” + tmp;
}
str += tmp;
}
return str;
}

// convert string to short integer
function parseShort(str, base) {
var n = parseInt(str, base);
return (n << 16) >> 16;
}

// decode Hex sensor string data to object
function rakSensorDataDecode(hexStr) {
var str = hexStr;
var myObj = {};
var environment = {};

while (str.length > 4) {
var flag = parseInt(str.substring(0, 4), 16);
switch (flag) {
case 0x0768:// Humidity
environment.humidity = ((parseShort(str.substring(4, 6), 16) * 0.01 / 2) * 100).toFixed(1) + ‘% RH’;
str = str.substring(6);
break;
case 0x0673:// Atmospheric pressure
environment.barometer = (parseShort(str.substring(4, 8), 16) * 0.1).toFixed(2) + “hPa”;
str = str.substring(8);
break;
case 0x0267:// Temperature
environment.temperature = (parseShort(str.substring(4, 8), 16) * 0.1).toFixed(2) + “°C”;
str = str.substring(8);
break;
case 0x0188:// GPS
var gps = {};
gps.latitude = (parseInt(str.substring(4, 10), 16) * 0.0001).toFixed(4) + “°”;
gps.longitude = (parseInt(str.substring(10, 16), 16) * 0.0001).toFixed(4) + “°”;
gps.altitude = (parseInt(str.substring(16, 22), 16) * 0.01).toFixed(1) + “m”;
myObj.gps = gps;
str = str.substring(22);
break;
case 0x0371:// Triaxial acceleration
var acceleration = {};
acceleration.x = (parseShort(str.substring(4, 8), 16) * 0.001).toFixed(3) + “g”;
acceleration.y = (parseShort(str.substring(8, 12), 16) * 0.001).toFixed(3) + “g”;
acceleration.z = (parseShort(str.substring(12, 16), 16) * 0.001).toFixed(3) + “g”;
myObj.acceleration = acceleration;
str = str.substring(16);
break;
case 0x0402:// air resistance
environment.gasResistance = (parseShort(str.substring(4, 8), 16) * 0.01).toFixed(2) + “KΩ”;
str = str.substring(8);
break;
case 0x0802:// Battery Voltage
myObj.battery = (parseShort(str.substring(4, 8), 16) * 0.01).toFixed(2) + “V”;
str = str.substring(8);
break;
case 0x0586:// gyroscope
var gyroscope = {};
gyroscope.x = (parseShort(str.substring(4, 8), 16) * 0.01).toFixed(2) + “°/s”;
gyroscope.y = (parseShort(str.substring(8, 12), 16) * 0.01).toFixed(2) + “°/s”;
gyroscope.z = (parseShort(str.substring(12, 16), 16) * 0.01).toFixed(2) + “°/s”;
myObj.gyroscope = gyroscope;
str = str.substring(16);
break;
case 0x0902:// magnetometer x
var magnetometer = {};
magnetometer.x = (parseShort(str.substring(4, 8), 16) * 0.01).toFixed(2) + “μT”;
magnetometer.y = (parseShort(str.substring(12, 16), 16) * 0.01).toFixed(2) + “μT”;
magnetometer.z = (parseShort(str.substring(20, 24), 16) * 0.01).toFixed(2) + “μT”;
myObj.magnetometer = magnetometer;
str = str.substring(24);
break;
default:
str = str.substring(7);
break;
}
}
if(Object.getOwnPropertyNames(environment).length > 0) {
myObj.environment = environment;
}

return myObj;
}

Here is an example of the decoded payload from inside the data tab of my device on TTN;

{

“DecodeDataHex”: “0802016a076855067327540267011d0402077b”,
“DecodeDataObj”: {
“battery”: “3.62V”,
“environment”: {
“barometer”: “1006.80hPa”,
“gasResistance”: “19.15KΩ”,
“humidity”: “42.5% RH”,
“temperature”: “28.50°C”
}
}
}

I have a few variables coming through but only want 3 (Humidity, Temp, Air Pressure), 4 actually - Battery voltage.
For now I’ll be happy with 3. I did read somewhere late last night about a need for the decoder to have a trigger flag that would let IFTTT know new data has appeared… as I don’t see any activity in IFTTT, i think I am stuck around here somewhere…
Here is my config from TTN… my key was copied from IFTTT

In IFTTT I dont see any activity…

Should these value fields be ‘value 1,2,3’ or should they be the names I defined in ttn? temperature humidity air pressure? Perhaps this isn’t connected correctly to pull those variables names…

Anyway something is probably wrong with my decoder or a trigger between TTN and IFTTT…
Thoughts? Tips?

This has been a great tutorial for me and my high school students. We want to use Adafruit IO for our sensordata, but now, with TTN v3, the IFTTT integration paart in this tutorial is no longer available. Have you guys found a way to tackle this, and can thus update the tutorial, because we love TTN->IFTTT->AIO!