ESP32 dual core

Hello Everyone! My problem would be that while the esp32 reconnects to wifi, nothing else works. I already tried dual core, but it still doesn't work. So: if there is no wifi, it won't work until then, for example:

 if (buttonState1 != lastButtonState1) {
    if (buttonState1 == HIGH) {
     digitalWrite(ledPin1, LOW);

I want digitalWrite to work even when there is no wifi. How could this be solved?

I moved your topic to an appropriate forum category @azxo1 .

In the future, please take some time to pick the forum category that best suits the subject of your topic. There is an "About the _____ category" topic at the top of each category that explains its purpose.

This is an important part of responsible forum usage, as explained in the "How to get the best out of this forum" guide. The guide contains a lot of other useful information. Please read it.

Thanks in advance for your cooperation.

There is no dependency on WiFi in the code you posted. So, you're good to go.

OOOOO! That this has not been noticed until now. Thank you for your valuable help. :slight_smile:

#include <Arduino.h>    
#include <Wire.h>
#include <WiFi.h>
#include <PubSubClient.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
#include <U8g2lib.h>
#include <WiFiUdp.h>
#include <WiFiMulti_Generic.h> 

TaskHandle_t Task1;
TaskHandle_t Task2;

const char* ssid = "WWWWWWWWWW";
const char* password =  "AAAAAAAAAAA";
const char* mqttServer = "CCCCCCCCCC";
const int mqttPort = 1883;
const char* mqttUser = "XXXXXXXXXXXXXX";
const char* mqttPassword = "XXXXXXXXXXXXXX";

unsigned long lastRun1 = 0;
unsigned long lastRun2 = 0;
unsigned long lastRun3 = 0;
unsigned long lastRun4 = 0;


 int buttonPin1 = 15;    
 int ledPin1 = 13;        

 int buttonPin2 = 12;    
 int ledPin2 = 14;

int counter = 0;

int buttonState1 = 0;
int lastButtonState1 = 0; 

int buttonState2 = 0;
int lastButtonState2 = 0; 

bool buttonstate1 = true;
bool buttonstate2 = true;


const char* NTPtime = "NTP/time";
String ntptimeo;

AsyncWebServer server(80);



WiFiClient KONYHA;              //KONYHA
PubSubClient client(KONYHA);

      IPAddress ip(192, 168, 5, 116);  
      IPAddress gateway(192, 168, 5, 1);
      IPAddress subnet(255, 255, 255, 0);

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);


void setup() {

  pinMode(buttonPin1, INPUT);
  pinMode(ledPin1, OUTPUT);
  
  pinMode(buttonPin2, INPUT);
  pinMode(ledPin2, OUTPUT);



    WiFi.config(ip, gateway, subnet);  
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);

    u8g2.begin();

 /*
     while (WiFi.status() != WL_CONNECTED)
  {
    delay(200);
    if (++counter > 100)
    delay(1000);
    //  ESP.restart();
  } 
*/
    client.setServer(mqttServer, mqttPort);
    client.setCallback(callback);
    AsyncElegantOTA.begin(&server);

           while (!client.connected()) {
      if (client.connect("KONYHA", mqttUser, mqttPassword )) {
  client.subscribe("lamp/konyhalamp");
  client.subscribe("lamp/konyhaled");
  client.subscribe("hiba/viz");
  client.subscribe("hiba/suto");
  client.subscribe("hiba/fozolap");
  client.subscribe("NTP/time");
      delay(50);   
     }
     }

  //create a task that will be executed in the Task1code() function, with priority 1 and executed on core 0
  xTaskCreatePinnedToCore(
                    Task1code,   /* Task function. */
                    "Task1",     /* name of task. */
                    10000,       /* Stack size of task */
                    NULL,        /* parameter of the task */
                    1,           /* priority of the task */
                    &Task1,      /* Task handle to keep track of created task */
                    0);          /* pin task to core 0 */                  
  delay(500); 

  //create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1
  xTaskCreatePinnedToCore(
                    Task2code,   /* Task function. */
                    "Task2",     /* name of task. */
                    10000,       /* Stack size of task */
                    NULL,        /* parameter of the task */
                    1,           /* priority of the task */
                    &Task2,      /* Task handle to keep track of created task */
                    1);          /* pin task to core 1 */
    delay(500);
     
 //   server.begin(); 
  //  WiFi.setAutoReconnect(true);
 //   WiFi.persistent(true);

/*     // Send web page to client
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html);
  });

  // Receive an HTTP GET request
  server.on("/on", HTTP_GET, [] (AsyncWebServerRequest *request) {
    ESP.restart();
    request->send(200, "text/plain", "ok");
  });
  */
server.begin();
delay(20000);
  
}



