platformio / platform-espressif8266

Espressif 8266: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/espressif8266
Apache License 2.0
320 stars 218 forks source link

Monitor_filter not working #315

Open ChiuTommy opened 5 months ago

ChiuTommy commented 5 months ago

Configuration

Operating system:

Macbook pro Apple M1 Pro MacOS Sonoma version 14.3

PlatformIO Version (platformio --version):

vscode January 2024 (version 1.86)+ PlatformIO IDE v3.3.3

Description of problem

I encountered the following stack error while running, and I want to use the espressif8266_exception_decoder to automatically decode the error, but it’s not working.

Steps to Reproduce

  1. To view the console messages I have set up from the TERMINAL, enter '1' to initiate the mode for inputting WiFi SSID and password. 2.Enter WiFi SSID. 3.Enter WiFi password; the ESP32 will automatically establish a connection. Use the GET method to retrieve webpage data. Subsequently, a stack error may occur.

I use the board "nodeMCU1.0"

Actual Results

Connecting to Wi-Fi Waiting for Wifi........... Wifi Connected OK <!DOCTYPE html>錯誤

Google Apps Script
TypeError: Cannot read properties of null (reading 'getRange') (第 314 行,檔案名稱:程式碼)

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Exception (28): epc1=0x40219bf5 epc2=0x00000000 epc3=0x00000000 excvaddr=0x00000000 depc=0x00000000

stack>>>

ctx: cont sp: 3ffffab0 end: 3fffffc0 offset: 0150 3ffffc00: 00000000 3ffe8368 3ffffc60 40217ff1
3ffffc10: 000001b7 00000005 00000000 3ffe8368
3ffffc20: 00000001 3ffe8368 4021c30c 4021c3d0
3ffffc30: 3fff17fc 3ffe8836 00000001 00000030
3ffffc40: 3ffef20c 1146545c 00418937 3ffe8835
3ffffc50: 3ffe8836 3ffe8368 3ffffd10 4021c820
3ffffc60: 00000000 ffffffff 00000000 00000000
3ffffc70: 4000050c 00000000 3f302073 401007e5
3ffffc80: 40211d42 00000030 00000010 ffffffff
3ffffc90: 4021232b 00000000 00000073 00000000
3ffffca0: 007f8000 0000007e 00000000 fffffffe
3ffffcb0: ffffffff 3fffc6fc 00000000 3fff7bca
3ffffcc0: 3ffffe40 3ffffe10 0000000c 00000030
3ffffcd0: 3ffffe40 3ffffe10 00000008 000001b7
3ffffce0: 00000000 00000000 00000001 401001c0
3ffffcf0: 0000102f 00000020 3ffe85e4 3ffe8834
3ffffd00: 3ffeed4c 3ffe8368 00000040 40219bad
3ffffd10: 3ffffdcc f6abeb50 0000003f ffff0208
3ffffd20: 3ffffdcc 0000003f 00000000 401003f8
3ffffd30: 00000000 00000000 00000001 401001c0
3ffffd40: 00000000 3fff17fc 3fff7cc8 00000000
3ffffd50: 3fff7cc9 0000000b 3fff7cc8 40210a8e
3ffffd60: 00000002 59581062 00046c2c 40210ac8
3ffffd70: 00000000 6d916872 00046c2c 40212331
3ffffd80: 00001089 ffffff80 00000000 40219be9
3ffffd90: 3ffffe40 3ffffe10 00000008 3ffe8834
3ffffda0: 3ffeed4c 00000020 3fff7b1c 40100b42
3ffffdb0: 00000001 000001b8 3fff7b1c 4020e8b7
3ffffdc0: 3ffffe40 3ffffe10 00000008 736e6173
3ffffdd0: 7265732d 203b6669 746e6f66 7a69732d
3ffffde0: 31203a65 3b747032 6e6f6620 65772d74
3ffffdf0: 74686769 6f62203a 203b646c 656e696c
3ffffe00: 6965682d 3a746867 00353120 3fff17fc
3ffffe10: 3fff7294 000002c6 00000000 00000001
3ffffe20: 00000000 00000000 00000050 40100b79
3ffffe30: 000001b9 3ffe8368 00000000 402198bf
3ffffe40: 3fffff30 00000000 00000005 3fff17fc
3ffffe50: 00000001 ffffff80 00000000 40206e69
3ffffe60: 40207072 3fff15bc 000017a4 00000000
3ffffe70: 0087008f 00000000 00000000 0080008f
3ffffe80: 00000000 00000000 0087008f 00000000
3ffffe90: 3fff1bdc 3fff1c0c 3fff1fac 0011001f
3ffffea0: 80000000 e80101bb 3f001388 3fff1fd4
3ffffeb0: 006e006f 80000000 70747468 40100073
3ffffec0: 05000000 3fff210c 0000001f 80000000
3ffffed0: 00000000 3ffeeddc 00000000 3fff18d4
3ffffee0: 0011001f 80000000 00000000 00000000
3ffffef0: 000000c8 000002c6 00046101 00000001
3fffff00: 0000000a 00000000 00045f34 00000000
3fffff10: 00000001 3fff1f64 3fff1de4 0087008f
3fffff20: 80000000 3fff756c 02c602cf 80000000
3fffff30: 003a002c 00000003 3ffeed4c 4020e9f8
3fffff40: 00000000 3ffeecec 3ffeed4c 4020ea50
3fffff50: 3ffeece0 3ffeecec 3ffeed4c 3ffeee08
3fffff60: 3fffdad0 00000000 3ffeed4c 40207296
3fffff70: 00000000 33303130 00000000 00000000
3fffff80: 00004945 00000000 00000001 401001c0
3fffff90: 3fffdad0 00000000 3fffdab0 401001e1
3fffffa0: feefeffe feefeffe 3fffdab0 40210b9e
3fffffb0: feefeffe feefeffe feefeffe 40100f45
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------

