JAndrassy / WiFiEspAT

Arduino networking library. Standard Arduino WiFi networking API over ESP8266 or ESP32 AT commands.
GNU Lesser General Public License v2.1
290 stars 44 forks source link

MQTT Connection Skip a second or RC -2 or -3 #58

Closed leejames92 closed 2 years ago

leejames92 commented 3 years ago

Hi,

I have this issue of which I am unable to solve thus far. My ESP8266 paired with Arduino Mega and DS3231 RTC is setup to publish data every second to thingsboard IOT online through my home WiFi.

Most times per second works fine, but occasionally it would skip a second and after 12 hours or so (sometimes sooner) it would disconnect (but able to reconnect). I would like to eliminate the skip a second + the MQTT disconnect entirely to be able to say my system is stable and reliable.

Sample of sketch in Arduino,

#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <SoftwareSerial.h>
#include "RTClib.h"
#include <SPI.h>
#include "DHT.h"
#include <WiFiClient.h>
#include <WiFiEspAT.h>

#include <WiFiUdp.h>
#include <PubSubClient.h>
#include "SoftwareSerial.h"

#define WIFI_AP "HomeWifiSSID"
#define WIFI_PASSWORD "HomePassword"

#define TOKEN "ThingsboardAccessToken"

char thingsboardServer[] = "thingsboard.cloud";
WiFiClient espClient;
PubSubClient client(espClient);

int status = WL_IDLE_STATUS;
unsigned long lastSend;

unsigned long previousDT = 0;
int uptime;  
int status2;
int status3;
int status4;
int status5;
int status6;
int status7;
int status8;

void setup()
{
  Serial.begin(38400);
  Serial1.begin(38400);
  pinMode (sensor1, INPUT);
  pinMode (sensor2, INPUT);
  pinMode (sensor3, INPUT);
  pinMode (sensor4, INPUT);
  pinMode (sensor5, INPUT);
  pinMode (sensor6, INPUT);
  pinMode (sensor7, INPUT);
  pinMode (sensor8, INPUT);
  InitWiFi();
  client.setServer( thingsboardServer, 1883 );
  lastSend = 0;
  WiFi.sleepMode(WIFI_NONE_SLEEP);

  if ( client.connect ("ClientName", "James", "Password"))  {
    Serial.println( "[DONE]" );
  }
  boolean uptime = digitalRead(sensor1);
}

void loop()
{
  DateTime now = rtc.now();
  unsigned long currentMillis = now.unixtime();
  if (currentMillis - previousDT >= intervalDT) {
    previousDT = currentMillis;

 {
      if (WiFi.status() != WL_CONNECTED) {
        Serial.println("WiFi not OK");
      }
      else {
        Serial.println("WiFi OK");
      }
    }

    Serial.print (" WiFi state: ");
    Serial.print(client.state());

    long rssi = WiFi.RSSI();
    Serial.print("Signal strength (RSSI):");
    Serial.print(rssi);
    Serial.println(" dBm");

    if (WiFi.status() == WL_CONNECTED && uptime == 0 && client.state() == 0) {
      client.loop();
     getAndSendMachineStatus();
    }
}
}

