Hello, I'm using esp32 mcu to set up 2 different tasks, both via wifi. Task1 obtains and displays data in the serial monitor, whereas task2 controls a relay ON/OFF-wise. here is the code:
#include <WiFi.h>
#include <HTTPClient.h>
#include <HX711_ADC.h>
#if defined(ESP8266) || defined(ESP32) || defined(AVR)
#include <EEPROM.h>
#endif
WiFiServer server(80);
TaskHandle_t Task1;
TaskHandle_t Task2;
const int HX711_dat = 18;
const int HX711_clk = 19;
HX711_ADC LoadCell(HX711_dat, HX711_clk);
const int relay_pin = 26; //
const char* wifi_name = "**********"; //
const char* wifi_pass = "*********"; //
WiFiClient client;
void Task1code(void* pvParameters); //
void Task2code(void* pvParameters);
void setup() {
Serial.begin(57600);
delay(100);
pinMode(relay_pin, OUTPUT);
Serial.print("Connecting to ");
Serial.println(wifi_name);
WiFi.begin(wifi_name, wifi_pass);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
Serial.println("Connection Successful");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("Type the above IP address into the browser search bar");
server.begin();
float calibrationValue;
calibrationValue = 23.09;
LoadCell.begin();
unsigned long stabilizingtime = 2000;
boolean _tare = true;
LoadCell.start(stabilizingtime, _tare);
if (LoadCell.getTareTimeoutFlag()) {
Serial.println("Timeout, check MCU>HX711 wiring and pin designations");
} else {
LoadCell.setCalFactor(calibrationValue);
Serial.println("Startup is complete");
}
xTaskCreatePinnedToCore(
Task1code,
"Task1",
10000,
NULL,
1,
&Task1,
0
);
xTaskCreatePinnedToCore(
Task2code,
"Task2",
10000,
NULL,
1,
&Task2,
1
);
delay(150);
}
void loop() {
}
void Task1code(void* pvParameters) {
static unsigned long t = 0;
static boolean newDataReady = 0;
const int serialPrintInterval = 30; //increase value to slow down serial print activity
// check for new data/start next conversion:
if (LoadCell.update()) newDataReady = true;
// get smoothed value from the dataset:
if (newDataReady) {
if (millis() > t + serialPrintInterval) {
float i = LoadCell.getData();
Serial.print("Load_cell output val: ");
Serial.println(i);
newDataReady = 0;
t = millis();
}
}
// receive command from serial terminal, send 't' to initiate tare operation:
if (Serial.available() > 0) {
char inByte = Serial.read();
if (inByte == 't') LoadCell.tareNoDelay();
}
// check if last tare operation is complete:
if (LoadCell.getTareStatus() == true) {
Serial.println("Tare complete");
}
}
void Task2code(void* pvParameters) {
Serial.print("Task2 running on core ");
Serial.println(xPortGetCoreID());
WiFiClient client;
while (1) {
client = server.available();
if (client) {
String currentLine = "";
while (client.connected()) {
if (client.available()) {
char c = client.read();
if (c == '\n') {
if (currentLine.length() == 0) {
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html><body><center><h2>ESP32 Web Server</h2>");
client.println("<h3>Click to turn ON/OFF the Relay</h3>");
client.println("<a href=\"/RELAYON\"><button>RELAY ON</button></a>");
client.println("<a href=\"/RELAYOFF\"><button>RELAY OFF</button></a>");
client.println("</center></body></html>");
break;
} else {
currentLine = "";
}
} else if (c != '\r') {
currentLine += c;
}
if (currentLine.endsWith("GET /RELAYON")) { // Changed from "/LEDON" to "/RELAYON"
digitalWrite(relay_pin, HIGH);
}
if (currentLine.endsWith("GET /RELAYOFF")) { // Changed from "/LEDOFF" to "/RELAYOFF"
digitalWrite(relay_pin, LOW);
}
}
}
client.stop();
}
}
}
the problem is that I'm receiving this error in the serial monitor:
Type the above IP address into the browser search bar
Startup is complete
Guru Meditation Error: Core 0 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400d2aa4: 2502adf5 f01d0284 a1004136
Core 0 register dump:
PC : 0x400d2aaa PS : 0x00060030 A0 : 0x00000000 A1 : 0x3ffcef30
A2 : 0x3ffc4164 A3 : 0x3ffc3f84 A4 : 0x3ffc3f50 A5 : 0x00000000
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x800d2aa0 A9 : 0x3ffcef10
A10 : 0x00000000 A11 : 0x00000000 A12 : 0x00000014 A13 : 0x00000000
A14 : 0x3ffb8188 A15 : 0x80000001 SAR : 0x0000000a EXCCAUSE: 0x00000000
EXCVADDR: 0x00000000 LBEG : 0x4008576d LEND : 0x40085775 LCOUNT : 0x00000027
Backtrace: 0x400d2aa7:0x3ffcef30
ELF file SHA256: 52d10e35e48d70b2
Rebooting...
how can I fix this?