-
Notifications
You must be signed in to change notification settings - Fork 0
/
UDP.ino
61 lines (33 loc) · 882 Bytes
/
UDP.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char* ssid = "esp8266";
const char* password = "imuimuimu";
const char * udpAddress = "192.168.43.18";
const int udpPort = 5000;
String buff;
WiFiUDP udp;
void setup()
{
Serial.begin(115200);
Serial.println();
Serial.printf("Connecting to %s ", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println(" connected");
Serial.printf("Web server started, open %s in a web browser\n", WiFi.localIP().toString().c_str());
}
void loop()
{
if(Serial.available()){
buff = Serial.readStringUntil('\n');
char charBuf[buff.length() + 1];
buff.toCharArray(charBuf, buff.length() + 1);
udp.beginPacket(udpAddress,udpPort);
udp.printf("%u %s",millis(),charBuf);
udp.endPacket();
}
}