void getAndSendMachineStatus()
{

  DateTime now = rtc.now();
  unsigned int minutes = (now.hour() * 60 + now.minute());
  unsigned int seconds = minutes * 60 + now.second();
  boolean uptime = digitalRead(sensor1);
  boolean status2 = digitalRead(sensor2);
  boolean status3 = digitalRead(sensor3);
  boolean status4 = digitalRead(sensor4);
  boolean status5 = digitalRead(sensor5);
  boolean status6 = digitalRead(sensor6);
  boolean status7 = digitalRead(sensor7);
  boolean status8 = digitalRead(sensor8);
  Serial.println("Machine Status..");

  Serial.print("Uptime: ");
  Serial.print(uptime);
  Serial.print(",");
  Serial.print(status2);
  Serial.print(",");
  Serial.print(status3);
  Serial.print(",");
  Serial.print(status4);
  Serial.print(",");
  Serial.print(status5);
  Serial.print(",");
  Serial.print(status6);
  Serial.print(",");
  Serial.print(status7);
  Serial.print(",");
  Serial.print(status8);
  Serial.print(",");

  {
    if (WiFi.status() != WL_CONNECTED) {
      Serial.print("WiFi not OK");
    }
    else {
      Serial.print("WiFi OK");
    }
  }

  Serial.print(" seconds: ");
  Serial.print(seconds);

  // Prepare a JSON payload string
  String payload = " {";
  payload += "\"uptime\":"; payload += uptime; payload += ",";
  payload += "\"status2\":"; payload += status2; payload += ",";
  payload += "\"status3\":"; payload += status3; payload += ",";
  payload += "\"status4\":"; payload += status4; payload += ",";
  payload += "\"status5\":"; payload += status5; payload += ",";
  payload += "\"status6\":"; payload += status6; payload += ",";
  payload += "\"status7\":"; payload += status7; payload += ",";
  payload += "\"status8\":"; payload += status8;
  payload += "}";

  // Send payload
  char attributes[100];
  payload.toCharArray( attributes, 100 );
  client.publish( "v1/devices/me/telemetry", attributes );
  Serial.println( attributes );
}

void InitWiFi()
{
  // initialize serial for ESP module
  // initialize ESP module
  WiFi.init(&Serial1);
  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  Serial.println("Connecting to AP ...");
  // attempt to connect to WiFi network
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(WIFI_AP);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(WIFI_AP, WIFI_PASSWORD);
    delay(500);
  }
  Serial.println("Connected to AP");

}

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) {
    Serial.print("Connecting to Thingsboard node ...");
    // Attempt to connect (clientId, username, password)
    if ( client.connect ("James1992SSM", "James", "920810abcde") ) {
      Serial.println( "[DONE]" );
    } else {
      Serial.print( "[FAILED] [ rc = " );
      Serial.print( client.state() );
      Serial.println( " : retrying...]" );
      // Wait 5 seconds before retrying
      delay( 5000 );
    }
  }
}

void WiFiLoop () {

  status = WiFi.status();
  if ( status != WL_CONNECTED) {
    while ( status != WL_CONNECTED) {
      Serial.print("Attempting to connect to WPA SSID: ");
      Serial.println(WIFI_AP);
      //Connect to WPA / WPA2 network
      status = WiFi.begin(WIFI_AP, WIFI_PASSWORD);
      delay(500);
    }
    Serial.println("Connected to AP");
  }

  if ( !client.connected() ) {
    reconnect();
    client.loop();
  }

}

In the loop I've disregarded for now to use WiFiLoop() as this would attempt to reconnect loss MQTT.

My ESP8266 is connected to stable WiFi connection so I'm trying to figure out why its disconnecting at random times and skipping seconds at random times. I want my connection to be stable and no loss first.

My ESP8266 is flashed to latest:

AT version:1.7.4.0(May 11 2020 19:13:04) SDK version:3.0.4(9532ceb) compile time:May 27 2020 10:12:17 Bin version(Wroom 02):1.7.4 OK

Set to max RX and TX power.

A quick debug so far showing an example it skipped a second:

