Arduino + ESP8622 (wemos) After adding dht to auto connect code = packets too big, reconnecting

SOLVED (blynk older library version working good)

Hello, i spend 3 days to search over internet to get my arduino mega wemos working with autoconnect function, once i get it working i was very happy, but then i start to add dht sensor, and can’t understand what i’m doing wrong, i add antenna to my arduino for good connection and also tried with mobile hotspot, i din’t relly found similar topics about arduino mega + esp8266 with similar problems.

• Hardware model = Wemos® Mega + WiFi R3 ATmega2560 + ESP8266 32Mb
• Smartphone = Android 10
• Blynk server or local server = local and blynk server
• Blynk Library version = 0.6.1 (when i updated to this 1.0.0 beta 3 i get errors)

CODE:



#define BLYNK_PRINT                   Serial

// Debug level, 0-3
#define BLYNK_WM_DEBUG                1

#define USE_NEW_WEBSERVER_VERSION     true  //false
#define _ESP_AT_LOGLEVEL_             0
#define _ESP_AT_LIB_LOGLEVEL_         0

/* Comment this out to disable prints and save space */
#define ESP_AT_DEBUG_OUTPUT       Serial
//#define ESP_AT_LIB_DEBUG_OUTPUT   Serial

#define ESP_AT_DEBUG              true
#define ESP_AT_LIB_DEBUG          true

/* Comment this out to disable prints and save space */
#define DRD_GENERIC_DEBUG         true 

// Uncomment to use ESP32-AT commands
//#define USE_ESP32_AT      true

// USE_ESP_AT_LIB == true to use new ESP_AT_Lib, instead of ESP8266_Lib
// For ESP32-AT, must use ESP_AT_Lib
#if (defined(USE_ESP32_AT) && USE_ESP32_AT )
  #define USE_ESP_AT_LIB    true
#else
  #define USE_ESP_AT_LIB    true
  //#define USE_ESP_AT_LIB    false
#endif

//#if !( defined(ARDUINO_AVR_MEGA) || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_ADK) )
#if !( defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1280__)   || defined(__AVR_ATmega1281__) || \
       defined(__AVR_ATmega640__)  || defined(__AVR_ATmega641__)  || defined(ARDUINO_AVR_MEGA2560) || defined(ARDUINO_AVR_MEGA) )
  #error This code is intended to run only on the Arduino Mega 1280/2560/ADK boards ! Please check your Tools->Board setting.
#endif

// For Mega, use Serial1 or Serial3
#define EspSerial Serial3

#if ( defined(ARDUINO_AVR_MEGA2560)|| defined(__AVR_ATmega2561__) )
  #define BOARD_TYPE      "AVR Mega2560"
#elif ( defined(__AVR_ATmega1280__) ||  defined(__AVR_ATmega1281__) )
  #define BOARD_TYPE      "AVR Mega1280"
#elif defined(ARDUINO_AVR_ADK)
  #define BOARD_TYPE      "AVR MegaADK"
#else
  #define BOARD_TYPE      "AVR Mega"
#endif

#ifndef BOARD_NAME
  #define BOARD_NAME    BOARD_TYPE
#endif

// Start location in EEPROM to store config data. Default 0
// Config data Size currently is 128 bytes)
#define EEPROM_START     0

#define USE_BLYNK_WM      true
//#define USE_BLYNK_WM      false

#if USE_BLYNK_WM
  #include <BlynkSimpleShieldEsp8266_WM.h>
#else
  #include <BlynkSimpleShieldEsp8266.h>
  
  #define USE_LOCAL_SERVER      true
  
  #if USE_LOCAL_SERVER
    char auth[] = "****";
    char BlynkServer[] = "account.duckdns.org";
    //char BlynkServer[] = "192.168.2.112";
  #else
    char auth[] = "****";
    char BlynkServer[] = "blynk-cloud.com";
  #endif
  
  #define BLYNK_SERVER_HARDWARE_PORT    8080

  // Your WiFi credentials.
  char ssid[] = "****";
  char pass[] = "****";

#endif

// SSID and PW for Config Portal
char portal_ssid[]      = "Gunar";
char portal_password[]  = "1122334455";

// Your Mega <-> ESP8266 baud rate:
#define ESP8266_BAUD 115200

ESP8266 wifi(&EspSerial);

#if USE_BLYNK_WM

#define BLYNK_PIN_FORCED_CONFIG           V19
#define BLYNK_PIN_FORCED_PERS_CONFIG      V20

// Use button V10 (BLYNK_PIN_FORCED_CONFIG) to forced Config Portal
BLYNK_WRITE(BLYNK_PIN_FORCED_CONFIG)
{
  if (param.asInt())
  {
    Serial.println( F("\nCP Button Hit. Rebooting") );

    // This will keep CP once, clear after reset, even you didn't enter CP at all.
    Blynk.resetAndEnterConfigPortal();
  }
}

// Use button V20 (BLYNK_PIN_FORCED_PERS_CONFIG) to forced Persistent Config Portal
BLYNK_WRITE(BLYNK_PIN_FORCED_PERS_CONFIG)
{
  if (param.asInt())
  {
    Serial.println( F("\nPersistent CP Button Hit. Rebooting") );

    // This will keep CP forever, until you successfully enter CP, and Save data to clear the flag.
    Blynk.resetAndEnterConfigPortalPersistent();
  }
}

