Update value after reading thingspeak

Hallo to community.
I manage to retrieve data from thingspeak which in my case is public and I am doing that in case of a power loss to have the last stored value back again. My problem is I can't set the value to the stored value. I can print the value to serial monitor but I can't use it in my loop in order the value I want to begin from the stored one. I want this to happen once and at the beginning in order after rebooting the value of totalLitres to be updated from the one retrieved from thingspeak. The code below is shorted in order to become easier to read.
Thanks so much for your help.


// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 30000;          // your network key Index number (needed only for WEP)
WiFiClient  client;

// Initialize our values
String myStatus = "";
float temp;    // get temperature in °C
float humi;       // get humidity in %
float pres;    
long currentMillis = 0;
long previousMillis = 0;
int interval = 1000;

float flowLitres;
float totalLitres;

void setup() {
  Serial.begin(115200);

  WiFi.mode(WIFI_STA);   
  ThingSpeak.begin(client); 
  
 
  pulseCount = 0;
  flowRate = 0.0;
  flowMilliLitres = 0;
  totalMilliLitres = 0;
  previousMillis = 0;
 attachInterrupt(digitalPinToInterrupt(SENSOR), pulseCounter, FALLING); 
 
}

void loop() {
  if(WiFi.status() != WL_CONNECTED){
      Serial.print("Attempting to connect");
      while(WiFi.status() != WL_CONNECTED){
        WiFi.begin(ssid, password); 
        delay(10000);     
      } 
      Serial.println("\nConnected.");
      printWifiStatus();
      readTLData(); // read last logged totallitres data 
      Serial.println("Updating totalLitres adding+");
    }
    
    if ((millis() - lastTime) > timerDelay) {
    // Get
    ThingSpeak.setField(1, temp);
    ThingSpeak.setField(2, humi);
    ThingSpeak.setField(3, pres/100);
    ThingSpeak.setField(4, flowLitres);
    ThingSpeak.setField(5, totalLitres);    
    int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    
    if(x == 200){
      Serial.println("Channel update successful.");
    }
    else{
      Serial.println("Problem updating channel. HTTP error code " + String(x));
    }
    lastTime = millis();
   }
   temp = aht20.getTemperature();    // get temperature in °C
   humi = aht20.getHumidity();       // get humidity in %
   pres = bmp.readPressure();       // get pressure in Pa
   Serial.printf("Temperature: %.02f *C\n", temp);
   Serial.printf("Humidity: %.02f %RH\n", humi);
   Serial.printf("Pressure: %.02f hPa\n", pres/100);
   // CODE FROM flow.h
    currentMillis = millis();
  if (currentMillis - previousMillis > interval) {
    pulse1Sec = pulseCount;
    pulseCount = 0;
    flowRate = ((1000.0 / (millis() - previousMillis)) * pulse1Sec) / calibrationFactor;
    previousMillis = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    flowLitres = (flowRate / 60);
    totalMilliLitres += flowMilliLitres;
    totalLitres += flowLitres;
    
  delay(5000); // Wait 20 seconds to update the channel again
}

void pulseCounter()
{
  pulseCount++;
}
void readTLData() {
  
  long TL = ThingSpeak.readLongField(myChannelNumber, FieldNumber5, myReadAPIKey);
  int y = ThingSpeak.getLastReadStatus();
  if (y == 200)
  {
    Serial.print("Totallitres from ThingSpeak: ");
    Serial.println(TL);
  }
  else
  {
    Serial.println("Unable to read channel / No internet connection");
  }
  delay(100);
  //-------------- End of Channel  -------------//
}

Here is the output in serial monitor:

  1. Attempting to connect
  2. Connected.
  3. SSID: CYTA_CRby_2.4G
  4. IP Address: 192.168.10.2
  5. Signal strength (RSSI):-49 dBm
  6. Totallitres from ThingSpeak: 0
  7. Updating totalLitres adding+
  8. Temperature: 24.87 *C
  9. Humidity: 69.31 RH
  10. Pressure: 1013.88 hPa
  11. Flow rate: 0.00L/min Output Liquid Quantity: 0mL / 0.00L
    Overall I want line 6 to enter line 11 as the new output to begin with!

As from your request you need to start the program by accepting the value from thingspeak . You want total liters then you can make the function void readTLData() to int readTLData() with return TL; so when you call this function it will give you the value so in your code when you need to add the totalliters from thingspeak long ThTL=readTLData() ; the Thtl will have the value of TL from thingspeak and also change the function like this

int readTLData() {
  
  long TL = ThingSpeak.readLongField(myChannelNumber, FieldNumber5, myReadAPIKey);
  int y = ThingSpeak.getLastReadStatus();
  if (y == 200)
  {
    Serial.print("Totallitres from ThingSpeak: ");
    Serial.println(TL);
return TL;
  }
  else
  {
    Serial.println("Unable to read channel / No internet connection");
return -1; // Negative value if data is not available
  }
  delay(100);
  //-------------- End of Channel  -------------//
}

Tkank you so much. This totally make sense to me. I will try it and as soon as practicable I let you know the result.

Hallo to community. I have managed to get to thingspeak the values I want with the code above. I tried to upgrade the code but when it is connected to thinkspeak the nodemcu32s crashes and reboots. I tried several things but the result the same. Even I isolated the power consumptions but the ESP keeps crashes.

#include <WiFi.h>
#include "ThingSpeak.h"
#include <Wire.h>
#include <WiFiClient.h>
#include <HTTPClient.h>
#include <AHT20.h>
#include <Adafruit_BMP280.h>
#define SENSOR  27
Adafruit_BMP280 bmp;
AHT20 aht20;
const char *ssid     = "CYTA_CRby_2.4G";
const char *password = "erererere";
unsigned long lastTime = 0;
unsigned long timerDelay = 1000;
unsigned long startTime = 0; // Start time for sensor timing
unsigned long totalElapsedTime = 0; // Total elapsed time for sensor timing
unsigned long lastThingSpeakUpdateTime = 0; // Last time ThingSpeak fields were updated
unsigned long lastPrintTime = 0; // Last time sensor elapsed time was printed
const unsigned long thingSpeakUpdateInterval = 60000; //
bool timing = false; // Flag to indicate whether timing is active
const int FieldNumber = 5;  // The field you wish to read
const int sensorPin = SENSOR;
WiFiClient client;
unsigned long myChannelNumber = 2514774;
const char *myWriteAPIKey = "Y9V8GLKAH5ZOAA7Q";
const char *myReadAPIKey = "X7GOTNVKG9JH4XJT";
float temp;    // get temperature in °C
float humi;    // get humidity in %
float pres;
long currentMillis = 0;
long previousMillis = 0;
int interval = 5000;
float calibrationFactor = 0.45;
volatile byte pulseCount;
byte pulse1Sec = 0;
float flowRate;
unsigned long flowMilliLitres;
unsigned int totalMilliLitres;
float flowLitres;
float totalLitres;
void IRAM_ATTR pulseCounter();

void setup() {
    Serial.begin(115200);
    WiFi.mode(WIFI_STA);
    ThingSpeak.begin(client);
    WiFi.begin(ssid, password);
    Wire.begin();
    if (aht20.begin() == false) {
        Serial.println("AHT20 not detected. Please check wiring. Freezing.");
        while (1);
    }
    Serial.println("AHT20 acknowledged.");
    unsigned status;
    status = bmp.begin();
    if (!bmp.begin()) {
        Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
        while (1);
    }
    bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                    Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                    Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                    Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                    Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */

    pinMode(SENSOR, INPUT_PULLUP);
    pulseCount = 0;
    flowRate = 0.0;
    flowMilliLitres = 0;
    totalMilliLitres = 0;
    previousMillis = 0;
    attachInterrupt(digitalPinToInterrupt(SENSOR), pulseCounter, FALLING);
if (WiFi.status() != WL_CONNECTED) {
        Serial.println("Attempting to connect to WiFi...");
        WiFi.begin(ssid, password);
        while (WiFi.status() != WL_CONNECTED) {
            delay(10000);
            Serial.print("Connection attempt ");
            Serial.println("...");
        }
        if (WiFi.status() == WL_CONNECTED) {
            Serial.println("Connected to WiFi.");
            delay(5000);
        } else {
            Serial.println("Failed to connect to WiFi.");
        }
    }

    if (WiFi.status() == WL_CONNECTED) {
        Serial.println("Updating totalLitres...");
        long ThTL = readTLData();
        totalLitres = ThTL;
    } else {
        Serial.println("WiFi is not connected. Cannot update totalLitres.");
    }
}

void loop() {
    currentMillis = millis();
// Flow rate and timing section
    if (flowRate >= 0.05) {
        if (!timing) {
            startTime = millis();
            timing = true;
        }
    } else {
        if (timing) {
            unsigned long endTime = millis();
            unsigned long elapsedTime = endTime - startTime;
            timing = false;
            totalElapsedTime += elapsedTime;
            updateTFTDisplay(totalElapsedTime);
        }
    }
    
  // Print elapsed time every second while timing is active
    if (timing && (currentMillis - lastPrintTime) >= 1000) {
        unsigned long elapsedTime = (currentMillis - startTime) / 1000; // Elapsed time in seconds
        Serial.print("Elapsed time: ");
        Serial.print(elapsedTime);
        Serial.println(" seconds");
        lastPrintTime = currentMillis;
    }
     // ThingSpeak update section
    if ((currentMillis - lastThingSpeakUpdateTime) > thingSpeakUpdateInterval) {
        lastThingSpeakUpdateTime = currentMillis;
        // Check Wi-Fi connection before attempting to update ThingSpeak
        if (WiFi.status() == WL_CONNECTED) {
            updateThingSpeakFields();
            } else {
            Serial.println("WiFi not connected. Skipping ThingSpeak update.");
            }
       }
       updateFlowRate();
       updateSensorData();     
 }
  void updateTFTDisplay(unsigned long elapsedTime) {
    Serial.print("totalElapsedTime: ");
    Serial.print(totalElapsedTime);
    Serial.println(" seconds");
}    
void updateThingSpeakFields() {
  Serial.print((int)temp);
  Serial.print((int)humi);
  Serial.print((int)pres/100);
  Serial.print((int)flowLitres);
  Serial.print((int)totalLitres);
  ThingSpeak.setField(1, (int)temp);
  ThingSpeak.setField(2, (int)humi);
  ThingSpeak.setField(3, (int)pres/100);
  ThingSpeak.setField(4, (int)flowLitres);
  ThingSpeak.setField(5, (int)totalLitres);    
  int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    if(x == 200) {
      Serial.println("Channel update successful.");
    } else {
      Serial.println("Problem updating channel. HTTP error code " + String(x));
  }
} 
void updateSensorData() {
  // Update temperature, humidity, pressure
  temp = aht20.getTemperature();    // get temperature in °C
  humi = aht20.getHumidity();       // get humidity in %
  pres = bmp.readPressure();        // get pressure in Pa
  // Update flow rate
  
}
void updateFlowRate() {
  currentMillis = millis();
  if (currentMillis - previousMillis > interval) {
    pulse1Sec = pulseCount;
    pulseCount = 0;
    flowRate = ((1000.0 / (millis() - previousMillis)) * pulse1Sec) / calibrationFactor;
    previousMillis = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    flowLitres = (flowRate / 60);
    totalMilliLitres += flowMilliLitres;
    totalLitres += flowLitres;
    // Print flow rate and total litres
    Serial.print("Flow rate: ");
    Serial.print(flowRate);
    Serial.print(" L/min");
    Serial.print("\t");  
    Serial.print("Output Liquid Quantity: ");
    Serial.print(totalMilliLitres);
    Serial.print(" mL / ");
    Serial.print(totalLitres);
    Serial.println(" L");
  }
}
String httpGETRequest(const char* serverName) {
    HTTPClient http;
    http.begin(serverName);
    int httpResponseCode = http.GET();
    String payload = "{}";
    if (httpResponseCode > 0) {
       Serial.print("HTTP Response code: ");
       Serial.println(httpResponseCode);
        payload = http.getString();
    } else {
        Serial.print("Error code: ");
        Serial.println(httpResponseCode);
    }
    http.end();
    return payload;
}
long readTLData() {
    if (WiFi.status() == WL_CONNECTED) {
        WiFiClient client;
        ThingSpeak.begin(client);
        long totalLitres = ThingSpeak.readLongField(myChannelNumber, FieldNumber, myReadAPIKey);
        if (totalLitres == 0) {
            Serial.println("No data found or failed to read data.");
        } else {
            Serial.print("Total Litres from ThingSpeak: ");
            Serial.println(totalLitres);
        }
        return totalLitres;
    } else {
        Serial.println("WiFi is not connected.");
        return 0;
    }
} 

void pulseCounter() {
    pulseCount++;
}

If i exclude the updateThingSpeakFields() everything working.

Sorry for replying late .Did you solve the issue or still facing it. Can you describe the nodemcu crash like do you get any error in Serial monitor or just the board not giving any response

I have a memory exception on core 1. The funny thing is that I experienced the same issue with the wifi connection block at the beginning of setting the code without anything else block interacting with wifi but it solved somehow when I put it in the setup(). The first time I suspected the loads or the cables but it isn't because if I use another sketch with thingspeak functions is ok; Here is the other code that interacts ok with thinkspeak.

#include <AHT20.h>
#include <SPI.h>
#include <WiFi.h>
#include <Wire.h>
#include "ThingSpeak.h"
#include <Adafruit_BMP280.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#define SENSOR  27
Adafruit_BMP280 bmp;
AHT20 aht20;
const char *ssid =  "CYTA_CRby_2.4G";     // replace with your wifi ssid and wpa2 key
const char *password =  "PhYkD6YZ";
//const char* server = "184.106.153.149";
unsigned long myChannelNumber = 2514774;
const char * myWriteAPIKey = "Y9V8GLKAH5ZOAA7Q";
const char * myReadAPIKey = "X7GOTNVKG9JH4XJT";
const int FieldNumber6 = 6;  // The field you wish to read
// Timer variables
unsigned long lastTime = 0;
unsigned long timerDelay = 30000;  // your network key Index number (needed only for WEP)
WiFiClient  client;
#define TFT_DC   2  //VCC, GND, SCL = CLK, SDA = DIN, RS / DC = D/C, RES = RST, CS
#define TFT_RST -1         
#define TFT_CS   5
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
// Initialize our values
String myStatus = "";
float temp;    // get temperature in °C
float humi;       // get humidity in %
float pres;    
long currentMillis = 0;
long previousMillis = 0;
int interval = 1000;
boolean ledState = LOW;
float calibrationFactor = 0.45;
volatile byte pulseCount;
byte pulse1Sec = 0;
float flowRate;
unsigned long flowMilliLitres;
unsigned int totalMilliLitres;
float flowLitres;
float totalLitres;

void setup() {
  Serial.begin(115200);
  Serial.println(F("AHT20+BMP280 test"));
  Wire.begin();
  
 if (aht20.begin() == false)  {
    Serial.println("AHT20 not detected. Please check wiring. Freezing.");
    while (1);
  }
  Serial.println("AHT20 acknowledged.");
  WiFi.mode(WIFI_STA);   
  ThingSpeak.begin(client); 
  
  tft.initR(INITR_BLACKTAB);   // initialize a ST7735S chip, black tab
  tft.setTextWrap(false); // Allow text to run off right edge
  tft.fillScreen(ST7735_BLACK);
  tft.setTextColor(ST7735_RED, ST7735_BLACK);   // set text color to red and black background
    tft.setTextSize(1.5);         // text size = 2
    tft.setCursor(7, 4);       // move cursor to position (5, 76) pixel
    tft.print("Flr L/min");
    tft.setTextColor(ST7735_RED, ST7735_BLACK);   // set text color to red and black background
    tft.setTextSize(1);         // text size = 2
    //tft.setCursor(40, 28);       // move cursor to position (5, 76) pixel
    //tft.print("L/m");
    tft.setTextColor(ST7735_RED, ST7735_BLACK);   // set text color to red and black background
    tft.setTextSize(1.5);         // text size = 2
    tft.setCursor(70, 4);       // move cursor to position (5, 76) pixel
    tft.print("Total Ltrs");
    // Print the cumulative total of litres flowed since starting
    tft.setTextColor(ST7735_RED, ST7735_BLACK);   // set text color to red and black background
    tft.setTextSize(1.5);         // text size = 2
    //tft.setCursor(125, 28);       // move cursor to position (5, 76) pixel
    //tft.print("L");
    tft.drawFastHLine(0, 47,  tft.width(), ST7735_WHITE); // draw horizontal white line at position (0, 30)
    tft.drawFastVLine(67, -80,  tft.width(), ST7735_WHITE); 
   tft.setTextColor(ST7735_WHITE, ST7735_BLACK);  // set text color to white and black background
   tft.setTextSize(1);  
   tft.drawFastHLine(0, 90,  tft.width(), ST7735_WHITE);   // draw horizontal white line at position (0, 76)
   tft.drawFastHLine(0, 125,  tft.width(), ST7735_WHITE);  // draw horizontal white line at position (0, 122)
   tft.setTextColor(ST7735_RED, ST7735_BLACK);     // set text color to red and black background
   tft.setCursor(25, 54);              // move cursor to position (25, 39) pixel
   tft.print("TEMPERATURE");
   tft.setTextColor(ST7735_CYAN, ST7735_BLACK);  // set text color to cyan and black background
   tft.setCursor(34, 94);              // move cursor to position (34, 85) pixel
   tft.print("HUMIDITY");
   tft.setTextColor(ST7735_GREEN, ST7735_BLACK);  // set text color to green and black background
   tft.setCursor(34, 131);              // move cursor to position (34, 131) pixel
   tft.print("PRESSURE");
   tft.setTextSize(2);                 // text size = 2
  // print °C
  tft.drawCircle(89, 70, 2, ST7735_YELLOW);  // print degree symbol ( ° )
  tft.setCursor(95, 70);                     // move cursor to position (95, 54) pixel
  tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);  // set text color to yellow and black background
  tft.print("C");
  tft.setCursor(91, 146);
  tft.print("hPa");
  unsigned status;
  //status = bmp.begin(BMP280_ADDRESS_ALT, BMP280_CHIPID);
  status = bmp.begin();
  if (!bmp.begin()) 
  {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }

  /* Default settings from datasheet. */
  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_500); /* Standby time. */
 //pinMode(LED_BUILTIN, OUTPUT);
 pinMode(SENSOR, INPUT_PULLUP);
  pulseCount = 0;
  flowRate = 0.0;
  flowMilliLitres = 0;
  totalMilliLitres = 0;
  previousMillis = 0;
 attachInterrupt(digitalPinToInterrupt(SENSOR), pulseCounter, FALLING); 
 
}