void Task2code( void * pvParameters ){


  for(;;){
 if (millis() - lastRun1 > 400)
  {
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);




 //////////////////////////////////////////////////////////////////////   1
  if (buttonState1 != lastButtonState1) {
    if (buttonState1 == HIGH) {
   
      digitalWrite(ledPin1, LOW);
     //  client.publish("lamp/konyhalamp1", "off");
    } else {
 
       digitalWrite(ledPin1, HIGH);
     //  client.publish("lamp/konyhalamp1", "on");
    }
  lastButtonState1 = buttonState1;
  }
 
//delay(50);
 //////////////////////////////////////////////////////////////////////   
  if (buttonState2 != lastButtonState2) {
    if (buttonState2 == HIGH) {
 
      digitalWrite(ledPin2, LOW);
    //  client.publish("lamp/konyhaled1", "off");
    } else {

       digitalWrite(ledPin2, HIGH);
    //   client.publish("lamp/konyhaled1", "on");
    }
  lastButtonState2 = buttonState2;
  }
  
   lastRun1 = millis();
  }
  } 
}



void Task1code( void * pvParameters ){


  for(;;){
   //////////////////////////////////////////////////////////////////////   

 if (millis() - lastRun2 > 1000)
  {
                                if  ((digitalRead (13)) == LOW) { client.publish("test/konyhalamp", "on"); }  
                               if  ((digitalRead (13)) == HIGH) { client.publish("test/konyhalamp", "off"); }

                             //   if  ((digitalRead (14)) == LOW) { client.publish("test/konyhaled1", "off"); }  
                              //  if  ((digitalRead (14)) == HIGH) { client.publish("test/konyhaled1", "on"); }
 

    lastRun2 = millis();
 }

 //////////////////////////////////////////////////////////////////////   


  if (millis() - lastRun4 > 1000)
  {
    printLocalTime();
    lastRun4 = millis();
 }


 //////////////////////////////////////////////////////////////////////   


 if (millis() - lastRun3 > 1000)
  {

    if(!client.connected())reconnect();

    
     while (WiFi.status() != WL_CONNECTED)
   {
    WiFi.config(ip, gateway, subnet); 
    delay(50);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    }

   lastRun3 = millis();
  }
 //////////////////////////////////////////////////////////////////////   
  }
}


void hivogat() {
    while (WiFi.status() != WL_CONNECTED)
  {
    WiFi.config(ip, gateway, subnet); 
    delay(50);
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
    

}
}

void reconnect() {
    client.setServer(mqttServer, mqttPort);
     client.connect("KONYHA", mqttUser, mqttPassword );

  client.subscribe("lamp/konyhalamp");
  client.subscribe("lamp/konyhaled");
  client.subscribe("hiba/viz");
  client.subscribe("hiba/suto");
  client.subscribe("hiba/fozolap");
  client.subscribe("NTP/time");
   
  } 

void callback(char *topic, byte *payload, unsigned int length) {
  
 payload[length] = '\0';
   if(strcmp(topic,"lamp/konyhalamp")==0)
   {

       if(strcmp((char*)payload,"on")==0)         
       {
             digitalWrite(ledPin1,HIGH);
        }
       else if(strcmp((char*)payload,"off")==0)      
       {
             digitalWrite(ledPin1,LOW);
        }
        lastButtonState1 = buttonState1;
   }
////////////////////////////////////////////////////////////
      if(strcmp(topic,"lamp/konyhaled")==0)
   {

       if(strcmp((char*)payload,"on")==0)          
       {
             digitalWrite(ledPin2,HIGH);
        }
       else if(strcmp((char*)payload,"off")==0)       
       {
             digitalWrite(ledPin2,LOW);
     
        }
        lastButtonState2 = buttonState2;
   }
////////////////////////////////////////////////////////////

               if (strcmp(topic,NTPtime)==0){
      payload[length] = '\0';
      ntptimeo = ((char *)payload);
       }
}


