Hello,
I am writing a sketch that is a bit complex. It includes two I2C sensors, Wifi, Web client, BlueTooth, constatns in flash, and a timer. I realized that the program sometimes crashes with Guru Meditation Error message in the Output when printing to the web client.
I investigated a bit, stripped the code off so it is only Web client, sensors and timer now, and it still crashes at client.println().
Here is my code
#include <WiFi.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define OUT1 17
#define OUT2 5
#define OUT3 18
#define ONEWIRE_AIR 4
#define ONEWIRE_WATER 16
#define PROCESSING_PERIOD_SEC 20
#define COMMUNICATION_PERIOD_SEC 2
#define READ_ERROR_TIMEOUT_SEC 60
#define PROCESSING_PERIOD_TICKS PROCESSING_PERIOD_SEC
#define COMMUNICATION_PERIOD_TICKS COMMUNICATION_PERIOD_SEC
#define READ_ERROR_TIMEOUT_TICKS READ_ERROR_TIMEOUT_SEC
const uint16_t port = 77;
unsigned char WirelessIncoming, TCPRxString[144];
char TCPTxMessage[256];
String ssid = "******";
String password = "******";
String host = "192.168.0.3";
float setpointF = 25.0;
float threshold_up[3] = {1, 3,5};
float threshold_down[3] = {2,4,6};
unsigned short int id = 0;
unsigned char control_enable = 0;
float temperatureAir;
float temperatureWater;
OneWire oneWireAir(ONEWIRE_AIR);
OneWire oneWireWater(ONEWIRE_WATER);
DallasTemperature sensorAir(&oneWireAir);
DallasTemperature sensorWater(&oneWireWater);
hw_timer_t *Timer0_Cfg = NULL;
unsigned short int communication_ticks = 0;
bool communication_period = true;
WiFiClient client;
volatile SemaphoreHandle_t timerSemaphore;
void IRAM_ATTR Timer0_ISR()
{
xSemaphoreGiveFromISR(timerSemaphore, NULL);
}
void setup()
{
Serial.begin(230400);
pinMode(OUT1, OUTPUT); digitalWrite(OUT1,LOW);
pinMode(OUT2, OUTPUT); digitalWrite(OUT2,LOW);
pinMode(OUT3, OUTPUT); digitalWrite(OUT3,LOW);
sensorAir.begin();
sensorWater.begin();
WiFi.begin( ssid.c_str(), password.c_str());
timerSemaphore = xSemaphoreCreateBinary();
Timer0_Cfg = timerBegin(1000000);
timerAttachInterrupt(Timer0_Cfg, &Timer0_ISR);
timerAlarm(Timer0_Cfg, 1000000, true,0);
}
void loop()
{
sensorAir.requestTemperatures(); temperatureAir = sensorAir.getTempCByIndex(0);
sensorWater.requestTemperatures(); temperatureWater = sensorWater.getTempCByIndex(0);
if (xSemaphoreTake(timerSemaphore, 0) == pdTRUE)
{
communication_ticks++;
if (communication_ticks == COMMUNICATION_PERIOD_TICKS) //2 sec
{
communication_period = true;
communication_ticks = 0;
}
}
if (communication_period == true)
{
Serial.println("communication");
communication_period = false;
if (WiFi.status() == WL_CONNECTED)
{
Serial.println("WiFi connected");
if (client.connected()==false)
{
client.stop();
Serial.println("client not connected");
if (client.connect(host.c_str(), port))
{
Serial.println("connecting to sever");
}
}
else //povezani na server
{
Serial.println("client connected, sending");
sprintf(TCPTxMessage,"%u,%u,%.2f,%.2f,%d,%d,%d,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f", control_enable, id,temperatureAir,temperatureWater,digitalRead(OUT1),digitalRead(OUT2),digitalRead(OUT3),
setpointF, threshold_up[0],threshold_down[0],threshold_up[1],threshold_down[1],threshold_up[2],threshold_down[2] );
Serial.println("client message ready");
Serial.println(strlen(TCPTxMessage));
client.println(TCPTxMessage);
Serial.println("client message sent");
}
}
else Serial.println("WIFI not connected");
}
}
and here is the Output:
communication
WiFi connected
client connected, sending
client message ready
57
Guru Meditation Error: Core 1 panic'ed (InstrFetchProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x00000001 PS : 0x00060130 A0 : 0x8008e3ae A1 : 0x3ffbcbb0
A2 : 0x3ffc3df8 A3 : 0x00000018 A4 : 0x00000001 A5 : 0x00000000
A6 : 0x80000000 A7 : 0x3ffbdc80 A8 : 0x800e2aa5 A9 : 0x3ffbcb90
A10 : 0x00000001 A11 : 0xb33fffff A12 : 0x8008ff77 A13 : 0x3ffbcaa0
A14 : 0x00000003 A15 : 0x00060023 SAR : 0x00000000 EXCCAUSE: 0x00000014
EXCVADDR: 0x00000000 LBEG : 0x00000010 LEND : 0x00000000 LCOUNT : 0x00000000
Core 0 register dump:
PC : 0x00000004 PS : 0x00000000 A0 : 0x00000000 A1 : 0x000f4240
A2 : 0x00000000 A3 : 0x00000000 A4 : 0x00000000 A5 : 0x00000000
A6 : 0x60002000 A7 : 0x00000000 A8 : 0x00000000 A9 : 0x00000000
A10 : 0x00000000 A11 : 0x00000000 A12 : 0x00000000 A13 : 0x00000000
A14 : 0x00000000 A15 : 0xe01f8000 SAR : 0x9c400000 EXCCAUSE: 0x000007d0
EXCVADDR: 0x00004e20 LBEG : 0x000fffff LEND : 0x000fffff LCOUNT : 0x00000000
Backtrace: 0x00000001:0x000f4240 |<-CORRUPTED
ELF file SHA256: 1454c1bb29a24f65