kyberpunk / openthread

OpenThread implementation of network Thread protocol with MQTT-SN support.
Other
5 stars 5 forks source link

Tasklet Posting causing mqtt start to lock up #29

Open ajlennon opened 1 year ago

ajlennon commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

I'm using nRF Connect SDK and have replaced the openthread module with main of this mqtt-sn enabled openthread repo.

I've set OT_MQTT=1 to build in the mqtt commands to the nRF Connect SDK CLI example and they appear fine.

When I execute ot mqtt start the call never returns.

I've debugged through and it looks like mProcessTask.Post() in mttsn_client.cpp::Process() is - I think - causing it to loop continuously and thus lock up

With these two lines commented out it returns (although I assume no mqtt-sn processing will be occuring)

https://github.com/kyberpunk/openthread/blob/1bfec38433c3fb74e0f980684148b8143d49036f/src/core/mqttsn/mqttsn_client.cpp#L1167

https://github.com/kyberpunk/openthread/blob/1bfec38433c3fb74e0f980684148b8143d49036f/src/core/mqttsn/mqttsn_client.cpp#L1209

I assume I am doing something slightly different somehow and this is causing a problem. I can't quite see where the OpenThread tasklet would yield and am not sure why whatever I am doing with my build seems to be causing this problem...

Any help would be appreciated!

To Reproduce Information to reproduce the behavior, including:

  1. Git commit id

1bfec38433c3fb74e0f980684148b8143d49036f

  1. IEEE 802.15.4 hardware platform

Nordic nRF52840 dongle / DK

  1. Build steps

As above

  1. Network topology

Don't get that far

Expected behavior A clear and concise description of what you expected to happen.

ot mqtt start should return or error

Console/log output If applicable, add console/log output to help explain your problem.

Additional context Add any other context about the problem here.

ajlennon commented 1 year ago

So I took a step back and tried building with the OpenThread code rather than the Nordic example

Something like this

git clone git@github.com:openthread/ot-nrf528xx.git --recursive
cd ot-nrf528xx/
git submodule remove openthread
rm -Rf openthread/
git clone https://github.com/kyberpunk/openthread.git --recursive
# Bootloader option lets us build for nRF52840 dongle
./script/build nrf52840 USB_trans -DOT_BOOTLOADER=USB -DOT_MQTT=ON -DOT_JOINER=ON -DOT_RCP_RESTORATION_MAX_COUNT=0
arm-none-eabi-objcopy -O ihex build/bin/ot-cli-ftd build/bin/ot-cli-ftd.hex

Really pleased to be able to say this works perfectly! I can publish and subscribe to a Mosquitto broker in the cloud via MQTTSNGateway running on my OTBR. Excellent!

I just wish I knew what was up with the Nordic example code

ajlennon commented 1 year ago

I've ported the MQTT-SN changes to the current version of OpenThread that nRF Connect SDK (v2.4.0) uses.

https://github.com/DynamicDevices/openthread-upstream/tree/nrf-connect-with-mqtt-sn

Still getting lock ups on mqtt start.

ajlennon commented 1 year ago

OK I have this figured out. I've replaced the use of Tasklets with the use of Timers and have this plugged into and working in nRF Connect now. Code is here

https://github.com/DynamicDevices/openthread-upstream/tree/nrf-connect-with-mqtt-sn

Basically you just need to install your v2.4.0 nRFConnect as usual then replace ~/ncs/v2.4.0/modules/lib/openthread with this code

^^^ @kyberpunk

kyberpunk commented 11 months ago

@ajlennon For some reason I have no issues on nRF52840. But when I've built it on ESP32-C6, it stuck always on mqtt connect. After patching it with your change it work. Thank you for that, I will try to understand more what is the problem and fix it also in my fork.

ajlennon commented 11 months ago

@ajlennon For some reason I have no issues on nRF52840. But when I've built it on ESP32-C6, it stuck always on mqtt connect. After patching it with your change it work. Thank you for that, I will try to understand more what is the problem and fix it also in my fork.

Ah great - glad to be of help! Yes would love to hear from you what you think is going on "underneath"