2

I'm trying to build my own OpenThread application on two nrf52840 DK borads. When a specific button is pressed I want to start sending udp multicast in a specific time intervall. For now I have achieved that, when the button is pressed, the multicast is sent once. But is there any way that I can periodically send a udp multicast? I thought about using a while loop where the udp_send() methods is called and the some form of thread sleep is called. But I can't seem to find a sleep method that actually works.

Has anybody an idea how to put it into sleep?

ouflak
  • 2,458
  • 10
  • 44
  • 49
Emily
  • 39
  • 3

2 Answers2

1

The usual non-blocking method (i.e. without threads and sleep) is to

  1. send the packet
  2. take a timestamp
  3. continuously check if time_now >= (timestamp + 1 second) (for 1 second intervals, change accordingly)
  4. if so: send a packet, update the timestamp -> rinse and repeat
Morten Jensen
  • 5,818
  • 3
  • 43
  • 55
0

You should create a periodic task that sends a packet. Just exit the task at the end and the device should enter sleep.

Quoted from: Nordic Devzone

With the nRF Connect SDK and Zephyr there is a idle thread, and this idle thread will automatically enter system ON sleep mode (WFE). There is no need to do anything specifically for this to happen. As long as you don't have any other threads using the CPU, the CPU will be idle. Note that regardless of this you also need to ensure you don't use other resources on the chip or your board that consume power, like for instance UART logging, in order to achieve low power. I suggest you refer to the Power optimization chapter in the SDK documentation for an overview.

Frank Schrijver
  • 101
  • 1
  • 6
  • Welcome to StackOverflow! While links can be of great use, they might become obsolete with no alternative to finding similar information. Would mind posting an example? Even a bit of untested (preferrably tested) psuedo code instructions could be useful to future visitors having the same issue. – ouflak Jan 01 '23 at 15:13