Skip to content

Instantly share code, notes, and snippets.

@devyte
Last active June 15, 2020 02:53
Show Gist options
  • Save devyte/2c7c5404294f93c20c841179e88291cd to your computer and use it in GitHub Desktop.
Save devyte/2c7c5404294f93c20c841179e88291cd to your computer and use it in GitHub Desktop.
Udp Reentrancy Issue due to endPacketMayRetry() and scheduled functions
#include "Arduino.h"
WiFiUdp Udp;
Ticker pingAlive;
void pingAliveFunction()
{
Udp.beginPacket("watchdog.host.net", 12345);
Udp.write("I'm still alive you dolt");
Udp.endPacketMayRetry(); //retry if fail
}
esp8266::polledTimeout::periodic checkGPIO(200);
int lastGPIO;
void setup()
{
WiFi.begin("blah", "bleh") ;
while(WiFi.status() != connected)
{
}
pingAlive.attach_scheduled(pingAliveFunction, 1000);
pinMode(4, INPUT);
lastGPIO = digitalRead(4);
}
void loop()
{
if(WiFi. status() == connected && checkGPIO)
{
int currGPIO = digitalRead(4);
if(currGPIO != lastGPIO)
{
lastGPIO = currGPIO;
Udp.beginPacket("watchdog.host.net", 12345);
Udp.write(String("gpio=") + currGPIO);
Udp.endPacketMayRetry();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment