I am having issues with my code for an ESP32 Wroom. I am trying to use both cores on the esp to speed up and create an efficient process for the device; one core checks for a change/response from a website page. and the other changes the led patterns according to the response received.
Core 0 (getting response) should be constantly updating a string called "payload" with the latest received information form the website. this is happening whilst the other core is displaying a pattern until it receives a change in "payload"; and changes accordingly.
the issue i am having is that the esp after uploading and first time starting prints the following message every 1-2 seconds:
rst:0x8 (TG1WDT_SYS_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1044
load:0x40078000,len:8896
load:0x40080400,len:5816
entry 0x400806ac
This is also printed in some of the messages:
Guru Meditation Error: Core 0 panic'ed (Double exception)
I am new to ESP32's and have not much experience with Arduino, does anybody know what I am doing wrong or ways of achieving the same aim avoiding the current issues. Thanks in advance.
Here is the code for my project.
TaskHandle_t Task1;
#include <WiFi.h>
#include <Wire.h>
#include <HTTPClient.h>
#include "FastLED.h"
#define NUM_LEDS 50
#define PIN 27
uint8_t hue[NUM_LEDS];
CRGBArray<NUM_LEDS> leds;
const char* ssid = "Username";
const char* password = "Password";
const char* serverName = "https://example.com/page.php";
String apiKeyValue = "tPmAT5Ab3j7F9";
String payload;
void codeForTask1( void * parameter )
{
for (;;)
{
if(WiFi.status() == WL_CONNECTED)
{
HTTPClient http;
// Your Domain name with URL path or IP address with path
http.begin(serverName);
// Specify content-type header
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
// Prepare your HTTP POST request data
String httpRequestData = "api_key=" + apiKeyValue;
// Send HTTP POST request
int httpResponseCode = http.GET();
if (httpResponseCode>0)
{
payload = http.getString();
}
}
delay(1000);
}
}
void setup()
{
Serial.begin(115200);
WiFi.begin(ssid, password);
while(WiFi.status() != WL_CONNECTED) {
delay(500);
}
FastLED.addLeds<NEOPIXEL, PIN>(leds, NUM_LEDS);
for (int i = 0; i < NUM_LEDS; i++)
{
hue[i] = 255 / NUM_LEDS * i;
}
xTaskCreatePinnedToCore(
&codeForTask1,
"led1Task",
2000,
NULL,
1,
&Task1,
0);
delay(500); // needed to start-up task1
}
void loop()
{
String payload2 = payload;
if(payload2.indexOf("rainbow") >= 0)
{
while(payload2.indexOf("rainbow") >= 0)
{
for(int i=0; i<NUM_LEDS; i++)
{
leds[i] = CHSV(hue[i]++, 255, 255);
}
delay(100);
FastLED.show();
}
Serial.print(payload2 + " || Rainbow \n");
}
else if(payload2.indexOf("worm") >= 0)
{
for(int i=0; i<NUM_LEDS; i++)
{
for(int e=0; e<=1; e++)
{
if(e == 0){
leds[i] = CRGB(255, 255, 255);
leds[i+2] = CRGB(255, 255, 255);
leds[i+4] = CRGB(255, 255, 255);
leds[i+6] = CRGB(255, 255, 255);
FastLED.show();
}else{
leds[i] = CRGB(0, 0, 0);
leds[i+2] = CRGB(0, 0, 0);
FastLED.show();
}
delay(100);
}
}
Serial.print(payload2 + " || Worm \n");
}
else if(payload2.indexOf("ant") >= 0)
{
for(int i=0; i<NUM_LEDS; i++) // loop
{
for(int e=0; e<=1; e++)
{
if(e == 0)
{
leds[i] = CRGB(255, 255, 255);
leds[i+1] = CRGB(255, 255, 255);
leds[i+2] = CRGB(0, 0, 0);
leds[i+4] = CRGB(255, 255, 255);
leds[i+5] = CRGB(255, 255, 255);
leds[i+3] = CRGB(0, 0, 0);
FastLED.show();
}
else
{
leds[i] = CRGB(0, 0, 0);
leds[i+1] = CRGB(0, 0, 0);
FastLED.show();
}
delay(50);
}
}
Serial.print(payload2 + " || Ant \n");
}
else if(payload.indexOf("off") >= 0)
{
Serial.print(payload2 + " || Off \n" );
}
else if(!payload2.isEmpty())
{
String dab = payload;
String hexstring = dab;
long number = (long) strtol( &hexstring[0], NULL, 16 );
int r = number >> 16;
int g = number >> 8 & 0xFF;
int b = number & 0xFF;
for(int i=0; i<NUM_LEDS; i++){
leds[i] = CRGB(r, g, b);
}
FastLED.show(); // start new rgb led strip assignment/patterns
Serial.print(payload2 + " || CUSTOM COLOR \n");
}
delay(1000);
Serial.print("Task 1: Done \n");
}