void loop() {
  if(WiFi.status() != WL_CONNECTED){
      Serial.print("Attempting to connect");
      while(WiFi.status() != WL_CONNECTED){
        WiFi.begin(ssid, password); 
        delay(10000);     
      } 
      Serial.println("\nConnected.");
      printWifiStatus();
      readTLData(); // read last logged totallitres data 
      Serial.println("Updating totalLitres adding+");
      long ThTL=readTLData() ;
      totalLitres=ThTL;
    }
    float totalMilliLitres;
    if ((millis() - lastTime) > timerDelay) {
    // Get
    ThingSpeak.setField(1, temp);
    ThingSpeak.setField(2, humi);
    ThingSpeak.setField(3, pres/100);
    ThingSpeak.setField(4, flowLitres);
    ThingSpeak.setField(5, totalMilliLitres/1000); 
    ThingSpeak.setField(6, totalLitres);    
    int x = ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);
    
    if(x == 200){
      Serial.println("Channel update successful.");
    }
    else{
      Serial.println("Problem updating channel. HTTP error code " + String(x));
    }
    lastTime = millis();
   }
   temp = aht20.getTemperature();    // get temperature in °C
   humi = aht20.getHumidity();       // get humidity in %
   pres = bmp.readPressure();       // get pressure in Pa
   Serial.printf("Temperature: %.02f *C\n", temp);
   Serial.printf("Humidity: %.02f %RH\n", humi);
   Serial.printf("Pressure: %.02f hPa\n", pres/100);
   // CODE FROM flow.h
    currentMillis = millis();
  if (currentMillis - previousMillis > interval) {
    pulse1Sec = pulseCount;
    pulseCount = 0;
    flowRate = ((1000.0 / (millis() - previousMillis)) * pulse1Sec) / calibrationFactor;
    previousMillis = millis();
    flowMilliLitres = (flowRate / 60) * 1000;
    flowLitres = (flowRate / 60);
    totalMilliLitres += flowMilliLitres;
    totalLitres += flowLitres;
    // Print the flow rate for this second in litres / minute
    Serial.print("Flow rate: ");
    Serial.print(float(flowRate));  // Print the integer part of the variable
    Serial.print("L/min");
    Serial.print("\t");  
    Serial.print("Output Liquid Quantity: ");
    Serial.print(totalMilliLitres);
    Serial.print("mL / ");
    Serial.print(totalLitres);
    Serial.println("L");
  }
  tft.setCursor(5, 24);
  tft.setTextColor(0xFD00, ST7735_BLACK);  // set text color to orange and black background
  tft.printf("%02u.%01u", (int)flowRate, (int)(flowRate* 100) % 100  );
  tft.setCursor(78, 24);
  tft.setTextColor(0xFD00, ST7735_BLACK);  // set text color to orange and black background
  tft.printf("%04u", (int)totalLitres, (int)(totalLitres* 100) % 100  );

   // print data on the display
  // print temperature (in °C)
  tft.setCursor(11, 70);
  tft.setTextColor(ST7735_YELLOW, ST7735_BLACK);  // set text color to yellow and black background
  if(temp < 0)    // if temperature < 0
    tft.printf( "-%02u.%02u", (int)abs(temp), (int)(abs(temp) * 100) % 100 );
  else            // temperature >= 0
    tft.printf( " %02u.%02u", (int)temp, (int)(temp * 100) % 100 );
 
  // 2: print humidity
  tft.setCursor(23, 108);
  tft.setTextColor(ST7735_MAGENTA, ST7735_BLACK);  // set text color to magenta and black background
  tft.printf( "%02u.%02u %%", (int)humi, (int)(humi * 100) % 100 );
 
  // 3: print pressure (in hPa)
  tft.setCursor(3, 146);
  tft.setTextColor(0xFD00, ST7735_BLACK);  // set text color to orange and black background
  tft.printf( "%04u.%02u", (int)(pres/100), (int)((uint32_t)pres % 100) );
  delay(3000); // Wait 20 seconds to update the channel again
}

