Code: Select all
String server_address;
bool is_config = false;
const byte interruptPin = 27;
volatile int interruptCounter = 0;
int numberOfInterrupts = 0;
portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;
void IRAM_ATTR handleInterrupt() {
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
portENTER_CRITICAL_ISR(&mux);
if (interrupt_time - last_interrupt_time > 10)
{
interruptCounter++;
}
portEXIT_CRITICAL_ISR(&mux);
last_interrupt_time = interrupt_time;
}
void setup_counter()
{
is_config = false;
Serial.begin(115200);
Serial.println("Monitoring interrupts: ");
pinMode(interruptPin, INPUT_PULLUP);
pinMode(2, OUTPUT);
attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);
Serial.println("SSID:|"+(ssid)+"|");
Serial.println("PASS:|"+(pass)+"|");
WiFi.begin(string2char(ssid),string2char(pass));
while (WiFi.status() != WL_CONNECTED) { //Check for the connection
delay(500);
Serial.println("Connecting..");
}
void loop()
{
if(is_config)
return;
//if(interruptCounter>0)
{
portENTER_CRITICAL(&mux);
numberOfInterrupts = interruptCounter;
interruptCounter = 0;
portEXIT_CRITICAL(&mux);
if(numberOfInterrupts%2 == 0)
digitalWrite(2,HIGH);
else
digitalWrite(2,LOW);
Serial.print("An interrupt has occurred. Total: ");
Serial.println(numberOfInterrupts);
HTTPClient http;
http.begin(server_address+":9021/detected/"+device_id+"/"+numberOfInterrupts); //Specify destination for HTTP request
http.addHeader("Content-Type", "text/plain"); //Specify content-type header
int httpResponseCode = http.POST(""); //Send the actual POST request
Serial.println(httpResponseCode);
if(httpResponseCode>0)
{
Serial.println(httpResponseCode); //Print return code
}
else
{
Serial.print("Error on sending request: ");
Serial.println(httpResponseCode);
}
http.end();
delay(5000);
}
}
I am sending a light switch on/off count data to a python flask web server
The above code works perfectly fine but if I try to send anything in the post
Code: Select all
int httpResponseCode = http.POST("MAGIC"); //Send the actual POST request
to avoid this, for now I am passing the values in url but I cannot figure out why this is happening.
any idea as to why would this be happening ?
and generates this
Connected to the WiFi network with IP: 192.168.1.101
An interrupt has occurred. Total: 0
[E][WiFiClient.cpp:382] read(): 104
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x400d3e0c PS : 0x00060230 A0 : 0x800d3ee3 A1 : 0x3ffb1d10
A2 : 0x00000000 A3 : 0x3ffb1d5f A4 : 0x00000001 A5 : 0x00000001
A6 : 0x00000000 A7 : 0x00000000 A8 : 0x00000000 A9 : 0x00000000
A10 : 0x00000000 A11 : 0x00000000 A12 : 0x00000050 A13 : 0x00000000
A14 : 0x00000000 A15 : 0x00000000 SAR : 0x0000000a EXCCAUSE: 0x0000001c
EXCVADDR: 0x00000008 LBEG : 0x4000c2e0 LEND : 0x4000c2f6 LCOUNT : 0xffffffff
Backtrace: 0x400d3e0c:0x3ffb1d10 0x400d3ee0:0x3ffb1d30 0x4015ed16:0x3ffb1d50 0x400daa45:0x3ffb1d80 0x400daa79:0x3ffb1da0 0x400d3359:0x3ffb1dc0 0x400d3763:0x3ffb1e50 0x400d37a3:0x3ffb1e90 0x400d37bc:0x3ffb1eb0 0x400d294a:0x3ffb1ed0 0x4014374a:0x3ffb1fa0
Rebooting...