Send MQTT directly from chip
Closed this issue · 5 comments
Would it be possible to change the firmware running on the chip in order to make it send MQTT instead of UDP messages?
The reason we are using UDP is time. The fastest way and therefor saving lots of energy is to send UDP packets. MQTT and MAtter compared to that is quite heavy in resource consumption.
I created a Home Assistant Addon: https://hackaday.io/page/22298-home-assistant-addon-to-integrate-the-thread-sensor-tag
But we also provide a script which takes the UDP packets and translates them into MQTT messages if that helps?
Somewhere in here: https://github.com/HomeSmartMesh/raspi/tree/master/py/thread_tags
The only waay for this device to directly send MQTT would be MQTT-SN if I remember correctly, thats a version of MQTT where the device is allowed to sleep. Becauise our device is sleeping most of the time. But that is not implemented.
You can use the scripts from that repo and make your own version to translate the UDP messages into MQTT but the script needs to run on the same device where the Thread Network is running on.
I understand the reasoning behind the choice of UDP, I just wanted to test a setup with direct MQTT / MQTT-SN communication within the thread network.
I got stuck on how to update the firmware on the chip. I tried with nRF Connect Bluetooth Low Energy but the software seems to have a bug. The specs of the chip mentions the possibility of doing Over-the-Air(OTA) firmware updates (https://www.minew.com/uploads/MS88SF2_V1.0-nRF52833-Datasheet.pdf) but there is no explanation about how to do this.
Do you have any suggestions on how to proceed in order to add some changes to the original firmware?
I am a bit confused now because in the datasheet it says nrf52833 but it actually should be a nrf52840. Thats strange.
Anyway: to progrm or change the firmware you will need an Segger J-Link Programmer Board. I am using this one: https://www.segger.com/products/debug-probes/j-link/models/j-link-edu-mini/
But with that you need to find a way of getting to the Pins you need. All Pins you need are broken out on the Thread Sensor Tag.
There are other Segger Boards as well but I have not used them (maybe @wassfila did) and they are also more expensive.
Updating the firmware via OTA will not work with the current firmware because the current firmware is a Zephyr RTOS. As far as I know it does not support it as it is.
So my suggestion would be to get such a J-Link Debugger and then you can do what ever you want with the board. You can also checkout the samples folder as a beginning. I remember that we actually tried out MQTT-SN @wassfila do you know if we still have some sample code laying around somewhere for that?
yes, here, I tested some samples with MQTT-SN https://github.com/HomeSmartMesh/nrf52_thread_sensortag/tree/main/firmware
If I remember right, the reason why I abandoned MQTT-SN is that it's any way not MQTT native, cannot connect naively to an MQTT broker, and need a proxy in the middle, that is complex to install and has many constraints, so it's not anyhow better than our UDP->MQTT proxy.
A native MQTT client would actually be nice as you no longer need a proxy, but for our low power use case it did not made sense, because even if it works, it will be a waste of power with all messages, that's the reason why some came with MQTT-SN and we with UDP.
Technically speaking there's no reasons why MQTT should not work, here a sample that could be tested https://github.com/zephyrproject-rtos/zephyr/tree/main/samples/net/mqtt_publisher.
@FedeTommi before "changing the firmware", it might be necessary first to follow some Zephyr tutorials until you feel comfortable with it, it incurs quite a learning curve, but it is worth it.
Thank you @Informaticore and @wassfila for the links and the suggestions!