esp INFO: soft reset
esp> AT+RST ...sent
esp> AT+RST ...ignored
esp> OK ...ignored
esp> 2s⸮⸮⸮Y}=w⸮93q⸮``⸮pp⸮⸮h⸮⸮S⸮4⸮⸮`p⸮8⸮b⸮2⸮S`⸮;⸮s⸮x⸮q⸮`⸮2⸮S ...ignored
esp> ⸮PY ⸮⸮⸮2⸮pr⸮ᡢp⸮Sq:1ES⸮⸮⸮`K⸮K⸮⸮C⸮⸮⸮}@a⸮⸮}=8⸮⸮⸮⸮⸮r⸮⸮Ĥ/⸮ o$ ...ignored
esp> ⸮7=R#9⸮!$⸮⸮UA!⸮eE⸮)('⸮M?.i$⸮a⸮)`.⸮lnj+⸮Ɔ⸮⸮礊⸮⸮⸮㥂D⸮ܤ+h⸮⸮Ą ...ignored
esp> ⸮⸮⸮⸮DX⸮ ...ignored
esp> ready ...matched
esp> ATE0 ...sent
esp> ATE0 ...ignored
esp> OK ...matched
esp> AT+CIPMUX=1 ...sent
esp> OK ...matched
esp> AT+CIPRECVMODE=1 ...sent
esp> OK ...matched
esp> AT+CWMODE? ...sent
esp> +CWMODE:1 ...matched
esp> OK ...matched
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:5 ...matched
esp> OK ...matched
Connecting to AP ...
Attempting to connect to WPA SSID: HomeWifiSSID
esp INFO: join AP _HomeWifiSSID_ current
esp> AT+CWJAP_CUR="HomeWifiSSID","HomePassword" ...sent
esp> ?
esp> busy p... ...ignored
esp> ?
esp> busy p... ...ignored
esp> ?
esp> busy p... ...ignored
esp> WIFI CONNECTED ...ignored
esp> ?
esp> busy p... ...ignored
esp> ?
esp> busy p... ...ignored
esp> WIFI GOT IP ...ignored
esp> OK ...matched
Connected to AP
esp INFO: set sleep mode
esp> AT+SLEEP=0 ...sent
esp> OK ...matched
esp INFO: free linkId is 4
esp INFO: start TCP to thingsboard.cloud:1883 on link 4
esp> AT+CIPSTART=4,"TCP","thingsboard.cloud",1883 ...sent
esp> ?
esp> busy p... ...ignored
esp> 4,CONNECT ...ignored
esp> OK ...matched
esp INFO: BuffManager new buff.stream at 0 for linkId 4 rx 64 tx 64
esp INFO: sync
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...matched
esp> OK ...end of list
esp> AT+CIPRECVLEN? ...sent
esp> +CIPRECVLEN:0,0,0,0,0 ...matched
esp> OK ...matched
esp INFO: send data on link 4
esp> AT+CIPSEND=4,46 ...sent
esp> OK ...ignored
esp> > ...matched
esp> Recv 46 bytes ...matched
esp> SEND OK ...matched
esp INFO:   sent 46 bytes on link 4
esp> +IPD,4,4 ...processed
esp INFO: get data on link 4
esp> AT+CIPRECVDATA=4,64 ...sent
esp> +CIPRECVDATA,4 ...matched
esp> OK ...matched
esp INFO:   got 4 bytes on link 4
[DONE]
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...ignored
esp> OK ...matched
WiFi OK

WiFi state: 0esp INFO: AP query
esp> AT+CWJAP? ...sent
esp> +CWJAP:"HomeWifiSSID","7c:8b:ca:3e:d7:5b",11,-57,0 ...matched
esp> OK ...matched
Signal strength (RSSI):-57 dBm
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...ignored
esp> OK ...matched
esp INFO: sync
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...matched
esp> OK ...end of list
esp> AT+CIPRECVLEN? ...sent
esp> +CIPRECVLEN:0,0,0,0,0 ...matched
esp> OK ...matched
Machine Status..
Uptime: 1,1,1,1,1,1,1,1,esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...ignored
esp> OK ...matched
WiFi OK **seconds: 81057**esp INFO: send data on link 4                         <<<<<<<<<<<<<<Here for seconds
esp> AT+CIPSEND=4,124 ...sent
esp> OK ...ignored
esp> > ...matched
esp> Recv 124 bytes ...matched
esp> ?
esp> busy s... ...ignored
esp> SEND OK ...matched
esp INFO:   sent 124 bytes on link 4
 {"uptime":1,"status2":1,"status3":1,"status4":1,"status5":1,"status6":1,"status7":1,"status8":1}
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...ignored
esp> OK ...matched
WiFi OK
 WiFi state: 0esp INFO: AP query
