Sending Data to TTN when sensor value changes

Hi , Im new here :slight_smile:

I tried to find something here and in the web for this but I wasnt able to.

I would like to monitor a door with a Dragino shield on an Arduino Uno and and a binary sensor that is High when the door is closed and low when the door is open. I also would like to send a data package when the sensor value changes to TTN. And exactly here lies the problem:

In the example sketches everything depends on the set time interval (TX)

Is there a way to change “send data dependent on time” to value change?

for example in the Hello World sketch:

I would be very happy if someone could share some wisdom with me :slight_smile:

Thank you!

when the door is closed nothing happens, when the door opens an interrupt is generated, the nodes wakes up and transmits a byte to your application.
then the node waits until the door closes and go back to sleep.
this is how your code could work (not the code you’ve posted)

depending on the distance to your gateway and the interval (how many times per minute the door opens/closes), and NO, you must not change these LMIC parameters.


1 Like

Thanks for your reply :slight_smile:
Ill try it again tomorrow and read through you attached threat

Hi @nicopuw,
I work on a similar use case. Could you solve your problem mentioned here? If yes, what’s the trick? Thanks you!

You need to remove the scheduling of next transmission in the onEvent section and add a call to do_send in the main loop if the door is opened or closed - preferably as mentioned above, with some time logic to stop it sending every few seconds when there is a rush out the door.


Hi @descartes, thank you!
I tried this by changing the Timed Callback (os_setTimedCallback) in the onEvent section to an immediate one os_setCallback(&sendjob, do_send); and only calling LMIC_setTxData2(1, payload, sizeof(payload), 0); in the do_send section with data if there has been a change that should be sent to the network. Unfortunately that does not work. Could you provide any code snippet that shows how to send data only event-based? I could not find one… Thanks!

I’ll be clearer, you need to remove any send in the onEvent section - you swapped a request to schedule for one that sends immediately. The onEvent function processes events from the LMIC library and it’s the section when a send has just been completed - EV_TXCOMPLETE.

In the main Arduino loop(), check for the status of the switch (if statement), setup the data as you’ve done above and then call do_send()

Read the code, it tells you what it is doing, speak it out loud, it sounds mad but it helps.

1 Like