Change a Var when a bit sensor keep activate 5 payloads in a row

I want to confirm when a end of carrer stay pushed for 1 hour aprox, to do this I try with a while with a i++ and it reach 5 for example with a refresh rate of 10 minutes, how can I acumulate the increment of i
Thank you a lot

It seems a basic programming question more than a LoRaWAN one, and it is also unclear what you want to do. The variable i already contains 5 after five times.

1 Like

Rather than the how, I think you’ll first need to decide where you want to implement this:

  • In the node, to only transmit an uplink every hour, or even only after some state did not change for an hour; or:

  • In your application, which would need to track the recent uplinks, or the last hour of uplinks, which would be transmitted by the node every 10 minutes.

Also: what if the state keeps being “pushed” for more than an hour?

I’d do this in the node. This would even allow you to use a much shorter interval to check the “pushed” state, making it much more accurate. It might also allow for using interrupts to act on state changes and/or timeouts. But above all: this would limit the number of uplinks a lot, and those uplinks are expensive for both the maximum daily air time and for battery usage. But note that transmissions might not be received at all.

Aside: I’ve no idea what “a end of carrer” is. A button?

1 Like

Thank you very much for your answers.
I want to make a sensor that detects when a silo is emptied, for this I see the option of doing it in the node more optimal, not reducing the cycles to one hour because a false positive (which would occur during filling for example) may coincide with the reading.
I am not sure how that would be done in code, because what I have tried could not connect it from one reading to another.
A end of carrer is like a limit switch of a door, in Spain we call it “final de carrera”.
Sorry if my post is repeated, I have looked for a similar problem but I havent found any solution on the internet, regards

The end node that I used in this case is a Dragino LSN50,

With the standard firmware in that Dragino device, you cannot add such logic to the node: one can only transmit the current digital state of pin PA12 at a fixed interval, or use AT+INTMOD=1 along with connecting the switch to interrupt pin PB14 to transmit whenever the switch state changes. (I don’t know if the Dragino firmware does proper debouncing of the input, or might use some throttling, which would be needed to avoid sending too many uplinks.)

Explaining all that’s needed to create an application to analyse those uplinks is way too much for me, or for this forum, I feel. You’ll need to hire a software developer who knows some basics about how to persist and retrieve data, and use those historical values for your business logic. It’s not something that can be achieved with just TTN Console.

It seems one can also upload one’s own Arduino sketches into that Dragino device. That would be great, if only as then you don’t waste air time using the standard Dragino payload format, which sends way more details than you need. I’ve not searched for any examples, and maybe you’d need to choose a different device altogether. But unless you’ve already started investigating this without telling us, you’d need a software developer for that too.

It might be easier to look for an off-the-shelf device that allows for setting some min/max thresholds or supports delayed alerts, to only transmit when needed. And maybe use a distance meter rather than a switch? (It seems that Nemeus NIS-UL – Ultrasonic sensor supports such thresholds, but surely there are others too.)

And of course, even with the ideal device, one would still need some application to process the uplinks too, unless something from Visualize (and push) your IOT data suffices.