esp> AT+CWJAP? ...sent
esp> +CWJAP:"HomeWifiSSID","7c:8b:ca:3e:d7:5b",11,-58,0 ...matched
esp> OK ...matched
Signal strength (RSSI):-58 dBm
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...ignored
esp> OK ...matched
esp INFO: sync
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...matched
esp> OK ...end of list
esp> AT+CIPRECVLEN? ...sent
esp> +CIPRECVLEN:0,0,0,0,0 ...matched
esp> OK ...matched
Machine Status..
Uptime: 1,1,1,1,1,1,1,1,esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...ignored
esp> OK ...matched
WiFi OK **seconds: 81059**esp INFO: send data on link 4                           <<<<<<<<<<<<<<Here for seconds
esp> AT+CIPSEND=4,124 ...sent
esp> OK ...ignored
esp> > ...matched
esp> Recv 124 bytes ...matched
esp> SEND OK ...matched
esp INFO:   sent 124 bytes on link 4
 {"uptime":1,"status2":1,"status3":1,"status4":1,"status5":1,"status6":1,"status7":1,"status8":1}
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...ignored
esp> OK ...matched
WiFi OK

As you can see above bolded seconds can see a 1 second skip. I really don't know why is this happening.

Is it because of the baud rate? or a delay in a sketch? I tried many possible solutions but to no avail :(

Please help thank you.

JAndrassy commented 3 years ago

maybe first fix the presented sketch. variable seconds is not declared. global variables are shadowed by local variables... please edit the original post.

leejames92 commented 3 years ago

Hi jassandry,

Thanks for the find. I've just amended in my code and testing now.

However, this is an error log I've captured using the original code and the MQTT connection broke,

 WiFi state: 0esp INFO: AP query
esp> AT+CWJAP? ...sent
esp> +CWJAP:"HomeWifiSSID","7c:8b:ca:3e:d7:5b",11,-55,0 ...matched
esp> OK ...matched
Signal strength (RSSI):-55 dBm
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...ignored
esp> OK ...matched
esp INFO: sync
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...matched
esp> OK ...end of list
esp> AT+CIPRECVLEN? ...sent
esp> +CIPRECVLEN:0,0,0,0,0 ...matched
esp> OK ...matched
Machine Status..
Uptime: 1,1,1,1,1,1,1,1,esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...ignored
esp> OK ...matched
WiFi OK seconds: 21421esp INFO: send data on link 4
esp> AT+CIPSEND=4,124 ...sent
esp> OK ...ignored
esp> > ...matched
esp> Recv 124 bytes ...matched
esp> SEND OK ...matched
esp INFO:   sent 124 bytes on link 4
 {"uptime":1,"status2":1,"status3":1,"status4":1,"status5":1,"status6":1,"status7":1,"status8":1}
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...ignored
esp> OK ...matched
WiFi OK

WiFi state: 0esp INFO: AP query
esp> AT+CWJAP? ...sent
esp> +CWJAP:"HomeWifiSSID","7c:8b:ca:3e:d7:5b",11,-57,0 ...matched
esp> OK ...matched
Signal strength (RSSI):-57 dBm
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...ignored
esp> OK ...matched
esp INFO: sync
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...matched
esp> OK ...end of list
esp> AT+CIPRECVLEN? ...sent
esp> +CIPRECVLEN:0,0,0,0,0 ...matched
esp> OK ...matched
Machine Status..
Uptime: 1,1,1,1,1,1,1,1,esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,12611,0 ...ignored
esp> OK ...matched
WiFi OK seconds: 21422esp INFO: send data on link 4
esp> AT+CIPSEND=4,124 ...sent
esp> OK ...ignored
esp> > ...matched
esp> Recv 124 bytes ...matched
esp> ?
esp> busy s... ...ignored
esp> ?
esp> busy s... ...ignored
esp> ?
esp> busy s... ...ignored
esp> ?
esp> busy s... ...ignored
esp> ?
esp> busy s... ...ignored
esp> ?
esp> busy s... ...ignored
esp> ?
esp> busy s... ...ignored
esp> 4,CLOSED ...processed
esp INFO: closed linkId 4
esp> SEND FAIL ...matched
esp ERROR: failed to send data
 {"uptime":1,"status2":1,"status3":1,"status4":1,"status5":1,"status6":1,"status7":1,"status8":1}
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
WiFi OK

 WiFi state: 0esp INFO: AP query
esp> AT+CWJAP? ...sent
esp> +CWJAP:"HomeWifiSSID","7c:8b:ca:3e:d7:5b",11,-56,0 ...matched
esp> OK ...matched
Signal strength (RSSI):-56 dBm
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
Machine Status..
Uptime: 1,1,1,1,1,1,1,1,esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
WiFi OK seconds: 21429 {"uptime":1,"status2":1,"status3":1,"status4":1,"status5":1,"status6":1,"status7":1,"status8":1}
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
WiFi OK

WiFi state: -3esp INFO: AP query
esp> AT+CWJAP? ...sent
esp> +CWJAP:"HomeWifiSSID","7c:8b:ca:3e:d7:5b",11,-57,0 ...matched
esp> OK ...matched
Signal strength (RSSI):-57 dBm
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
WiFi OK

 WiFi state: -3esp INFO: AP query
esp> AT+CWJAP? ...sent
esp> +CWJAP:"HomeWifiSSID","7c:8b:ca:3e:d7:5b",11,-54,0 ...matched
esp> OK ...matched
Signal strength (RSSI):-54 dBm
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
WiFi OK

I am unable to decipher the issue based on this log. Do hope I can get some clarity and assistance. Looks like there is a send fail, then send once ok after skipping couple of seconds, then the MQTT connection broke right after.

JAndrassy commented 3 years ago

AT firmware responded SEND FAIL. there is no more info

leejames92 commented 3 years ago

Meaning there is an issue with my sketch? Sorry i'm quite unfamiliar still with this MQTT related matters

JAndrassy commented 3 years ago

Meaning there is an issue with my sketch? Sorry i'm quite unfamiliar still with this MQTT related matters

I guess not. What version of AT firmware is it?

leejames92 commented 3 years ago

AT 1.7.4.0

Is it esp8266 wifi connection cut off or its busy?

JAndrassy commented 3 years ago

AT 1.7.4.0 Is it esp8266 wifi connection cut off or its busy?

1.7.4 is the best ESP AT firmware ever (I doubt AT 2 can be so stable in near or far future), but event then it can have problems for various reasons. Does the next sending work?

leejames92 commented 3 years ago

I see. I tried again and after 8 hours the MQTT connection broke again :/

 WiFi state: 0esp INFO: AP query
esp> AT+CWJAP? ...sent
esp> +CWJAP:"HomeWiFiSSID","7c:8b:ca:3e:d7:5b",1,-68,0 ...matched
esp> OK ...matched
Signal strength (RSSI):-68 dBm
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,43552,0 ...ignored
esp> OK ...matched
esp INFO: sync
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,43552,0 ...matched
esp> OK ...end of list
esp> AT+CIPRECVLEN? ...sent
esp> +CIPRECVLEN:0,0,0,0,0 ...matched
esp> OK ...matched
Machine Status..
Uptime: 1,1,1,1,1,1,1,1,esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,43552,0 ...ignored
esp> OK ...matched
WiFi OK seconds: 59821esp INFO: send data on link 4
esp> AT+CIPSEND=4,124 ...sent
esp> OK ...ignored
esp> > ...matched
esp> Recv 124 bytes ...matched
esp> SEND OK ...matched
esp INFO:   sent 124 bytes on link 4
 {"uptime":1,"status2":1,"status3":1,"status4":1,"status5":1,"status6":1,"status7":1,"status8":1}
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,43552,0 ...ignored
esp> OK ...matched
WiFi OK

 WiFi state: 0esp INFO: AP query
esp> AT+CWJAP? ...sent
esp> +CWJAP:"HomeWiFiSSID","7c:8b:ca:3e:d7:5b",1,-65,0 ...matched
esp> OK ...matched
Signal strength (RSSI):-65 dBm
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,43552,0 ...ignored
esp> OK ...matched
esp INFO: sync
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,43552,0 ...matched
esp> OK ...end of list
esp> AT+CIPRECVLEN? ...sent
esp> +CIPRECVLEN:0,0,0,0,0 ...matched
esp> OK ...matched
Machine Status..
Uptime: 1,1,1,1,1,1,1,1,esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:3 ...matched
esp> +CIPSTATUS:4,"TCP","54.85.19.206",1883,43552,0 ...ignored
esp> OK ...matched
WiFi OK seconds: 59822esp INFO: send data on link 4
esp> AT+CIPSEND=4,124 ...sent
esp> OK ...ignored
esp> > ...matched
esp> Recv 124 bytes ...matched
esp> ?
esp> busy s... ...ignored
esp> ?
esp> busy s... ...ignored
esp> ?
esp> busy s... ...ignored
esp> ?
esp> busy s... ...ignored
esp> ?
esp> busy s... ...ignored
esp> ?
esp> busy s... ...ignored
esp> ?
esp> busy s... ...ignored
esp> 4,CLOSED ...processed
esp INFO: closed linkId 4
esp> SEND FAIL ...matched
esp ERROR: failed to send data
 {"uptime":1,"status2":1,"status3":1,"status4":1,"status5":1,"status6":1,"status7":1,"status8":1}
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
WiFi OK

 WiFi state: 0esp INFO: AP query
esp> AT+CWJAP? ...sent
esp> +CWJAP:"HomeWiFiSSID","7c:8b:ca:3e:d7:5b",1,-63,0 ...matched
esp> OK ...matched
Signal strength (RSSI):-63 dBm
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
Machine Status..
Uptime: 1,1,1,1,1,1,1,1,esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
WiFi OK seconds: 59830 {"uptime":1,"status2":1,"status3":1,"status4":1,"status5":1,"status6":1,"status7":1,"status8":1}
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
WiFi OK

 WiFi state: -3esp INFO: AP query
esp> AT+CWJAP? ...sent
esp> +CWJAP:"HomeWiFiSSID","7c:8b:ca:3e:d7:5b",1,-64,0 ...matched
esp> OK ...matched
Signal strength (RSSI):-64 dBm
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
WiFi OK

 WiFi state: -3esp INFO: AP query
esp> AT+CWJAP? ...sent
esp> +CWJAP:"HomeWiFiSSID","7c:8b:ca:3e:d7:5b",1,-62,0 ...matched
esp> OK ...matched
Signal strength (RSSI):-62 dBm
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
esp INFO: wifi status
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched
esp> OK ...matched
WiFi OK

Again it is seen that the esp is busy first. and then the connection just break :(

JAndrassy commented 3 years ago

Does the next sending work?

leejames92 commented 3 years ago

Sorry, what do you mean by next sending? Is it restart my arduino mega and esp8266? if that, yes it work.

Also if I include reconnect after MQTT connection loss, that'll work as well I believe.

leejames92 commented 3 years ago

Maybe I think you meant my client.state()? It becomes - 3.

When it becomes -3 then it loops without sending anymore

JAndrassy commented 3 years ago
esp> AT+CIPSTATUS ...sent
esp> STATUS:4 ...matched

status 4 is "The TCP or UDP transmission of ESP8266 Station is disconnected" which is expected, because the TCP connection closing was announced by AT firmware here

esp> busy s... ...ignored
esp> 4,CLOSED ...processed

but there is no new connection attempt. I don't know what code you run. maybe the cloud kicks you out for too frequent calls.

leejames92 commented 3 years ago

I see. I'm disappointed with self unable to solve this issue.

However I bought a WeMos arduino mega with installed on board esp8266 and hopefully it'll work when it arrives. Maybe my current setup esp8266 isn't getting enough power.