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 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:

Hi Ignacio,
Thanks for reply. Yes, I’ve checked the documentation and in the measurements in the InfluxDB I see the RPM but I have no way to make the same with the other objects, because I get an error message in the lora-app-server log where it seems it can’t handle an array of values.
So, just to update the situation, I have done with the integration and I’m having problems to send an Array of values to the InfluxDB. If anyone know how to do this, I’ll appreciate the help.
Thanks in advance.

I don’t believe you can store an array in InfluxDB. I have to look into this what LoRa App Server does in this case (I don’t think this is handled), but potentially it could store this as measurement_name_INDEX, thus turning a temperature: [20, 22, 21] into temperature_0 = 20, temperature_1 = 22, … You could also do this in the custom JS function.

Thanks for reply. I’m checking the code inside Influx handler and I figure it out, it can’t handle arrays of values, so I must modify this to make it work, so I have 2 options:

I modify the Go file, to make a case when it get an array and make it push one by one to influx

Send it as you said, tagged values and then check how to make the Grafana side shows them in order and in the right way.

But for now I’m reading how to build from sources the lora-app-server to try to modify the Go file, so probably I’ll post in the github if I have some problems, at the moment I have problems to build from sources after I have a running app at the moment.
Thanks for help, and any suggestion about will be welcome.

Okay, finally with a solution for this problem.
What I’ve done is not exactly the best solution but it’s the simplest.
If you don’t want to mess with the Go code, what you can do it’s take the data and convert the payload in String where you “tag” the measurements and when it’s done, the integration will push the data to the influx in different tables. The code here:

Well, to do this I implemented a python code to read, i.e. all the data of VAC (voltage line sensor) from an specific Device and put it in the right order in another measurement DB with the same DevEUI tag. An example of code to do this in python 3 is:
import time
from datetime import datetime
from datetime import timedelta
import pytz
from influxdb import InfluxDBClient

The code just use the InfluxDB python client API with the datetime objects to write in this case a json formated value collecting 256 measurements with the same tag in 16 different tables to put the all together and it runs as a service every 5 minutes when it’s expected to have around 256 values some of them new and some other olders. After that you can improve the query if you want, like if you want the last 256 or wait for new values, or maybe add a drop of the data after collecting it to the new one.
Anyway, I think it’s quite enough to give some idea to someone with the same problem, and it need to be improved for a better performance.
Suggestions are welcome, and I repeat, this is NOT the best way to solve this. I’m working with the Go file, but without success yet.

I’d encourage you to do it directly from lora-app-server using a Go client, but if you’re more comfortable with Python or don’t wanna get into the source, I think at this point it’s better to just use the HTTP integration to get your data out. In this way, you can have your Python service receive the data, format it in whatever way you need and then insert into InfluxDB, keeping the data simple and with the needed measurements only.