ets Jan 8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3424, room 16 tail 0 chksum 0x2e load 0x3fff20b8, len 40, room 8 tail 0 chksum 0x2b csum 0x2b v0006c4b0 ~ld �␜␂␇␒�n�␒r��n|�␌l␌�␌l␂␜b␒␒␂␌b␒r␒␂l�nb�n␂␌l␂�␜r␒l�l␒�␌␌␌� Listing directory: / Now mount it Reading file: /SSID.txt Failed to open file for reading Listing directory: / Listing directory: / Now mount it Reading file: /PASSWORD.txt Failed to open file for reading Listing directory: /

Expected Results

If problems with PlatformIO Build System:

The content of platformio.ini:

[env:nodemcuv2]
platform = espressif8266
board = nodemcuv2
framework = arduino
build_type = debug
monitor_port = //dev/cu.usbserial-1110
monitor_speed = 115200
monitor_filters = espressif8266_exception_decoder

Source file to reproduce issue:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
#include <WiFiClientSecureBearSSL.h>
#include <FS.h>
#include <LittleFS.h>

//Enter WIFI Credentials
//char * ssid = "MEIMEI";  // Enter your Wifi Username
//char * password = "29410103";  // Enter your Wifi Password

String ssid;  // Enter your Wifi Username
String password;  // Enter your Wifi Password
char ssid_array[20];
char password_array[20];
char * SerialNumber="rain001"; 
String GOOGLE_SCRIPT_ID = "AKfycbyxQf76E-OBVfoX8hOuxnWOcUEHvL479tlg5tOXTeSi3AdnKH0QJxns9Vw0jXwfxEPwBg";
//---------------------------------------------------------------------

const int sendInterval = 50;
String message = "Welcome";
int x;
int len=0;
int k=0;
WiFiClientSecure client;

void read_google_sheet(int Debug);
void wifi_connect(const char *ssid,const char* password);

void listDir(const char *dirname) {
  Serial.printf(" Listing directory: %s\n", dirname);

  Dir root = LittleFS.openDir(dirname);

  while (root.next()) {
    File file = root.openFile("r");
    Serial.print("  FILE: ");
    Serial.print(root.fileName());
    Serial.print("  SIZE: ");
    Serial.print(file.size());
    file.close();
  }
}

void readFile(const char *path,char* data) {
  int index = 0;
  char readData;
  Serial.printf(" Reading file: %s\n", path);

  File file = LittleFS.open(path, "r");
  if (!file) {
    Serial.println("Failed to open file for reading ");
    return;
  }

  Serial.print("Read from file: ");
  while (file.available()) 
  { 
    readData = file.read();
    *(data+index++) = readData;
    Serial.write(readData); 
  }
  file.close();
}

