Last active
June 15, 2020 02:53
-
-
Save devyte/2c7c5404294f93c20c841179e88291cd to your computer and use it in GitHub Desktop.
Udp Reentrancy Issue due to endPacketMayRetry() and scheduled functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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