#endif


//#include <ESP8266_Lib.h>
//#include <BlynkSimpleShieldEsp8266.h>
#include <DHT.h>
#define DHTPIN 40
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
BlynkTimer timer;

void sendSensor()
{
  float h = dht.readHumidity();
  float t = dht.readTemperature(); // or dht.readTemperature(true) for Fahrenheit

  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  // You can send any value at any time.
  // Please don't send more that 10 values per second.
  Blynk.virtualWrite(V5, h);
  Blynk.virtualWrite(V6, t);
}

void heartBeatPrint()
{
  static int num = 1;

  if (Blynk.connected())
  {
    Serial.print(F("B"));
  }
  else
  {
    Serial.print(F("F"));
  }

  if (num == 80)
  {
    Serial.println();
    num = 1;
  }
  else if (num++ % 10 == 0)
  {
    Serial.print(F(" "));
  }
}

void check_status()
{
  static unsigned long checkstatus_timeout = 0;

#define STATUS_CHECK_INTERVAL     15000L

  // Send status report every STATUS_REPORT_INTERVAL (60) seconds: we don't need to send updates frequently if there is no status change.
  if ((millis() > checkstatus_timeout) || (checkstatus_timeout == 0))
  {
    // report status to Blynk
    heartBeatPrint();

    checkstatus_timeout = millis() + STATUS_CHECK_INTERVAL;
  }
}

void setup()
{
  // Debug console
  Serial.begin(115200);
  while (!Serial);

  delay(500);

  Serial.print(F("\nStart Mega_ESP8266Shield on ")); Serial.println(BOARD_NAME);
  Serial.println(BLYNK_ESP8266AT_WM_VERSION);
  Serial.println(ESP_AT_LIB_VERSION);

  // initialize serial for ESP module
  EspSerial.begin(ESP8266_BAUD);

#if USE_BLYNK_WM
  Serial.println(DOUBLERESETDETECTOR_GENERIC_VERSION);
  Serial.println(F("Start Blynk_ESP8266AT_WM"));

  // Optional to change default AP IP(192.168.4.1) and channel(10)
  //Blynk.setConfigPortalIP(IPAddress(192, 168, 120, 1));
  // Personalized portal_ssid and password
  Blynk.setConfigPortal(portal_ssid, portal_password);
  //Blynk.setConfigPortal("Mega_WM", "MyMega_PW");
  Blynk.setConfigPortalChannel(0);
  
  Blynk.begin(wifi);
#else
  Serial.print(F("Start Blynk no WM with BlynkServer = "));
  Serial.print(BlynkServer);
  Serial.print(F(" and Token = "));
  Serial.println(auth);

  Blynk.begin(auth, wifi, ssid, pass, BlynkServer, BLYNK_SERVER_HARDWARE_PORT);
#endif
dht.begin();
timer.setInterval(1000L, sendSensor);

}

void loop()
{
  Blynk.run();
  check_status();
  timer.run();
}

Serial Monitor :


Start Mega_ESP8266Shield on AVR Mega2560
Blynk_Esp8266AT_WM v1.3.0
ESP_AT_Lib v1.2.0
DoubleResetDetector_Generic v1.2.0
Start Blynk_ESP8266AT_WM
[7085] AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK

EEPROM size = 4096, start = 0
Flag read = 0xd0d04321
No doubleResetDetected
SetFlag write = 0xd0d01234
[8624] CCSum=0x19b5,RCSsum=0x19b5
[8625] Hdr=SHD_ESP8266,SSID=Vodafone-*****,PW=**********
[8628] Svr=blynk-cloud.com,Prt=8080,Tok=nHbW4mMzh6KQRPpkN-HwLZaf15g1sFp2
[8634] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on Arduino Mega

[8647] Con2Wifi
[8648] con2WF:SSID=Vodafone-*****,PW=*********
[8652] Con2:Vodafone-******
[15233] AT version:1.1.0.0(May 11 2016 18:09:56)
SDK version:1.5.4(baaeaebb)
Ai-Thinker Technology Co. Ltd.
Jun 13 2016 11:29:20
OK
[15778] Mac=cc:50:e3:5d:c4:44
[22794] IP=192.168.0.175

[22815] WOK
[22815] con2WF:OK
[22815] IP=192.168.0.175

[22838] b:WOK.TryB
[33088] Ready (ping: 11ms).
[33499] b:WBOK
Stop doubleResetDetecting
ClearFlag write = 0xd0d04321
BBBBBBBBBB BBBBBB

Picture:

  1. remove this from your void loop:
  1. Change this:

to this:

timer.setInterval(5000L, sendSensor);

  1. Add these lines to the end of your sendSensor() function:
Serial.print("Humidity: ");
Serial.println(h);
Serial.print("Temperature : ");
Serial.println(t);

Pete.

1 Like

Thanks for help, i will try to add co2, ultrasonic sensor, soil moisure sensor later more sensors :slight_smile:
Challenge for me will be to code that slider value min 0 max 24 , value means how many hours light will be on and how many hours light will be off, than i need to think about what will happen if wifi will be lost how to set all working also without wifi, few days with research, i hope i will do it :slight_smile: