thesolarnomad / lora-serialization Goto Github PK
View Code? Open in Web Editor NEWLoraWAN serialization/deserialization library for The Things Network
License: MIT License
LoraWAN serialization/deserialization library for The Things Network
License: MIT License
Hi, great library, thanks for creating!
I'm working on a setup where used sensors may change over time, meaning a static decoding on the backend won't work. Searching for a solution I found things4u's message format - which isn't implemented anywhere.
The idea is to have 6 Bit prefixes announcing the type followed by a 2 Bit length field. The decode would read the first bite and may automatically add "temperature" or whatever as a dict key.
This would increase the message size by a single Byte per transported value but allows dynamic decoding.
A possible implementation could give the LoraMessage a parameter setting the use of opcodes, or not.
If you want to use the functions writeRawFloat()/addRawFloat(), you must install from the head of the repository, i.e. neither use the Arduino Library Manager nor install the library from the v3.0.1 archive.
hope you can :)
Hi,
I am testing with lora serializer-deserializer. Everything's work great.
The only thing I am missing is : a deserializer written in Java.
Can you provide one in Java?
Thank you
Fred
The serialization code looks perfect my project since it easily supports lat/long, but I want to deserialize on another Arduino. What do you recommend? Do you think its worth writing deserialization code in C, or should I use another library (https://github.com/francc/tinypacks/blob/master/README-TinyPacks.md maybe)?
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.
it's impossible to decode negative temperature values; the positive value is always returned.
don't know if its an error in the decode or encode function, or both. see this code:
const ls = require('lora-serialization'),
enc = ls.encoder, dec = ls.decoder;
const buf = enc.encode([-25.3], [enc.temperature]);
// { temperature: 25.3 }
console.log(dec.decode(buf, [dec.temperature], ['temperature']));
I am using LoraEncoder instead of LoraMessage, because a statically allocated buffer is perfectly fine for me.
Having a getLength() method would be greatly appreciated!
In my application, the data written to the buffer is configuration-dependent and I would like to avoid counting bytes in a second place.
I tried using Lora-serialisation to send GPD data from Node to TTN, but when I useencoder.writeLatLng(-33.905024, 151.26648);
data transmits but when I use encoder.writeLatLng((gps.location.lat(), 6), (gps.location.lng(), 6));
data dosen't transmits. am using
`
#include <LoraEncoder.h>
byte mydata[12];
void setup() {
Serial.begin(9600);
ss.begin(9600);
LoraEncoder encoder(mydata);
while (Serial.available() > 0)
if (gps.encode(ss.read()))
if (gps.location.isValid())
{
int32_t lt = -33.905024;
int32_t ln = 151.26648;
encoder.writeLatLng((gps.location.lat(), 6), (gps.location.lng(), 6));
}`
Please help me.
@joscha Is this library still active and relevant?
Hi Joscha. Great library. I noticed that not much has happened on this repo for a few years, is that because it was just so well written it doesn't need any improvements or has it faded from use?
I am trying to understand serialization and wanting to write a tutorial to use encoding and decoding on the Helium Network . This repo seems the best that I have found so far, easy enough to understand and looks useful. Any opinions?
Hi!
First off, thanks for the Library, works great on Arduino / ESP Side. However I have still troubles decoding the data on the TTN side.
For the uplink formatter I have got the example code as such:
function decodeUplink(bytes) {
data = {};
x = 0 // starting point
data.fPort = uint8(bytes.slice(x, x + 1))
return data
}
/* contents from src/decoder.js */
var bytesToInt = function(bytes) {
var i = 0;
for (var x = 0; x < bytes.length; x++) {
i |= +(bytes[x] << (x * 8));
}
return i;
};
...
However upon testing I am receiving the above error: TypeError: Object has no member 'slice' at decodeUplink (<eval>:5:32(15))
Does the bytes
object need to be converted first, in order to use slice()
or should I use it differently?
Thanks & BR :)
Release archive version v3.0.1 != library.properties version v3.0.0
Hello,
i really like this library and would love it another datatype: Boolean
It would be useful for stuff like "Battery Low: false/true" / "Something: on/off" / "Parking lot: occupied/free" and you could en/decode 8 Boolean datasets into 1 Byte.
message
.addBoolean(true/false);
At the moment i have to use the uint8 datatype and do the bitshifting "by hand", it would be great to have this inside the library. Thank you very much!
can you share a sample of serialization on lmic code?
we have detected a discrepancy in the library name written inside library.properties
LoRa Serialization
(with the capital R)
and the library name written inside inside the library manager index:
Lora Serialization
I think this is due to an error on our side when the library was registered in the library manager index (at the times this process was mostly manual).
Now we are about to introduce a change in the library manager that forbids the situation described above and the releases whose name differs from the name registered in the library index are ignored.
Is it ok for you to use the name LoRa Serialization
? If yes, the library will be re-published with the name LoRa Serialization
and the old Lora Serialization
will be removed from the index, in this case no action is needed on your side. In absence of an answer from you we will proceed with this proposal next week.
Thanks
See also: arduino/Arduino#7127
JOB 617 - 2018/01/15 15:43:20 Scraping https://github.com/thesolarnomad/lora-serialization.git
JOB 617 - 2018/01/15 15:43:21 Checking out tag: v2.1.0
JOB 617 - 2018/01/15 15:43:21 Release LoRa Serialization:2.1.0 has wrong library name, should be Lora Serialization
JOB 617 - 2018/01/15 15:43:21 Checking out tag: v2.2.0
JOB 617 - 2018/01/15 15:43:21 Release LoRa Serialization:2.2.0 has wrong library name, should be Lora Serialization
JOB 617 - 2018/01/15 15:43:21 Checking out tag: v3.0.1
JOB 617 - 2018/01/15 15:43:21 Release LoRa Serialization:3.0.0 has wrong library name, should be Lora Serialization
message
.addBitmap(false, true, false, true, false, false, false, false)
Returns less than 8 flags and the values seem to be offset.
In the decoder, you can currently do something like this:
const bytes = new Bytes(12);
const result = decoder.decode(
bytes,
[ decoder.latLng, decoder.unixtime ],
[ 'coords', 'timestamp']
);
// result is { coords: [/* lat */, /* longitude */], timestamp: /* unixtime */}
It would be great if we had something similar for the Arduino side, because currently it looks like this:
byte buffer[12];
latLngToBytes(buffer + 0, latitude, longitude);
unixtimeToBytes(buffer + 8, unixtime);
// byte has 12 define bytes
but ideally the user would not need to keep count of what position in the byte array the data is going to be written, e.g. it would be something like:
(pseudo code)
my_encoder = encoder(latLng, unixtime);
byte buffer[my_encoder.targetSize];
my_encoder.encode(buffer, latitude, longitude, timestamp);
Beautiful code, but a decoder also on .cpp would be very useful for generic usage.
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.