Device State Node refresh

In a workflow there is a delay node used for 10 seconds at some node point. This workflow is triggered by a virtual button press (via api on the user GUI frontend). But at the end of the workflow there is Device State Node which gets set indicating which button was pressed.

I have 3 button press actions invoking the same workflow.

The problem I am facing is … on the first button press, Device state is shown OK saying first button was pressed. However, on a second button press, it does not. on a third button press, it indicates the second button was pressed and and on the first button press again, it shown that third button was pressed.

If I do not have the delay node in the workflow, each button pressed gets indicated perfectly.

Not sure how to resolve the issue

Can you please send us the URL of the workflow so we can take a look?

here is the url of the workflow. Please look for the delay node and follow the path. At the end is a device state set , which shows which button was pressed on the UI to invoke the workflow.

https://app.losant.com/applications/626f68d0f25acc8bc3edd6c8/workflows/62dab95733f832701378e0c4/develop

I introduced this delay because there seems to be a delay in updating the table rows down the path and this was causing problems in the UI front end. On the UI front, buttons are getting pressed soon one after the other.

Thanks, but I am a little confused …

  • This workflow only has one Virtual Button in it; I got the impression from your description that there were multiple Virtual Buttons and one of them was being chosen to fire in your user interface?
  • I see the Delay Node, but there are several Device State Nodes that can follow it, all at the end of different Switch Node and Conditional Node branches.
  • The Delay Node is set for delay 12 seconds instead of 10 as you originally indicated.

Based on all of that, are you sure this is the correct workflow? If so, I am going to need more information to understand the issue.

Other notes:

  • You appear to be storing device telemetry data in Data Tables, which we do not recommend. Doing so does not expose those values to time series queries, data aggregations, and all the other benefits of writing these values to a time series database.
  • You mentioned that you added the Delay Node “because there seems to be a delay in updating the table rows down the path and this was causing problems in the UI front end”. But the Delay Node you added comes before all the table manipulation nodes; so wouldn’t the addition of that node make the problem worse?

I think I will need you to PM me a link and instructions for how to trigger this case in your UI before I can be of any more help.

Thanks Dylan for looking into this.

On the UI (Android application), I have 3 buttons and each button invokes the same virtual button.

Button 1 json input
{
“action”:“save”,
“type”: “imp”,
“date”: “20/05/2023”,
“time”: “6AM”,
“timeOrder”:1,
“reading”:5351.97}

Button 2 json input
{
“action”:“save”,
“type”: “exp”,
“date”: “20/05/2023”,
“time”: “6AM”,
“timeOrder”:1,
“reading”:3202.56}

Button 3 json input
{
“action”:“save”,
“type”: “imp”,
“date”: “20/05/2023”,
“time”: “6AM”,
“timeOrder”:1,
“reading”:293262}

Along with the json, of course the “key” value is passed

On the UI, User clicks button 1 first -
a record is created in the table. Quickly completes the workflow and Device state,at the end of the workflow, indicates that “20/05/2023 6AM imp readings are saved”
value gets set in column “reading” in the table
while that is going on, Immediately clicks button 2.
Flow checks if there is a record in the table, so it tries to update that table row. (This is where I had seen table row creation was taking time from the first button click, and this second button action was adding a new row instead, which I did not want to happen. So I introduced a delay for 12 second. My mistake, it is not 10 as I had mentioned)
value gets set in column “readingExp” in the table
Device state, at the end of the workflow, DOES NOT SHOW UP ON THE UI. WAS expecting “20/05/2023 6AM exp readings are saved”
while that is going on, Immediately clicks button 3.
same action happens to update the same table row.
value gets set in column “readingSolar” in the table
Device state indicates “20/05/2023 6AM exp readings are saved”. This is from the button 2 click, which is not correct. It should have been “20/05/2023 6AM solar readings are saved”

Again, if the user clicks button 1 with a different value of reading as 3202.9, for example, workflow completes, device state indicates “20/05/2023 6AM solar readings are saved” instead of “20/05/2023 6AM imp readings are saved”. It is picking up the previous state

All thes table row updates on the table named “MeterReadingTemp

Hope this makes sense?

sorry, in 3rd button json, type is “solar”, my typo

So I’m still not entirely sure what is going on, because reading these payloads and looking at your workflow, I would expect all three of these to ultimately hit the Delay Node. You have a Conditional Node checking if {{data.action}} == "save" (which it is for all three payloads) and that branches into a section of your workflow where some data table lookups are done; there are no writes to the data table before potentially hitting the Delay Node.

Regardless, my recommendation would be to change your user interface: Instead of invoking a Virtual Button press, have it make an HTTP request to a webhook or experience endpoint. The primary reason is that when you invoke a Virtual Button, the request to do so immediately returns a { "success": true } response, regardless of if the workflow run has completed, stopped due to an error, or much less even begun execution.

By making a webhook / endpoint request instead, you can issue a custom reply to the request when you are ready to do so (using the Webhook Reply / Endpoint Reply Nodes). This not only allows you to provide feedback to your user on if the request was successful, but would also allow you to disable or queue any other requests made from your UI until the first one resolves.

I do have table insert and table updates at the end of that ’save’ workflow path.

I will try your suggestion. I need an example how to convert this workflow to a webhook

Thanks

Right, but those Insert / Update Nodes are executed after your Delay Node, correct? So the first, second, and third actions would all be subject to their own 12-second delays, unless they follow one of your other Conditional paths first (which appear to lead to errors being logged as device state).

Have you considered using Events to log those cases instead of saving them as telemetry data?

Let the delay be there. Question is why the last device state indicate the one previous one for each button pressed?

My guess is there is a race condition at play here; you said users are pressing one Virtual Button and then immediately pressing another. The Device State Nodes would not necessarily execute in the same order as the Virtual Buttons are pressed, especially with all the different branches, loops, delays, and operations taking place within this workflow.

That is the reason I added the delay node

I’ve cloned your application (though you removed the Delay Node before I could) and added three Virtual Buttons to your workflow, each with one of the payloads you posted previously. I have not been able to reproduce the issue we are talking about here so far; I am wondering if the Delay Node was causing some confusion as to which requests were associate with which button presses? That is the best theory I have at the moment.

For your own testing, I recommend you also add these buttons to your workflow; this makes it very easy to debug this flow from one interface and see how a payload moves through the nodes.

Thanks Dylan, I appreciate all your effort helping me out with this. Let me watch how it goes for a while.

Thanks again Dylan