Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTN Encoder and Payload Format #24

Closed
coastalplain opened this issue Sep 17, 2019 · 5 comments · Fixed by #30
Closed

TTN Encoder and Payload Format #24

coastalplain opened this issue Sep 17, 2019 · 5 comments · Fixed by #30

Comments

@coastalplain
Copy link

Thank you for creating these functions for TTN decoding and encoding! I have the decoding functioning properly, and I cannot figure out the encoder on the TTN console.

For the decoder, I followed most of the images to end up with this code working correctly:

function Decoder(bytes, port) {
return decode(bytes, [temperature, humidity], ['temperature_C','humidity']);
}
//insert decoder.js below

Testing with hex 09 44 1D 0F as the Payload, it correctly gives the proper JSON output:
{
"humidity": 38.69,
"temperature_C": 23.72
}

When I try to setup the encoder, I cannot figure out the proper way to set it up on TTN, with or without the LoraMessage(encoder) convenience class. The following is what I am trying, with several variations I don't want to enumerate. The 'temperature_C',' humidity' are my variables on arduino.

function Encoder(object, port) {
return encode(object, [temperature, humidity], ['temperature_C','humidity']);
}
//lora-serialization/src/encoder.js
//lora-serialization/src/LoraMessage.js

The fields I am using are the JSON format from the decoder: { "humidity": 38.69, "temperature_C": 23.72 } and the error comes out as:
Internal error: Encoder threw error: TypeError("Values must be an array")

Thank you for your time.

@joscha
Copy link
Member

joscha commented Sep 18, 2019

hi @coastalplain , sorry I haven't had time to look at this yet in detail. The error message suggests that the setup is wrong, have you seen the images in the readme with the examples?

@coastalplain
Copy link
Author

coastalplain commented Sep 18, 2019

Hi @joscha: No worries, thank you for your time. edit: Yes, the images helped with the decoder. However, the TTN-side Payload Format encoder is currently my sticking point (to send downlinks). I have tried several options in the initial encoder function followed by encoder.js (I have also tried substituting function Encoder(json, port) with function Encoder(object, port). The eventual goal is to send a simple bitmap or uint8 to various ports to change node functionality.

image

I have the decoder working well:
DECODER on TTN
image

@joscha
Copy link
Member

joscha commented Sep 23, 2019

Just had time to look at this and I see the problem now. So the names of the fields are not actually sent over the wire in the encoder. If you look at the sample in the readme you can see:

var bytes = encode([timestamp, [latitude, longitude]], [unixtime, latLng]);

this effectively means:

  • encode an array of one unixtime and one latitude/longitude tuple (this is the , [unixtime, latLng]); part)
  • the value of the unixtime is: timestamp
  • the value of the latitude/longitude tuple is [latitude, longitude] (an array itself).

In your case the Encoder you wrote 1) doesn't actually use the json object to read the values from that you want to encode 2) uses the strings ['temperature_C','humidity'] as the encoder functions.

So this one would actually work:

function Encoder(object, port) {
  return encode([object.temperature_C, object.humidity], [temperature, humidity]);
}

// encoder.js follows:

with a sample payload of:

{ "temperature_C": 10, "humidity": 20 }

however I just tried the TTN console to run it and I am getting a ReferenceError("'Buffer' is not defined") - it seems that TTN has dropped Buffer support maybe?

@joscha
Copy link
Member

joscha commented Sep 23, 2019

I posted in the TTN forum to see what happened there: https://www.thethingsnetwork.org/forum/t/buffer-not-defined-any-more/30168/1

@coastalplain
Copy link
Author

Thank you; I will keep an eye on the TTN forum, and try to research the 'Buffer' is not defined error.

joscha added a commit that referenced this issue Jan 15, 2020
fix: remove dependencies on Buffer (#24)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants