Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <WiFiUdp.h>
- // config:
- const char *ssid = "ESPWifiTeszt"; // You will connect your phone to this Access Point
- const char *pw = "nincs"; // and this is the password
- IPAddress ip(192, 168, 1, 10); // From RoboRemo app, connect to this IP
- IPAddress netmask(255, 255, 255, 0);
- WiFiUDP UDPTestServer;
- unsigned int UDPPort = 4000;
- const int packetSize = 20;
- char packetBuffer[packetSize];
- void setup() {
- Serial.begin(115200);
- WiFi.softAPConfig(ip, ip, netmask); // configure ip address for softAP
- WiFi.softAP(ssid, pw); // configure ssid and password for softAP
- Serial.println("Wemos D1R2 UDP teszt");
- Serial.println((String)"SSID: " + ssid + " PASS: " + pw);
- Serial.println((String)"RoboRemo app must connect to " + ip.toString() + ":" + UDPPort);
- UDPTestServer.begin(UDPPort);
- pinMode(LED_BUILTIN, OUTPUT);
- digitalWrite(LED_BUILTIN, LOW);
- }
- void loop() {
- handleUDPServer();
- delay(1);
- }
- void handleUDPServer() {
- int cb = UDPTestServer.parsePacket();
- if (cb) {
- int len = UDPTestServer.read(packetBuffer, packetSize);
- if (len > 0) {
- packetBuffer[len-1] = '\0';
- if (strcmp(packetBuffer, "led_on") == 0) {
- Serial.println("Ha led_on szöveg érkezik...");
- digitalWrite(LED_BUILTIN, HIGH);
- }
- if (strcmp(packetBuffer, "led_off") == 0) {
- Serial.println("Ha led_off szöveg érkezik...");
- digitalWrite(LED_BUILTIN, LOW);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement