AnsweredAssumed Answered

How to improve SPWF04SA MQTT reconnection reliability?

Question asked by Feitze van Zwol on May 3, 2018

The situation

We are trying to use the SPWF04SA WiFi module to readout and control values on microcontrollers. As a test, we are using a Teensy 3.2 microcontroller and send/receive messages using the MQTT-client on the SPWF04SA WIFI module.

 

The Teensy sends commands to the WiFi module over a serial connection. The wifi module itself is connected to eduroam (university WPA enterprise network) and sends MQTT messages to a mosquitto-server and also receives messages from a certain topic.

 

The basic principle works, but this gets interesting when the module gets (randomly) disconnected from the eduroam WiFi network. We want to continuously listen to the subscribed MQTT-topic, but after a WiFi-disconnect, it does not automatically connect to the MQTT-server again. We currently solved it by allowing the Teensy to read the output of the serial port of the WiFi module and detect the words Dissociation or ERROR in the messages. If this happens, it will stop serial communication for a while and then try to reconnect.

 

Our problem

The problem that occurs is that reconnecting sometimes, but not consistently gives an error message: AT-S:ERROR 111:request failed

Another problem we ran into is that if we set the keep alive time to 3600 for example (because we want to have a basically continuous connection), the WiFi module will freeze and not respond to serial commands anymore.

 

What would we like to know?

Does anyone have any tips for improving the reliability of the MQTT-connection on the SPWF04SA?

I attached the script we wrote that is loaded on the Teensy. I am very novice and it could very well be that I made a really stupid mistake regarding MQTT, or serial communication with the module. Is this approach of connection a Teensy to the wifi module even the right approach? Or would we be better off with a different setup?

 

Thank you for reading my long post up until this point and thanks in advance for thinking about the problem!

 

 

Attachments

Outcomes