Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 5 months ago.
Session dropping
I've written a program that takes in sensor values via an NRF24 radio module converts them into an appropriate output and sends them off to an MQTT server (where OpenHAB picks them up)
The code works for a short period of time (between 20 minutes and a couple of hours) and then stops (mqtt messages stop turning up at the server). It looks to me like it's the session between the mBed and the MQTT server that is dropping/timing out.
I think this is the case because I can still ping the IP address of the mBed (so it's not crashed) and when the code receives a radio message it flashes an LED. This is still happening.
I've tried to trigger the connection routine again by checking the isConnected function with the code if(!client.isConnected()) but this doesn't seem to work.
My code is here: https://developer.mbed.org/users/Mephi/code/IoT_NRF24/file/cec410958705/main.cpp One thing to note is that I've moved the MQTT publishing into it's own function 'sendMessage'.
Any idea what could be going wrong?
Thanks,
Matt
Question relating to:
1 Answer
9 years, 5 months ago.
Hi Matt,
I think you need to reinitialize the variables ipstack and client before triggering the connection routine again.
Basically insert the following lines in the if(!isConnected) condition
ipstack = MQTTEthernet(); MQTT::Client<MQTTEthernet, Countdown> client = MQTT::Client<MQTTEthernet, Countdown>(ipstack);
I was facing a similar problem and this worked for me. However, after reconnecting and resubscribing, my messageArrived() function is triggered twice for each received message, and the second one only contains the first character of the actual message. I'm still trying to resolve this. Any idea why this would be happening?