void printLocalTime()
{

  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_inb24_mr); // u8x8.setFont(u8x8_font_courB18_2x3_f);
  u8g2.setCursor(12, 40);      //szélesség/magasság
  u8g2.print(ntptimeo);
  u8g2.sendBuffer();

}



void loop() {
//  client.loop(); 
  }

Is it better that way?
E.g. if I tinker with my mikrotik router (e.g. netinstall) and there is no wifi, the switch does not work. The above code is a proximity switch with an oled display and turns on a light. If there is no wifi, the switch does not work either. How could this be eliminated?

by writing a code that does execute the above lines inside
void loop() independant of other conditions.

The reason that it does not work with WiFi unconnected might be even that you use both cores !

One core handles all the WiFi-stuff. If you keep your own code in the other core = the NON-WiFi-core it will surely work

Why do you feel the need to use both cores?
Usually occupping the second core si just a lack of knowledge how to keep code nonblocking

I fixed your atrocious indentation:

Did you write this code yourself?

I don't know how AsyncElegantOTA.begin() behaves when there's no WiFi connection. But without WiFi, I don't see how client.connected() will ever return true. So, what do you that while loop does?

But that's not the question. (especially not the OTA, so how could it be without wifi???? :slight_smile:
) I thought it was quite clear that at first I only used core1, then I tried to manage the additional codes in core0 later (code above). Of course, I know that core0 deals with network management and other such things, I've already tried both methods. As e.g. Core0's digitalWrite handling and core1's reconnect and wifi.begin events, and vice versa... Probably because of my poor English, it's not entirely clear what I want. It's simple: wifi is required for esp32 to work. But if by chance it is not there, the switch should still work:
if (buttonState2 != lastButtonState2) { if (buttonState2 == HIGH) { digitalWrite(ledPin2, LOW);
Because while the esp32 is busy reconnecting, it won't work. Question: Is there a solution to this?

Read this again:

MQTT reconnection. And I'm not interested in AsyncElegantOTA, because it's quite clear that it doesn't work without an ip address.

A proximity switch is connected to the esp32. https://www.instructables.com/Interfacing-TTP223-Capacitive-Touch-Sensor-With-Ar/
The code for this :

if (buttonState2 != lastButtonState2) {
        if (buttonState2 == HIGH) {
           digitalWrite(ledPin2, LOW);
        } else {
           digitalWrite(ledPin2, HIGH);
    }
  lastButtonState2 = buttonState2;
  }

If there's no wifi because I'm fixing the mikrotik router, this little piece of code won't work either, because the esp32 is busy reconnecting to the wifi. My question is, is there a solution to make my switch work even during wifi reconnect?

I'll try one more time and then I'm out:

Without WiFi, I don't see how client.connected() will ever return true . So how will your code exit the while loop?

:slight_smile: is this serious now? It exits the cycle when it can rejoin. But that's exactly the point!!!! I tried using core0 and core1 separately because I thought that as long as core0 is busy with the while loop and waiting for the return value to be true, the digitalWrite code can work in core1. But unfortunately it's not like that, that's why I asked my question here, is there a solution for this????? Do you understand yet????

Or is the solution to just put an if instead of a while loop?

The trouble is, you don't understand what you're doing. That while() loop is in your setup() function before you create Task1 or Task2. Since the while() never exits, the tasks are never created, so your code in those tasks never executes.

It is always a good idea for debugging to add a lot of serial printing to make visible what your code is doing and what not

I took the while loop out of the code, which I understood. Here is the "clean" code below. I would think so until the reconnection in core0 (//Task1code), the code in core1 (//Task2code) runs smoothly. but unfortunately not.

#include <Arduino.h>    
#include <Wire.h>
#include <WiFi.h>
#include <PubSubClient.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
#include <U8g2lib.h>
#include <WiFiUdp.h>
#include <WiFiMulti_Generic.h> 

TaskHandle_t Task1;
TaskHandle_t Task2;

const char* ssid = "xxxxxxxxxxx";
const char* password =  "xxxxxxxxx";
const char* mqttServer = "xxxxxxxxxx";
const int mqttPort = 1883;
const char* mqttUser = "xxxxxxxxxx";
const char* mqttPassword = "xxxxxxxxxx";

unsigned long lastRun1 = 0;
unsigned long lastRun2 = 0;
unsigned long lastRun3 = 0;
unsigned long lastRun4 = 0;


 int buttonPin1 = 15;    
 int ledPin1 = 13;        

 int buttonPin2 = 12;    
 int ledPin2 = 14;

int counter = 0;

int buttonState1 = 0;
int lastButtonState1 = 0; 

int buttonState2 = 0;
int lastButtonState2 = 0; 

bool buttonstate1 = true;
bool buttonstate2 = true;


const char* NTPtime = "NTP/time";
String ntptimeo;

AsyncWebServer server(80);



WiFiClient KONYHA;              
PubSubClient client(KONYHA);

      IPAddress ip(192, 168, 5, 116);  
      IPAddress gateway(192, 168, 5, 1);
      IPAddress subnet(255, 255, 255, 0);

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup() {

  pinMode(buttonPin1, INPUT);
  pinMode(ledPin1, OUTPUT);
  
  pinMode(buttonPin2, INPUT);
  pinMode(ledPin2, OUTPUT);

  u8g2.begin();

    WiFi.config(ip, gateway, subnet);  
    WiFi.mode(WIFI_STA);
    WiFi.begin(ssid, password);
         
 //   client.setCallback(callback);
    
    AsyncElegantOTA.begin(&server);


  xTaskCreatePinnedToCore(
                    Task1code,   /* Task function. */
                    "Task1",     /* name of task. */
                    10000,       /* Stack size of task */
                    NULL,        /* parameter of the task */
                    1,           /* priority of the task */
                    &Task1,      /* Task handle to keep track of created task */
                    0);          /* pin task to core 0 */                  
  delay(500); 

  //create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1
  xTaskCreatePinnedToCore(
                    Task2code,   /* Task function. */
                    "Task2",     /* name of task. */
                    10000,       /* Stack size of task */
                    NULL,        /* parameter of the task */
                    1,           /* priority of the task */
                    &Task2,      /* Task handle to keep track of created task */
                    1);          /* pin task to core 1 */
    delay(500); 

server.begin();
delay(20000);
  
}
void printLocalTime()
{

  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_inb24_mr); // u8x8.setFont(u8x8_font_courB18_2x3_f);
  u8g2.setCursor(12, 40);      //szélesség/magasság
  u8g2.print(ntptimeo);
  u8g2.sendBuffer();

}

void printLocalTimeNOWIFI()
{

  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_inb24_mr); // u8x8.setFont(u8x8_font_courB18_2x3_f);
  u8g2.setCursor(12, 40);      //szélesség/magasság
  u8g2.print("00:00");
  u8g2.sendBuffer();

}
////////////////////////////////////////////////////////////////////////////////////////////


//Task1code

void Task1code( void * pvParameters ){

 for(;;){
 if (millis() - lastRun3 > 10000) {
  
    WiFi.config(ip, gateway, subnet); 
    WiFi.mode(WIFI_STA);  
    WiFi.begin(ssid, password);
    
    
      client.setServer(mqttServer, mqttPort);
      client.connect("KONYHA", mqttUser, mqttPassword );

        client.subscribe("lamp/konyhalamp");
        client.subscribe("lamp/konyhaled");
        client.subscribe("hiba/viz");
        client.subscribe("hiba/suto");
        client.subscribe("hiba/fozolap");
        client.subscribe("NTP/time");
  
   lastRun3 = millis();
  }
  } 
}
////////////////////////////////////////////////////////////////////////

//Task2code

void Task2code( void * pvParameters ){

  for(;;){
  
 if (millis() - lastRun1 > 400)
  {
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);

 //////////////////////////////////////////////////////////////////////   1
  if (buttonState1 != lastButtonState1) {
    if (buttonState1 == HIGH) {
   
      digitalWrite(ledPin1, LOW);
     
    } else {
 
       digitalWrite(ledPin1, HIGH);
  
    }
  lastButtonState1 = buttonState1;
  }
 
//delay(50);
 //////////////////////////////////////////////////////////////////////   
  if (buttonState2 != lastButtonState2) {
    if (buttonState2 == HIGH) {
       digitalWrite(ledPin2, LOW);
  
    } else {

       digitalWrite(ledPin2, HIGH);
   
    }
  lastButtonState2 = buttonState2;
  }
  
   lastRun1 = millis();
  }

  
   //////////////////////////////////////////////////////////////////////   
 
  if (millis() - lastRun4 > 1000)
  {
    if (WiFi.status() == WL_CONNECTED)
       {
        printLocalTime();
       } else {
        printLocalTimeNOWIFI();
       }
   
    lastRun4 = millis();
 }
  }
}

