ESP32, Wifimanager, integration with Blynk

board : ESP32 IOT DEV BOARD 30PIN
blynk server

I made numerous attempts, among these I attach the semi-functioning one. the problem is that the connection to the blynk server continues to reboot.

Can anyone help me? COSTAS!! please help me!


#define BLYNK_PRINT Serial    // Comment this out to disable prints and save space
#include <SPI.h>
#include <WiFi.h>
#include <BlynkSimpleEsp32.h>
#include <SimpleTimer.h>
#include <EEPROM.h>


#include <WebServer.h>
#include <DNSServer.h>
#include <WiFiManager.h>

#include <Ticker.h>
Ticker ticker;
SimpleTimer timer;

char auth[] = "xxxxxxxxxxxxxxxxxxxxxxx";       // You should get Auth Token in the Blynk App.
bool isFirstConnect = true;



#define ledPower 4            // LED Power                    ( Pin D0 )

#define TRIGGER_PIN 15     // Button     Reset Network     ( Pin D3 )
#define LED_PIN 2         // LED        connection status ( Pin D4 )



void tick()
{
  int state = digitalRead(LED_PIN);
  digitalWrite(LED_PIN, !state);
}
void configModeCallback (WiFiManager *myWiFiManager) {
  ticker.attach(0.2, tick);
}

BLYNK_CONNECTED() {
if (isFirstConnect) {
 Blynk.syncAll(); 
 Blynk.notify("ADS1115 STARTING!!!!");
isFirstConnect = false;
}
}

void reconnectBlynk() {
  if (!Blynk.connected()) {
    if(Blynk.connect()) {
     BLYNK_LOG("Reconnected");
    } else {
      BLYNK_LOG("Not reconnected");
    }
  }
}

void setup()
{
  Serial.begin(9600); 
  EEPROM.begin(512);   
  pinMode(TRIGGER_PIN, INPUT);
  pinMode(LED_PIN, OUTPUT);
  
  WiFiManager wifiManager;
  ticker.attach(0.6, tick);
  wifiManager.setAPCallback(configModeCallback);
  if (!wifiManager.autoConnect("Ap Name")) {                          //    your ap name
    wifiManager.setConfigPortalTimeout(180);


      
    delay(1000);
  }
ticker.detach();
digitalWrite(LED_PIN, HIGH);


timer.setInterval(30000L, reconnectBlynk);  // check every 30s if still connected to server 
  Blynk.config(auth);
  int mytimeout = millis() / 1000;
  while (Blynk.connect() == false) { // try to connect to server for 10 seconds
    if((millis() / 1000) > mytimeout + 8){ // try local server if not connected within 9 seconds
       break;
    }
  }
}

void loop()
{

  int count = 0;
    
    if (Blynk.connected()) {
    Blynk.run();    
  }
  timer.run();
  Blynk.run();
  


// Reset the network
  while(digitalRead(TRIGGER_PIN) == LOW) {
    delay(100);
    count++;
    if(count > 30) {
      //ESP.eraseConfig();
      WiFi.disconnect();
      digitalWrite(LED_PIN, LOW);
      delay(1000);
      count = 0;
      digitalWrite(LED_PIN, HIGH);
      delay(100);
      ESP.restart();
      delay(1000);
    }
  }EEPROM.commit();
}

That void loop looks very messy.
You have two Blynk.runs in there, plus this blocking while loop.

What happens if you trim this down to just Blynk.run and timer.run in the void loop?

Pete.

Is the same result. thanks a lot for help.

2 posts were split to a new topic: Need help converting WiFiManager code from ESP8266 to ESP32