Hello everyone
I’m quite new to TTN and AWS and have been struggling with the following issues for weeks now.
I try to be as specific as I can so excuse me if the post gets a bit long.
Situation:
I’m using the Things Stack Community Edition and am recieving data from my edge device.
So far so good. Data comes in to The Things Stack and I can format the payload:
function decodeUplink(input) {
var reserved = input.bytes[0];
var parkState = input.bytes[1];
return {
data: {
parkState: parkState,
state: {
reserved: reserved
}
}
}
}
Decoded payload looks good to me:
"decoded_payload": {
"parkState": 0,
"state": {
"reserved": 0
}
}
Switching to AWS. I subscribe (with MQTT Test Client) to the lorawan/+/uplink
topic to test if the data is recieved.
No problem JSON data is coming in as already seen in TTS.
I also want to send data down to the edge device, for this I have a payload encoder in TTS.
function encodeDownlink(input) {
return {
bytes: [input.data.reserved]
}
}
Works like a charm if I publish it in AWS (with MQTT Test Client) with the following message payload to the lorawan/downlink
topic (LED on edge device changes state as planned):
{
"thingName": "myproject_mything",
"payload": {
"reserved": 0
}
}
Problem:
I want to combine these capabilities using the device Shadow in AWS.
I have no idea how I can edit the shadow so that my uplink message gets written in to the shadow.
On the contriary I want to be able to change the desired state to trigger a downlink message to change the “reserved” value 0 or 1.
The shadow doesn’t contain my payload, and a lot of uneccesary data I don’t need.
lorawan shadow on the thing in AWS IoT Core:
{
"reported": {
"activated": "2021-04-27T15:28:44.976761797Z",
"lastSeen": "2021-04-27T19:58:58.851973028Z",
"gateways": 1,
"sessionID": "asdfasdfasdf==123123",
"fCntUp": 1534,
"fCntDown": 0,
"devAddr": "XXXXXX",
"rssi": -109,
"snr": 2.5
}
}
But I want something like this:
{
"desired": {
"reserved": 0
}
"reported": {
"reserved": 0
}
}
Maybe this is simple for someone of you guys but I’ve done a lot of research and experiments and haven’t found a solution. Maybe I’m looking to far. If you need more information I’m happy to provide you with that.