void loop() {
//  client.loop(); 

}






 

Here is exact your code with additional debug-printing to mkae visible what code gets executed and which not.

// MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START * MACRO-START *
// a detailed explanation how these macros work is given in this tutorial
// https://forum.arduino.cc/t/comfortable-serial-debug-output-short-to-write-fixed-text-name-and-content-of-any-variable-code-example/888298

#define dbg(myFixedText, variableName) \
  Serial.print( F(#myFixedText " "  #variableName"=") ); \
  Serial.println(variableName);

#define dbgi(myFixedText, variableName,timeInterval) \
  { \
    static unsigned long intervalStartTime; \
    if ( millis() - intervalStartTime >= timeInterval ){ \
      intervalStartTime = millis(); \
      Serial.print( F(#myFixedText " "  #variableName"=") ); \
      Serial.println(variableName); \
    } \
  }

#define dbgc(myFixedText, variableName) \
  { \
    static long lastState; \
    if ( lastState != variableName ){ \
      Serial.print( F(#myFixedText " "  #variableName" changed from ") ); \
      Serial.print(lastState); \
      Serial.print( F(" to ") ); \
      Serial.println(variableName); \
      lastState = variableName; \
    } \
  }

#define dbgcf(myFixedText, variableName) \
  { \
    static float lastState; \
    if ( lastState != variableName ){ \
      Serial.print( F(#myFixedText " "  #variableName" changed from ") ); \
      Serial.print(lastState); \
      Serial.print( F(" to ") ); \
      Serial.println(variableName); \
      lastState = variableName; \
    } \
  }
// MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END * MACRO-END *

#include <Arduino.h>
#include <Wire.h>
#include <WiFi.h>
#include <PubSubClient.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
#include <U8g2lib.h>
#include <WiFiUdp.h>
#include <WiFiMulti_Generic.h>

TaskHandle_t Task1;
TaskHandle_t Task2;

const char* ssid = "xxxxxxxxxxx";
const char* password =  "xxxxxxxxx";
const char* mqttServer = "xxxxxxxxxx";
const int mqttPort = 1883;
const char* mqttUser = "xxxxxxxxxx";
const char* mqttPassword = "xxxxxxxxxx";

unsigned long lastRun1 = 0;
unsigned long lastRun2 = 0;
unsigned long lastRun3 = 0;
unsigned long lastRun4 = 0;


int buttonPin1 = 15;
int ledPin1 = 13;

int buttonPin2 = 12;
int ledPin2 = 14;

int counter = 0;

int buttonState1 = 0;
int lastButtonState1 = 0;

int buttonState2 = 0;
int lastButtonState2 = 0;

bool buttonstate1 = true;
bool buttonstate2 = true;


const char* NTPtime = "NTP/time";
String ntptimeo;

AsyncWebServer server(80);



WiFiClient KONYHA;
PubSubClient client(KONYHA);

IPAddress ip(192, 168, 5, 116);
IPAddress gateway(192, 168, 5, 1);
IPAddress subnet(255, 255, 255, 0);

U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);

void setup() {
  Serial.begin(115200);
  Serial.println("Steup-Start");

  pinMode(buttonPin1, INPUT);
  pinMode(ledPin1, OUTPUT);

  pinMode(buttonPin2, INPUT);
  pinMode(ledPin2, OUTPUT);

  u8g2.begin();
  Serial.println("u8g2.begin done");

  WiFi.config(ip, gateway, subnet);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  Serial.println("WiFi.begin done");

  //   client.setCallback(callback);

  AsyncElegantOTA.begin(&server);
  Serial.println("AsyncElegantOTA.begin done");

  xTaskCreatePinnedToCore(
    Task1code,   /* Task function. */
    "Task1",     /* name of task. */
    10000,       /* Stack size of task */
    NULL,        /* parameter of the task */
    1,           /* priority of the task */
    &Task1,      /* Task handle to keep track of created task */
    0);          /* pin task to core 0 */
  delay(500);
  Serial.println("xTaskCreatePinnedToCore 1 done");

  //create a task that will be executed in the Task2code() function, with priority 1 and executed on core 1
  xTaskCreatePinnedToCore(
    Task2code,   /* Task function. */
    "Task2",     /* name of task. */
    10000,       /* Stack size of task */
    NULL,        /* parameter of the task */
    1,           /* priority of the task */
    &Task2,      /* Task handle to keep track of created task */
    1);          /* pin task to core 1 */
  delay(500);
  Serial.println("xTaskCreatePinnedToCore 2 done");

  server.begin();
  Serial.println("server.begin done");

  delay(20000);
  Serial.println("delay(20000) done");

}

void printLocalTime() {
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_inb24_mr); // u8x8.setFont(u8x8_font_courB18_2x3_f);
  u8g2.setCursor(12, 40);      //szélesség/magasság
  u8g2.print(ntptimeo);
  u8g2.sendBuffer();
}

void printLocalTimeNOWIFI() {
  u8g2.clearBuffer();
  u8g2.setFont(u8g2_font_inb24_mr); // u8x8.setFont(u8x8_font_courB18_2x3_f);
  u8g2.setCursor(12, 40);      //szélesség/magasság
  u8g2.print("00:00");
  u8g2.sendBuffer();
}
////////////////////////////////////////////////////////////////////////////////////////////


//Task1code

void Task1code( void * pvParameters ) {

  for (;;) {
    if (millis() - lastRun3 > 10000) {

      WiFi.config(ip, gateway, subnet);
      WiFi.mode(WIFI_STA);
      WiFi.begin(ssid, password);
      Serial.println("task1code WiFiBegin done");

      client.setServer(mqttServer, mqttPort);
      client.connect("KONYHA", mqttUser, mqttPassword );
      Serial.println("client.connect done");

      client.subscribe("lamp/konyhalamp");
      client.subscribe("lamp/konyhaled");
      client.subscribe("hiba/viz");
      client.subscribe("hiba/suto");
      client.subscribe("hiba/fozolap");
      client.subscribe("NTP/time");

      lastRun3 = millis();
    }
  }
}
////////////////////////////////////////////////////////////////////////

//Task2code

void Task2code( void * pvParameters ) {

  static long myCount = 0;
  Serial.println("entering Task2code");
    
  for (;;) {

    dbgi("Task2code",myCount++,1000);
    
    if (millis() - lastRun1 > 400) {
      buttonState1 = digitalRead(buttonPin1);
      buttonState2 = digitalRead(buttonPin2);

      //////////////////////////////////////////////////////////////////////   1
      if (buttonState1 != lastButtonState1) {
        if (buttonState1 == HIGH) {
          digitalWrite(ledPin1, LOW);
        } 
        else {
          digitalWrite(ledPin1, HIGH);
        }
        lastButtonState1 = buttonState1;
      }

      //delay(50);
      //////////////////////////////////////////////////////////////////////
      if (buttonState2 != lastButtonState2) {
        if (buttonState2 == HIGH) {
          digitalWrite(ledPin2, LOW);
        } 
        else {
          digitalWrite(ledPin2, HIGH);
        }
        lastButtonState2 = buttonState2;
      }
      lastRun1 = millis();
    }


    //////////////////////////////////////////////////////////////////////

    if (millis() - lastRun4 > 1000) {
      if (WiFi.status() == WL_CONNECTED) {
        printLocalTime();
      } 
      else {
        printLocalTimeNOWIFI();
      }
      lastRun4 = millis();
    }
  }
}

void loop() {
  //  client.loop();

}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.