void writeFile(const char *path, const char *message) {
  Serial.printf("Writing file: %s\n", path);

  File file = LittleFS.open(path, "w");
  if (!file) {
    Serial.println("Failed to open file for writing");
    return;
  }
  if (file.print(message)) {
    Serial.println("File written");
  } else {
    Serial.println("Write failed");
  }
  delay(2000);  // Make sure the CREATE and LASTWRITE times are different
  file.close();
}

void appendFile(const char *path, const char *message) {
  Serial.printf("Appending to file: %s\n", path);

  File file = LittleFS.open(path, "a");
  if (!file) {
    Serial.println("Failed to open file for appending");
    return;
  }
  if (file.print(message)) {
    Serial.println("Message appended");
  } else {
    Serial.println("Append failed");
  }
  file.close();
}

void renameFile(const char *path1, const char *path2) {
  Serial.printf("Renaming file %s to %s\n", path1, path2);
  if (LittleFS.rename(path1, path2)) {
    Serial.println("File renamed");
  } else {
    Serial.println("Rename failed");
  }
}

void deleteFile(const char *path) {
  Serial.printf("Deleting file: %s\n", path);
  if (LittleFS.remove(path)) {
    Serial.println("File deleted");
  } else {
    Serial.println("Delete failed");
  }
}

char ReadFileData[255]="";

String convertToString(char* a, int size)
{
    int i;
    String s = "";
    for (i = 0; i < size; i++) {
        s = s + a[i];
    }
    return s;
}

void format_allfile ()
{
   LittleFS.format();
}

int read_ssid ()
{
  listDir("/");
  Serial.println("Now mount it");
  if (!LittleFS.begin()) {
    Serial.println("LittleFS mount failed");
    return -1;
  }
  readFile("/SSID.txt",ssid_array);
  listDir("/");
  return 1;
}

int read_password()
{
  listDir("/");
  Serial.println(" Now mount it");
  if (!LittleFS.begin()) {
    Serial.println("LittleFS mount failed");
    return -1;
  }
  readFile("/PASSWORD.txt",password_array);
  listDir("/");
   return 1;
}

int write_ssid(const char* ssid)
{
  Serial.println("Formatting LittleFS filesystem");
  LittleFS.format();
  Serial.println("Mount LittleFS");
  if (!LittleFS.begin()) {
    Serial.println("LittleFS mount failed");
    return -1;
  }
  listDir("/");
  deleteFile("/SSID.txt");
  writeFile("/SSID.txt", ssid);
  listDir("/");
  return 1;
}

int write_password(const char* password)
{
  Serial.println("Mount LittleFS");
  if (!LittleFS.begin()) {
    Serial.println("LittleFS mount failed");
    return -1;
  }
  listDir("/");
  deleteFile("/PASSWORD.txt");
  writeFile("/PASSWORD.txt", password);
  listDir("/");
  return 1;
}

void setup() 
{ 
  int state = 1;
  int wrote = -1;
  Serial.begin(115200);
  delay(10);
  format_allfile();
  state = read_ssid();
  state = read_password();
  if(state == 1 )
  {
    if(strcmp(ssid_array,"\0") != 0)
    {
      wrote = 1;
      wifi_connect(ssid_array,password_array);
    }    
  }

  pinMode(D0, OUTPUT);
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);
  pinMode(D3, OUTPUT);

  Serial.println(" ");
  Serial.println("1:輸入WIFI帳密,2:開始除錯,3:停止除錯");
  Serial.println("請輸入選項號碼後,後按下Enter");
}

void stringToCharArray(const char* str, char* charArray) {
    while (*str != '\0') {
        *charArray = *str;
        str++;
        charArray++;
    }
    *charArray = '\0';
}

int get_int = 0;
int option = 0;
int Debug = 0;
int wifi_ConnectState = 0;
void wifi_connect(const char *ssid,const char* password)
{
  const char* Ssid = ssid;
  const char* Password = password;
  //--------------------------------------------
  WiFi.mode(WIFI_STA);
  WiFi.begin(Ssid,Password);

  Serial.println("");
  Serial.println(" 輸入1 停止連線");
  Serial.println("Connecting to Wi-Fi");
  Serial.print("Waiting for Wifi");
  while (WiFi.status() != WL_CONNECTED) 
  {
    delay(500);
    Serial.print(".");
    if( Serial.available() > 0)
    {
      get_int = Serial.read();
      if( get_int == 0x31 )
      {
         break;
      }
    }   
  }

  if(WiFi.status() == WL_CONNECTED)
  {
    wifi_ConnectState = 1;
    Serial.println("");
    Serial.print("Wifi Connected");
    Serial.println(" OK");
  }
  else
  {
    Serial.println("");
    Serial.println("Wifi disconnected");
    Serial.println(" ");
    Serial.println("1:輸入WIFI帳密,2:開始除錯,3:停止除錯");
    Serial.println("請輸入選項號碼後,後按下Enter");
  }
  option = '0';
  //--------------------------------------------
}

