(PROBLEM) disconnections without reason
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

(PROBLEM) disconnections without reason

by acuplush on Fri Dec 28, 2018 5:43 am

hello to all, I have the problem that my module esp8266 makes many reconnections to adafruit and I do not understand why, and of course when it has to act is not connected.
the result is that I lose the actions to be performed.
the unread command does not remain in the "buffer"?
what can it depend on?
thanks google translate
riconnessione.PNG (53.9 KiB) Viewed 133 times

Posts: 8
Joined: Mon Dec 17, 2018 12:50 pm

Re: (PROBLEM) disconnections without reason

by acuplush on Thu Jan 03, 2019 9:45 am

does anyone have a possible solution? here the problems continue ... sometimes even 10/15 continuous reconnections.
thank you

Posts: 8
Joined: Mon Dec 17, 2018 12:50 pm

Re: (PROBLEM) disconnections without reason

by abachman on Thu Jan 03, 2019 10:39 am

Hi acplush,

Unfortunately, the problem could be any piece of the system: your device itself, your device's connections to additional electronics, the case your device is in, power supply to your device, the strength of the local wifi network, transient internet failures in between your location and your internet service provider, the code your device is running, etc.

Adafruit IO is always on and available, so it's likely there is something else going on. You can try working with each of the variables you control to produce an always connected object, but you will probably have better luck writing your code in a way that expects to occasionally be disconnected. These devices are powerful, but not perfect. Reconnection is anticipated by our libraries, for example in Adafruit IO and Adafruit MQTT.

If you're able to share your code and project wiring, you may be able to get help with specifics.

- adam b.

- adam b.

Posts: 292
Joined: Mon Feb 01, 2010 12:48 pm

Re: (PROBLEM) disconnections without reason

by acuplush on Fri Jan 04, 2019 5:54 am

thanks for your time
the wifi signal is about -74 but even approaching the modem the problem is not solved
the esp-01 is connected via serial to arduino nano through level translator
it is powered by a 1.5A cell phone charger and I have lowered the voltage through 2 diodes and a capacitor, the same charger also powers arduino

I attach the code I use, I have modified one that I found in the online guides.
it simply receives the signal from adafruit and sends it via serial to arduino.
do you notice something strange or that can be improved? thank you

Code: Select all | TOGGLE FULL SIZE
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

#define intervallo 120000  //tempo tra 2 letture di segnale wifi in millisecondi (MODIFICABILE A PIACIMENTO)
char* ricevuto = "";
int risposta = 0;
int segnale;
char inviato = 0;
unsigned long tempinterval; //intervallo tra 2 letture di segnale wifi

/************************* WiFi Access Point *********************************/

#define WLAN_SSID       "*******"
#define WLAN_PASS       "**********"

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883                   // use 8883 for SSL
#define AIO_USERNAME    "*****"
#define AIO_KEY         "************"

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;


/****************************** Feeds ***************************************/
// impostazioni feed in ricezione o trasmissione
Adafruit_MQTT_Subscribe DomoticaCentrale = Adafruit_MQTT_Subscribe(&mqtt, AIO_USERNAME "/feeds/domotica_centrale");
Adafruit_MQTT_Publish StatoConnessione = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/stato-connessione");
Adafruit_MQTT_Publish SegnaleWifi = Adafruit_MQTT_Publish(&mqtt, AIO_USERNAME "/feeds/segnale-wifi");
/*************************** Sketch Code ************************************/

void MQTT_connect();

void setup() {

  while (WiFi.status() != WL_CONNECTED) {

  //  Serial.println("WiFi connected");
  // Serial.println("IP address: "); Serial.println(WiFi.localIP());

  // Setup MQTT subscription for onoff feed.

uint32_t x = 0;

void loop() {
  if (millis() > (tempinterval + intervallo)) { //lettura segnale ogni TOT millisecondi impostati nel setup
    long rssi = WiFi.RSSI();
    segnale = int (rssi);
    // Serial.print (segnale);
    tempinterval = millis();
  if (WiFi.status() != WL_CONNECTED) {


  Adafruit_MQTT_Subscribe *subscription;
  while ((subscription = mqtt.readSubscription(5000))) {
    if (subscription == &DomoticaCentrale) {
      ricevuto = ((char*)DomoticaCentrale.lastread);

  if (! mqtt.ping()) {

// Function to connect and reconnect as necessary to the MQTT server.
// Should be called in the loop function and it will take care if connecting.
void MQTT_connect() {
  int8_t ret;

  // Stop if already connected.
  if (mqtt.connected()) {

  // Serial.print("Connecting to MQTT... ");

  uint8_t retries = 3;
  while ((ret = mqtt.connect()) != 0) { // connect will return 0 for connected
    // Serial.println(mqtt.connectErrorString(ret));
    //Serial.println("Retrying MQTT connection in 5 seconds...");
    delay(5000);  // wait 5 seconds
    if (retries == 0) {
      // basically die and wait for WDT to reset me
      while (1);
  StatoConnessione.publish("Domotica Connessa");


Posts: 8
Joined: Mon Dec 17, 2018 12:50 pm

Please be positive and constructive with your questions and comments.