Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <ESP8266WiFi.h>
- #include <WiFiUdp.h>
- const char* ssid = "XXXXX";
- const char* password = "XXXXX";
- WiFiUDP Udp;
- unsigned int localUdpPort = 4210; // lokaler Port auf den der ESP Reagiert
- char incomingPacket[255]; // Zwischenspeicher für eingehende Packete
- char atmega_bestaetigung[] = "X"; // die bestaetigung, die an den sender zurueck geht
- char atmega_uebertragung; // Befehle zur uebertragung an den Atmega bzw zur weiterverarbeitung
- char atmega_sendung; // Informationen vom Atmega an den Sender
- void setup()
- {
- Serial.begin(115200);
- Serial.println();
- Serial.printf("Verbinde zum Netzwerk %s ", ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED)
- {
- delay(500);
- Serial.print(".");
- }
- Serial.println(" Verbunden");
- Udp.begin(localUdpPort);
- Serial.printf("UDP Adresse: IP %s, UDP port %d\n", WiFi.localIP().toString().c_str(), localUdpPort);
- }
- void loop()
- {
- int packetSize = Udp.parsePacket();
- if (packetSize)
- {
- // receive incoming UDP packets
- // Serial.printf("Eingehend %d bytes von %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
- int len = Udp.read(incomingPacket, 255);
- if (len > 0)
- {
- incomingPacket[len] = 0;
- }
- Serial.printf("%s\n", incomingPacket);
- // Antwort an die Ip und Port, die ein Paket gesendet hat
- Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
- Udp.write(atmega_bestaetigung);
- Udp.endPacket();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement