Hi all,
Using the thread CLI example (on a PCA10056 board) as a starting point I would like nodes to connect automatically to a thread mesh when booting. I then want to use this mesh to exchange UDP packets.
The joining of the thread network works fine, and opening and sending a UDP package works fine the first time too.
However, when I then try to send a second package over the still opened UDP port the code hangs, it never returns from the otUdpSend method.
I can't seem to find what I'm still missing, so any help would be very welcome.
int main(int argc, char *argv[])
{
log_init();
scheduler_init();
timer_init();
leds_init();
otError error;
long counter = 0;
uint32_t err_code = bsp_init(BSP_INIT_LEDS, NULL);
APP_ERROR_CHECK(err_code);
while (true)
{
// connect to thread mesh
thread_instance_init();
otLinkSetPanId(thread_ot_instance_get(), 5);
otIp6SetEnabled(thread_ot_instance_get(), true);
otThreadSetEnabled(thread_ot_instance_get(), true);
const char buf[100] = "test123\0";
otMessageInfo messageInfo;
otUdpSocket mySocket;
memset(&messageInfo, 0, sizeof(messageInfo));
otIp6AddressFromString("ff03::1", &messageInfo.mPeerAddr);
messageInfo.mPeerPort = 1994;
error = otUdpOpen(thread_ot_instance_get(), &mySocket, HandleUdpReceive, NULL);
otMessage *test_Message = otUdpNewMessage(thread_ot_instance_get(), NULL);
otMessageAppend(test_Message, buf, (uint16_t)strlen(buf));
NRF_LOG_INFO("after socket open");
while (!thread_soft_reset_was_requested())
{
thread_process();
app_sched_execute();
if (NRF_LOG_PROCESS() == false)
{
//thread_sleep();
}
otError errorUdpSend = otUdpSend(&mySocket, test_Message, &messageInfo);
NRF_LOG_INFO(otThreadErrorToString(errorUdpSend));
}
NRF_LOG_INFO("SOFT RESET");
thread_instance_finalize();
}
}