void pulseCounter()
{
  pulseCount++;
}
int readTLData() {
  
  long TL = ThingSpeak.readLongField(myChannelNumber, FieldNumber6, myReadAPIKey);
  int y = ThingSpeak.getLastReadStatus();
  if (y == 200)
  {
    Serial.print("Totallitres from ThingSpeak: ");
    Serial.println(TL);
    return TL;
  }
  else
  {
    Serial.println("Unable to read channel / No internet connection");
    return -1;
  }
  delay(100);
  //-------------- End of Channel 1 -------------//
}
void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

can you try this by adding this life after wifi begin and also can you share what is in

This coming out from the serial with the correction made as mentioned above:

Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

Core 1 register dump:
PC : 0x400d3251 PS : 0x00060d30 A0 : 0x800d3669 A1 : 0x3ffb2220
A2 : 0x3ffc4648 A3 : 0x3ffb222c A4 : 0x0000000a A5 : 0x3ffafefc
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x800d9124 A9 : 0x3ffb21e0
A10 : 0x3ffb21e0 A11 : 0x3f40132a A12 : 0x00000050 A13 : 0x0000ff00
A14 : 0x00ff0000 A15 : 0xff000000 SAR : 0x00000010 EXCCAUSE: 0x0000001c
EXCVADDR: 0x800d9158 LBEG : 0x4008b0a1 LEND : 0x4008b0b1 LCOUNT : 0xffffffff
Backtrace: 0x400d324e:0x3ffb2220 0x400d3666:0x3ffb2240 0x400d4a97:0x3ffb2260 0x400e1a89:0x3ffb2290

ELF file SHA256: 93b7059c2340f408

Rebooting...

And here is the ThinkSpeak.h:
GitHub - asukiaaa/ThingSpeak_asukiaaa: A library to send field values to ThingSpeak.

I hope you are using the official library .If you are facing exception .You can use ESP exception handler to figure out cause of the error

Ok guys, thanks for the replies. The problem was simple and stupid together; It wanted at the beginning of the thinkspeak function, the ThingSpeak.begin(client); although I had it declared at the setup;

Share the change in this thread so others can understand .

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