I want to display the data of an IoT sensor on the Losant control panel. The motherboard communicates with the Hologram through a cellular connection. From there, it sends the data to Losant via a Webhook.
The problem starts there because the device is already using a JSON template to identify and send data to the Hologram server. The data cannot be a newer JSON string, as it disrupts the original encoding on the Hologram server. Useful data can only be something like this:
Temp:27.34; Battery:3.6; Loc:47.45623, 19.67234
It contains data from several sensors that Loszant no longer interprets in this form because it is not JSON encoding.
Of course, I can put it in a suitable format in the Hologram message, but the data still looks like this:
{Temp:27.34; Battery:3.6; Loc:47.45623, 19.67234}
How can I set up the webhook on Losant so that it continues to transfer the data properly in JSON:
One option would be to have your device (or the Hologram platform, if possible) encode the JSON string as Base64. The Base64 string can then be added to the outer JSON object.
In Losant, you’d use the Base64 Decode Node followed by the JSON Decode Node to turn it into an object on the payload.
oh yeah, the screw in it is that the device already handles sending data in BASE64, so it translates everything into BASE64. I can’t even change this part from a program because it’s included in the base API. Then the entire BASE64 data set is converted back by Hologram so that the useful data is already displayed in decdata if I want. Or you can transmit in BASE64, but I can’t add useful data in BASE64
I just can’t write a character in the payload ("").
I would have to send the useful data in some other form that Losant can also interpret and manage.
I’ve been thinking about CSV, but I don’t know how to handle it.
What would be the right string.
I’m a little confused where to go.
CSV would also work - there’s a CSV Decode Node. It doesn’t really matter how the data is reported, as long as you can get the values on the payload. The Device: State Node, which would ultimately be used to save the data to device attributes, can pull values from anywhere on the payload.
Can you give me a simple example code for this?
I would now test these 3 sensors.
Currently I can handle an example JSON message:
{“Tem”: 26.7, “Battery”: 3.67, “Loc”: “49.25567, 18.09893”}
What CSV data set should I send to the Webhook?
How do I set the CSV node to receive it (Device: status)?
What CSV data set should I send to the Webhook? That is really up to you and what you want to record as the device state data.
How do I set the CSV node to receive it (Device: status)?
In order to accomplish this you would send the webhook a string of CSV data and then you would use the CSV: Decode Node to turn your data from CSV into JSON objects which can then be sent to the Device: State Node. The way you are using the device state node currently is by mapping the individual fields on a payload to your device state fields, if you’re CSV has multiple device states consider using a payload path to pass in your device states. The catch with using payload path is that your attributes will need to be named correctly on the objects given.
If I send this in CSV, what would be appropriate?
This is currently being sent by the device:
Tem: 26.7, Loc: 47.28519, 19.06179, Battery: 3.67
Can be varied:
For example, Tem = 26.7, or Tem, 26.7; it would only be nice to know what is easiest to set up in Losant.
Currently, if I send a non-JSON format to the Webhook, it will return an error.
Server sent HTTP status code 400 with body: {“statusCode”: 400, “error”: “Bad Request”, “message”: “Invalid request payload JSON format”}
So I asked how to set up the Webhook trigger to receive CSV.
Could you give an example of this (useful route) just how it works?
It has multiple device states at once, which can be separated by (,) (;). I would just like an example setting so I have little idea how to proceed.
If you want to send a CSV, you can send it in many different formats and specify the configuration via the CSV: Decode Node like the record delimiter (by default is a newline character (\n)), delimiter, quote and escape. We try to keep most of our nodes allow different configurations to fit different users needs. The only requirement for a CSV is that the first line is the header line and the following lines are the records. I.E.
Tem,Loc,Battery
26.7,'47.28519,19.06179',3.67
So if I wanted to send this as a body on a webhook I would do something like the following…
If you want to want to send this data in the body then yes it must be in the valid JSON format. If you want to send this as a simple string you could put it on a query param, however you may end up reaching the query param length limit depending on the length of your CSV string.
After that I would set up a workflow like the following,
I would use the webhook tester as seen above to actually trigger my workflow down here and view the payload path to make sure the data is being parsed correctly. You can use the debug node at any point to view the payload.
thanks for the help, i was able to set the CSV codes. The example code also helped a lot.
I had trouble with it because the Hologram was less supportive, but I ended up resolving it.
I have another question, maybe there is a solution at Losant.
GPS coordinates are sent by the device in one (DMM) format by default. (format: ddmm.mmmmmm N / S, dddmm.mmmmmm E / W)
Losant handles the (DD) format for location data that can be displayed on the control panel (format: (-) dd.ddddd, (-) ddd.ddddd)
Is it possible to convert location data from DMM to DD and send it to (device: status)?
You should try using our formatGps template helper that can be found in our format helpers. You can use the template tester on the workflow to play around with any of the format helpers you may need to use and you can utilize your debug messages or example payload from triggers.
Hope this helps get you a step closer to your solution,
Erin
I looked at the formatGps format helper.
It looks good although I may not recognize this particular format but I can try it.
My question is, where can I use this helper?
In Device: state, I use custom fields, such as
for temperature {{stateData.0.Tem}}
and {{stateData.0.Loc}} for location data
No useful route is specified at the end, the values are displayed directly in the dashboard.
I’d like a few more nodes for that later, but only if the data is already displayed correctly, at least in the control panel.
I also looked at the fact that formatGps returns the decimal value by default, so you don’t have to specify another format.
It basically looks like this:
{{formatGps gpsStr formatStr precision}}
Do you know a sample for this, where to put the template, and how to format it to use location data on {{stateData.0.Loc}} output?
Where would you do it? Need a new node?
These handlebar format helpers can be used in any field that takes a template, so you should be able to use it directly in the device: state node if you are using individual fields or a json template to set the device state. If the device state is being saved properly are you sure you need to convert the data?
I would also suggest that you run through some of these Losant University courses. It will go over a lot of these basic concepts and help you understand how each area of Losant works and then fits together as a whole.
ok i am trying to use it in the status node.
I need the conversion because what I sent earlier is just test data, not device data.
Yes, I am constantly learning Losant. I try to adjust to it and come up with knowledge.
Thanks for the help, they always take me forward.
When I use a specific case that needs a lot more attention anyway, it arouses interest!
Based on your screenshots you should be accessing your Loc attribute like this {{ stateData.[0].Loc }} without the brackets around the index you are trying to access this wont work. In order to use the handle bars helper you would simply write {{ formatGps stateData.[0].Loc }}. Any of these handlebars helpers can be used in fields where templates are allowed.
However, looking at what you have for your given data, the format GPS data will not help as your data is no longer a valid GPS format. You will probably have to use either a combination of the math node, the mutate node and the string nodes to transform the latitude and longitude into a decimal format. I found the conversion example online from this format into decimal and built a small workflow to show you how this can be done. And you should be able to apply the same logic to your workflow.
oh yeah i tried this solution too, albeit a little differently. Did not work.
(0) works because it is a path
not a key, but I’ll fix it.
yes i was also thinking of needing a node here for this conversion.
I’m also trying to convert the DD format from a program on the device side. One just works.
thank you for your help, i will review the document and then indicate what has been achieved.
You’re trying to import that file as an Edge Workflow, but it is actually an Application Workflow, hence your error. Instead, try importing it into the “Application Workflows” list at the top of the page.
What is obvious is that there is no conversion, the value is empty or 0 everywhere.
It seems to me that the string does not pick up the Loc data from the csv, even though it is in (stateData. [0] .Loc).
I did something wrong, even though the process is copied
do you have any idea what’s wrong?