Jetzt kommt eine Sache, die mich sehr verwirrt. Beim ersten Test funktioniert alles wunderbar. Nun habe ich ein neues Script gemacht wo ich quasi den "ServerESP" machen wollte aber dort kommt bei der Udp Class ein Compileerror (beim anderen Script nicht).
Arduino: 1.8.5 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E Module), 80 MHz, 115200, 4M (3M SPIFFS)"
D:\Schule\Seminarfach\arduino\ServerESP_test\ServerESP_test.ino: In function 'void startWiFi()':
ServerESP_test:36: error: The Udp class has been renamed EthernetUdp.
As of Arduino 1.0, the Udp class in the Ethernet library has been renamed to EthernetUdp.
Udp.begin(localPort); //start UDP-Server
^
D:\Schule\Seminarfach\arduino\ServerESP_test\ServerESP_test.ino: In function 'void checkUDPServer()':
ServerESP_test:43: error: 'WiFiUdp' has not been declared
int packetSize = WiFiUdp::Udp.parsePacket();
^
ServerESP_test:50: error: The Udp class has been renamed EthernetUdp.
As of Arduino 1.0, the Udp class in the Ethernet library has been renamed to EthernetUdp.
Udp.remoteIP().toString().c_str(), Udp.remotePort(),
^
exit status 1
The Udp class has been renamed EthernetUdp.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
Die Sache die mich am meisten Verwirrt ist, dass ich dein Script und meinen erster Test ohne Compileerror funktionieren, aber dieses Script nicht...
//TODO: add UDP-TX
//TODO: add autonomus driving
//TODO: add Buttons
/*
* WIFI UDP communication based on a script by noiasca:
* https://forum.arduino.cc/index.php?topic=676411.15
*
*
*/
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
//############################################# WIFI-SETUP ####################
IPAddress myIP(192,168,137,101);
IPAddress mySubnet(255,255,255,0);
IPAddress myGateway(192,168,137,200);
const uint32_t localPort = 1337;
IPAddress clientA(192, 168, 137, 21);
IPAddress clientB(192, 168, 137, 42);
const char* WiFissid = "supernicename";
const char* WiFipass = "supersecretpassword";
void startWiFi(){
WiFi.disconnect();
delay(20);
WiFi.config(myIP,myGateway,mySubnet);
WiFi.mode(WIFI_STA);
Serial.print(F("init WiFi:")); //DEBUG
WiFi.begin(WiFissid, WiFipass);
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.'); //DBEUG
delay(500);
}
Serial.print(F("Connected! IP address: ")); //DEBUG
Serial.println(WiFi.localIP()); //DEBUG
Serial.printf("UDP server on port %d\n", localPort); //DEBUG
Udp.begin(localPort); //start UDP-Server
}
//############################################# UDP-RX ########################
void checkUDPServer()
{
// if there's data available, read a packet
int packetSize = WiFiUdp::Udp.parsePacket();
if (packetSize) {
// buffers for receiving and sending data
char packetBuffer[UDP_TX_PACKET_MAX_SIZE + 1]; // buffer to hold incoming packet,
char ReplyBuffer[] = "OK"; // a string to send back
Serial.printf("Received packet of size %d from %s:%d\n (to %s:%d, free heap = %d B)\n",
packetSize,
Udp.remoteIP().toString().c_str(), Udp.remotePort(),
Udp.destinationIP().toString().c_str(), Udp.localPort(),
ESP.getFreeHeap()); //DEBUG
// read the packet into packetBufffer
int n = Udp.read(packetBuffer, UDP_TX_PACKET_MAX_SIZE);
packetBuffer[n] = 0;
Serial.println("Contents:"); //DEBUG
Serial.println(packetBuffer); //DEBUG
// send a reply, to the IP address and port that sent us the packet we received
Serial.printf("send answer to %s:%d\n",Udp.remoteIP().toString().c_str(), Udp.remotePort()); //DEBUG
Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
Udp.write(ReplyBuffer);
Udp.endPacket();
}
}
//############################################# UDP-TX ########################
//############################################# MAIN SECTION #################
void setup() {
Serial.begin(115200);
pinMode(LED_BUILTIN,OUTPUT);
digitalWrite(LED_BUILTIN,HIGH);
startWiFi();
digitalWrite(LED_BUILTIN,LOW);
}
void loop() {
checkUDPServer();
}
//############################################# END PRGM #####################
irgendeine Idee wieso das nun plötzlich auftaucht?
Beste Grüße
CodeCrafter1