Last active
March 2, 2016 21:44
-
-
Save kasperkamperman/1f646fecf099289c8b3d to your computer and use it in GitHub Desktop.
Particle UDP time out?
This file contains hidden or 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
/* | |
When no packets are received Udp.parsePacket() takes 997us (about 1ms) | |
When a packet is received it takes 17us. | |
I think there is a timeout. It would be nice if we can set that with a function like: setTimeOut (like on Arduino with the Serial port). | |
I'd like to set it on microsecond level. | |
You can try this script by sending for example OSC data (I used TouchOSC). | |
When you receive data it displays a '/' (first character in an OSC string). | |
*/ | |
#include "application.h" | |
// UDP Port used for two way communication | |
unsigned int localPort = 8000; | |
// An UDP instance to let us send and receive packets over UDP | |
UDP Udp; | |
unsigned long t1; // for measuring purposes | |
unsigned long t2; // for measuring purposes | |
unsigned long t3 = 0; // for measuring purposes | |
void setTime() { | |
t1 = micros(); | |
} | |
void printTime() { | |
t2 = micros()-t1; | |
if(t2>t3) t3 = t2; | |
Serial.print(F("time: ")); | |
Serial.print(t3); | |
Serial.print(" "); | |
Serial.println(t2); | |
} | |
void setup() { | |
// start the UDP | |
Udp.begin(localPort); | |
// Print your device IP Address via serial | |
Serial.begin(57600); | |
Serial.println(WiFi.localIP()); | |
} | |
void loop() { | |
char a = '-'; | |
setTime(); | |
if (Udp.parsePacket() > 0) { | |
// Read first char of data received | |
a = Udp.read(); | |
// Ignore other chars | |
Udp.flush(); | |
// Store sender ip and port | |
//IPAddress ipAddress = Udp.remoteIP(); | |
//int port = Udp.remotePort(); | |
// Echo back data to sender | |
//Udp.beginPacket(ipAddress, port); | |
//Udp.write(c); | |
//Udp.endPacket(); | |
} | |
printTime(); | |
// print the read character | |
Serial.println(a); | |
delay(100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment