this is my arduino code for an esp32 which just setups wifi and then runs the setGoogleCalendar() function forever:
Code: Untitled.c Select all
#include <WiFi.h>
#include <HTTPClient.h>
#include "time.h"
// Replace with your network credentials
const char* ssid = "FRITZ!Box 6490 Cable";
const char* password = "xxxx";
// NTP server to request epoch time
const char* ntpServer = "fritz.box";
const String gooleAppsScriptUrl = "https://script.google.com/macros/s/xxxxxxxxxxxx/exec";
RTC_DATA_ATTR int bootCount = 0;
//Multithreading
TaskHandle_t googleCalendar;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.print("Connecting to WiFi ..");
while (WiFi.status() != WL_CONNECTED) {
if(millis() < 12000){
Serial.print('.');
delay(1000);
}
else {
ESP.restart();
}
}
Serial.println(WiFi.localIP());
}
void loop() {
// put your main code here, to run repeatedly:
if (googleCalendar == NULL){
xTaskCreate(
setGoogleCalendar
, "Google calendar request"
, 20000 // Stack size
, NULL // When no parameter is used, simply pass NULL
, 1 // Priority
, &googleCalendar // With task handle we will be able to manipulate with this task.
);
}
}
void setGoogleCalendar(void *pvParameters) {
(void) pvParameters;
HTTPClient http;
http.begin(gooleAppsScriptUrl.c_str());
http.setFollowRedirects(HTTPC_STRICT_FOLLOW_REDIRECTS);
String payload = "";
int httpStatus = http.GET();
Serial.println("this is the last thing that gets printed in the second run");
if (httpStatus == 200){
Serial.println("this will not get printed in the second run");
delay(500);
payload = http.getString();
}
else {
Serial.println("failed google calendar http request: " + httpStatus);
return;
}
Serial.println(payload);
http.end();
googleCalendar = NULL;
vTaskDelete(NULL);
}when i put it in the stack trace decoder i get this result:Guru Meditation Error: Core 0 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400d29ec: 00250602 afa2f01d f0a0223c
Core 0 register dump:
PC : 0x400d29f0 PS : 0x00060130 A0 : 0x00000000 A1 : 0x3fffc790
A2 : 0xa38d7f39 A3 : 0x3fffc880 A4 : 0x00000000 A5 : 0x00000000
A6 : 0x00000000 A7 : 0x00000000 A8 : 0xa38d7f39 A9 : 0x3fffc770
A10 : 0x3fffc7bc A11 : 0x400d4d78 A12 : 0xa38d7f39 A13 : 0x00000000
A14 : 0x3fffc828 A15 : 0x3fffc838 SAR : 0x00000017 EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000 LBEG : 0x400899bc LEND : 0x400899c7 LCOUNT : 0x00000000
Backtrace: 0x400d29ed:0x3fffc790
ELF file SHA256: a313233634d34ef3
Due to the error occuring in the last line with only a bracket i expected it to have something to do with rtos tasks not being closed but according to espressif documentation this error should not occur.0x400d29ec: setGoogleCalendar(void*) at C:\Users\johan\OneDrive\Dokumente\Arduino\Freertostestwithtask_copy_20240122224400\Freertostestwithtask_copy_20240122224400.ino:76
0x400d29f0: setGoogleCalendar(void*) at C:\Users\johan\OneDrive\Dokumente\Arduino\Freertostestwithtask_copy_20240122224400\Freertostestwithtask_copy_20240122224400.ino:76
0x400d4d78: TLSTraits::~TLSTraits() at C:\Users\johan\AppData\Local\Arduino15\packages\esp32\hardware\esp32\2.0.11\libraries\HTTPClient\src\HTTPClient.cpp:64
0x400d29ed: setGoogleCalendar(void*) at C:\Users\johan\OneDrive\Dokumente\Arduino\Freertostestwithtask_copy_20240122224400\Freertostestwithtask_copy_20240122224400.ino:76
Now i have noticed that core 0 panics which runs the wifi functions? and occurs in the http library. However this error only happens when i set the function as a seperate task and does not happen when i let it run normaly.
How is this behaviour possible?
Thank you for your help in advance
