Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By sixbacon
#44159 Using the Arduino IDE I have programmed an ESP12 to measure a distance using the ultrasonic module, then send the result to an MQTT broker over the wifi and then go to sleep for a while. It works fine when not set to go to sleep, except that the first message after a reset is not sent. Put in the sleep section and no messages are sent, as they are always the first one after a reset. I got round this by setting up the wifi, the MQTT link and sending a dummy message( which never arrrives), doing my measurment, then setting up the wifi and the MQTT link again, sending the reading, which gets through this time, and then going to sleep. I am using the libraries,
extern "C" {
#include "user_interface.h"
}
#include <Ultrasonic.h>
#include "ESP8266WiFi.h"
#include <PubSubClient.h> .
The problem is not in the ultrasonic bit, not the wifi, not te deep sleep as I have checked all that. It is related to the MQTT.
As I say the program now works. But it is not elegant and I don't understand why I have to do it this way. I have used MQTT before to send other readings, see my competion entry(72). However I did not put the ESP12 to sleep then and may not have noticed that the first message never got through. Has anyone else had this problem, or know what is going on?