Hello,
i have this function which recieve POSTs from a client including commands to controll the RGB accordenly.
void handleLEDdata(){
// Send the response to the client
cJSON *json = cJSON_Parse(ethernetServer.arg("plain").c_str());
int indx = atoi(cJSON_GetObjectItemCaseSensitive(json, "index")->valuestring);
String st = cJSON_GetObjectItemCaseSensitive(json, "state")->valuestring;
uint8_t r = atoi(cJSON_GetObjectItemCaseSensitive(json, "red")->valuestring);
uint8_t g = atoi(cJSON_GetObjectItemCaseSensitive(json, "green")->valuestring);
uint8_t b = atoi(cJSON_GetObjectItemCaseSensitive(json, "blue")->valuestring);
led_state_type state;
String res = "00";
for(int i = 0; i < 8; i++){
if(i == 0) {
state.bits.on = strtol(("0000000" + String(st[i])).c_str(), NULL, 2);
} else if(i == 1) {
state.bits.mode = strtol(("0000000" + String(st[i])).c_str(), NULL, 2);
}else{
res += st[i];
}
}
state.bits.res = strtol(res.c_str(), NULL, 2);
setLEDState(indx, state, r, g, b);
updateLEDState(indx);
ethernetServer.send(200, "text/html", "");
}
And this function decide how the RGB should act:
void updateLEDState(int indx) {
if(ledinfo[indx].state.bits.on == 1 && ledinfo[indx].state.bits.mode == 0){
continueLED(indx);
}
else if(ledinfo[indx].state.bits.on == 1 && ledinfo[indx].state.bits.mode == 1){
pthread_t tid;
pthread_create(&tid, NULL, blinkLED, (void *)&indx);
}
else{
offLED(indx);
}
}
And this is the blink function:
void *blinkLED(void *index){
int indx = *((int *) index);
uint32_t color = ledinfo[indx].colorcode_red << 16 | ledinfo[indx].colorcode_green << 8 | ledinfo[indx].colorcode_blue;
// Check if the tool is present
// Tool is present and is the right for next process Tool is in process and must be inserted
while(ledinfo[indx].state.bits.on == 1 && ledinfo[indx].state.bits.mode == 1){
for(int i = 0; i < Num_LED; i++){
ring1.setPixelColor(i, color);
}
ring1.show();
delay(250);
for(int i = 0; i < Num_LED; i++){
ring1.setPixelColor(i, 0x000000);
}
ring1.show();
delay(250);
}
pthread_exit(NULL);
}
The problem is when the server (ESP32) get a POST from client asking to set the RGB in blink mode then it reboots and nothing happens.
I think the issue is with the pthread.
Here is the output:
Guru Meditation Error: Core 1 panic'ed (Unhandled debug exception).
Debug exception reason: Stack canary watchpoint triggered (pthread)
Core 1 register dump:
PC : 0x4037e45a PS : 0x00060c36 A0 : 0x8038064c A1 : 0x3fcf37e0
A2 : 0x3fc98160 A3 : 0xffffffff A4 : 0x00060c23 A5 : 0x000000ff
A6 : 0x000000ff A7 : 0x3fc96ad4 A8 : 0x000002cc A9 : 0x00000001
A10 : 0x03c98160 A11 : 0x3fc98160 A12 : 0x3fc96ea4 A13 : 0xffffffff
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x0000000e EXCCAUSE: 0x00000001
EXCVADDR: 0x00000000 LBEG : 0x400556d5 LEND : 0x400556e5 LCOUNT : 0xffffffff
So please any help.