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 = 8;
- byte packetBuffer[packetSize];
- void setup() {
- Serial.begin(115200);
- delay(2000);
- Serial.println();
- 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) {
- UDPTestServer.read(packetBuffer, packetSize);
- String myData = "";
- for(int i = 0; i < packetSize; i++) {
- myData += (char)packetBuffer[i];
- }
- Serial.println(myData);
- if (myData == "led_on")
- {
- Serial.println("Ha led_on szöveg érkezik...");
- digitalWrite(LED_BUILTIN, HIGH);
- }
- if (myData == "led_off")
- {
- Serial.println("Ha led_off szöveg érkezik...");
- digitalWrite(LED_BUILTIN, LOW);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement