[Solved] Workflow global is not populating when triggered from a field device

#1

Im sure I am missing something simple here but I have banged my head too long on this one. I set up a workflow-level global variable, “geolocation” that stores a lat/long string. When I trigger the workflow using the debug button, it populates correctly and the value shows in my dashboard. However, when I post data from my actual field device, the value is not showing in the dashboard. I can’t seem to find anything in the docs regarding this scenario. Am I missing something?

Thanks,

Todd

1 Like

#2

Hi Todd,

I may need a bit more information from you to help solve your problem. Is it that the global variable disappears from the dashboard, or is it not displaying the correct geolocation string that was given by the field device? If that is the case, it sounds like you are using {{ globals.geolocation }} instead of accessing the data from the payload of the device data coming in. On the virutal button node you can add a fake payload data, e.g. { geolocation: 'lat/long' }, and access that data by { data.geolocation }.

If this is not your issue, can you send me some screenshots as to how you are accessing your data on the workflow?

Hope this helps,
Erin

0 Likes

#3

Thank you for responding, Erin!

I am not actually setting the geolocation value in the device as I figured I could set it in the globals. the json string I send is as follows:

{"data":{"axav":0.03,"axmn":-0.25,"axmx":0.08,"ayav":-0.08,"aymn":0.11}}

I tried the following as a longshot hoping it would work but that got me a 400 error:

{"data":{"axav":0.03,"axmn":-0.25,"axmx":0.08,"ayav":-0.08,"aymn":0.11},"globals":{"geolocation":"test"}}

The value shows up fine when I debug the workflow, but it doesnt wind up in the payload in the end when I send the data from the field device. (I think Im doing something wrong but cant figure out what.)

0 Likes

#4

Hi Todd,

It doesn’t seem like you are triggering your webhook properly. I can tell because you are trying to access your data from the webhook by { data.axav }, and if it was reported through the webhook the data would either come in the query field or the body and would need to be accessed like { data.body.axav } or { data.query.axav }.

So here is how I would test a webhook, and hopefully, this helps you solve your issue.
I would first open 3 tabs, one on the workflow page, one of my device and one of the webhook, so you can see all the debug data coming in through the workflow and you can see the state data sent to your device in real time.

Here is my workflow, and I set up a Virtual Button with fake data like the webhook might send.

And here is what my device state node looks like:

After clicking the virtual button this is the log that came through on the device:

Here I can simulate a webhook request on the losant app or you could use Postman or Curl to post to the given link that was generated when creating the hook.

Here you can see in the debug log how that comes through in the workflow:

And here is the output on the device log:

I hope this helps you to better debug the issue you are seeing. If you are still stuck, please send me instructions on how you are triggering that webhook.

Thanks,
Erin

0 Likes

#5

I think we are closer… I set it up the way you mentioned and clicking the debug button on the webhook still populates the data correctly. Here is the data that came through

I saw that the “geolocation” element is in there so that lead me to believe I needed to add it to the json payload Im sending from my field device like so:

{"data":{"axav":0.03,"axmn":-0.25,"axmx":0.08,"ayav":-0.08,"aymn":0.11,"aymx":0.35,"azav":0.98,"azmn":0.92,"azmx":1.03,"geolocation":"-43.8655,95.8765"}}

I still have the geolocation pulling from the globals in the workflow as seen below, but (while the correct global value is saved when I click the debug button) sending the json with the geolocation to the device just ignores the global value and puts in the string I send from the field device.

Going back a step, I am posting my json payload to the device via the url:

https://api.losant.com/applications/XXXXXXXXXXXXXXXXXXXXXXXX/devices/XXXXXXXXXXXXXXXXXXXXX/state

Is that correct for this type of application?

0 Likes

#6

So a webhook URL would look like this https://triggers.losant.com/webhooks/XXXXXXXXXXXXXXXXXXXX. It is located on the webhooks list page, next to its name. This API endpoint https://api.losant.com/applications/XXXXXXXXXXXXXXXXXXXXXXXX/devices/XXXXXXXXXXXXXXXXXXXXX/state will trigger a Device: State Node, which you can use to solve your problem. And you can get rid of the webhook altogether if you choose to use this solution instead of using the webhook.
You will want to use the device state node to trigger the workflow, then add a conditional node, that checks to see if gpsString has been set. If it has not been updated add it to the payload, then push the new state to the device. You will need that conditional otherwise you will cause an infinite loop.

Hope this help :smiley:,
Erin

0 Likes

#7

Ok, that is making sense. From a production perspective, which would be the better route? webhook or device state node?

0 Likes

#8

Since you are trying to append to the state I would use the webhook for this, to make it less confusing, and you will never accidentally create an infinite loop. If you start sending the GPS location of your device from your device, then I would use the API endpoint to set state directly.

Thanks,
Erin

0 Likes

#9

Great. Looks like its working fine now! Thank you for the help!

0 Likes