Hi,
I’m a quite new in this forum working with a raspberry pi 3 and iC980A SPI to make a concentrator in US Freq Plan. After figuring out how to make it work I found this part in the Applications where I must define a Codec or use the CayenneLPP.
With CayenneLPP everything go smooth, and my nodes send the data perfectly. But I have no idea about how to use Javascript to decode my custom payload. To introduce in the right way the problem I’ll detail it here:
- The payload is an array of values:
[a0, a1, a2, a3, a4, a5, a6, a7, b0, b1, b2, b3, c0]
Where:
Every value with the letter “a” represent a single sensor, same to “b” and “c”.
example of values:
[121, 164, 9, 110, 152, 213, 55, 244, 59, 55, 60, 61, 5] - The output wanted is an array for each group of values defined by me.
Example: (following the idea)
So, with this I would like to get:
a = { 121, 164, 9, 110, 152, 213, 55, 244 }
b = { 59, 55, 60, 61 }
c = 5
The problem is that I don’t know about Javascript at all. My question is: Can anyone help me to build the Javascript Codec Function to have an output like the above andd send it to InfluxDB?
The full idea is the next, just to share the project:
- Build a node with analog sensors to check the voltage in the line, the temperature of a DC motor and the RPM of this motor like this:
- Take several measurements in the line to check the stability (that’s why an array of values) of the line and if it’s necessary turn off the system to protect the actives.
- Take several measurements in the temperature to check it’s not overloaded.
- Take the average RPM in the interval between radio transmissions.
- Send the array of values (maximum 51 to complain LoRaWAN specs) to the LoRa Server and decode the data in the array.
- Push each array to an InfluxDB to visualize the state of the active and trigger alerts if an anomaly is detected or if a temperature is Higher than expected.
Hope you can help me, I’ll keep trying and digging to learn Javascript.
Thanks in advance! Regards,
Franco.
UPDATE 1:
After a few hours reading a little bit more and doing some test an fails I’ve got a way to solve my idea, here’s the code:
function Decode(fPort, bytes) {
var i;
var line_read_length = 32;
var temp_raw = [];
var rpm_raw = [];
var rpm = bytes[48];
for(i=0;i<line_read_length-1;i+=2)
{
line_raw[i] = bytes[i]+bytes[i+1]*256;
if(i<(line_read_length/2)-1)
temp_raw[i+line_read_length] = bytes[i+line_read_length]+bytes[1+i+line_read_length]*256;
}
return {"Voltage Line Data": line_raw, "Temperature Data": temp_raw, "RPM Data": rpm};
}
and this put in the uplink info the data like:
Voltage Line Data:
0: 492
1: 525
2: 545
3: 515
4: 491
5: 503
6: 540
7: 522
8: 493
9: 486
10: 523
11: 543
12: 507
13: 484
14: 503
15: 541
Temperature Data:
0: 10
1: 10
2: 11
3: 12
4: 10
5: 10
6: 8
7: 9
RPM: 0
Now the next step is to know how I must integrate this with InfluxDB to show it with Grafana