char terminateChar =  '\n';      // 建立终止字符
//const int bufferLength = 100;// 定义缓存大小为100个字节
//char serialBuffer[bufferLength];// 建立字符数组用于缓存

void loop() 
{
  if(Serial.available() > 0)
  {
    option = Serial.read();
    Serial.readStringUntil(terminateChar);
  }
  else
  {
    switch(option)
    {
      case '1':
        Serial.println("請輸入 WIFI SSID 後按下 Enter");
        while(Serial.available() == 0);
        ssid = Serial.readStringUntil(terminateChar);
        Serial.print("SSID 是 ");
        Serial.println(ssid);       
        Serial.println("請輸入 WIFI Password 後按下 Enter");
        while(Serial.available() == 0);
        password = Serial.readStringUntil(terminateChar); 
        Serial.print("Password 是 ");
        Serial.println(password);
        write_ssid(ssid.c_str());
        write_password(password.c_str());
        wifi_connect(ssid.c_str(),password.c_str());
        break;
      case '2':
        Debug = 1;
        Serial.println("除錯開始");  
        break;
      case '3':
        Debug = 0;
        Serial.println("除錯停止");  
        option = '0';
      default:
        break;
    }

    if(wifi_ConnectState)
    {
      read_google_sheet(Debug);
    }
  }
}

void read_google_sheet(int Debug) 
{
   //-----------------------------------------------------------------------------------
   std::unique_ptr<BearSSL::WiFiClientSecure>client(new BearSSL::WiFiClientSecure);
   client->setInsecure();
   HTTPClient https;
   String url="https://script.google.com/macros/s/"+GOOGLE_SCRIPT_ID+"/exec?SerialNumber=" + SerialNumber;
   if(Debug)
   {
      Serial.println("Reading Data From Google Sheet.....");

   }
   https.begin(*client, url.c_str());
   //-----------------------------------------------------------------------------------
   //Removes the error "302 Moved Temporarily Error"
   https.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
   //-----------------------------------------------------------------------------------
   //Get the returning HTTP status code
   int httpCode = https.GET();

  if(Debug){
       Serial.print("HTTP Status Code: ");
       Serial.println(httpCode);
   }

   //-----------------------------------------------------------------------------------
   if(httpCode <= 0){Serial.println("Error on HTTP request"); https.end(); return;}
   //-----------------------------------------------------------------------------------
   //reading data comming from Google Sheet
   String payload = https.getString();
   //-----------------------------------------------------------------------------------
   if(httpCode == 200)
   message = payload;
   if(Debug)
   {
      Serial.println("Payload: "+message);
   }

   const char s[2] = ",";
   const char s1[2] = ":";
   char state[10];
   char *token;

   token = strtok((char*)message.c_str(), s);
   Serial.printf( "%s\n", token );
   if(strcmp(token,"A1:ON")==0)
   {
      digitalWrite(D0, HIGH);
   }
   else
   {
      digitalWrite(D0, LOW);
   }

   token = strtok(NULL, s);
   Serial.printf( "%s\n", token );
   if(strcmp(token,"B1:ON")==0)
   {
      digitalWrite(D1, HIGH);
   }
   else
   {
      digitalWrite(D1, LOW);
   }

   token = strtok(NULL, s);
   Serial.printf( "%s\n", token );
   if(strcmp(token,"C1:ON")==0)
   {
      digitalWrite(D2, HIGH);
   }
   else
   {
      digitalWrite(D2, LOW);
   }

   token = strtok(NULL, s);
   Serial.printf( "%s\n", token );
   if(strcmp(token,"D1:ON")==0)
    {
      digitalWrite(D3, HIGH);
   }
   else
   {
      digitalWrite(D3, LOW);
   }

   Serial.println("");
   //-------------------------------------------------------------------------------------
   https.end();
}

image

Additional info