Moppy2
Moppy2 copied to clipboard
UDP not working
In the UI I used the UDP server. I checked the Box and no errors in the Command Prompt window.
This is the code I used on my ESP8266, mostly copyed from the moppy2 sources for ESP8266 But I dont get any messages when I Start playing in the UI. When I use a other UDP Software I can send messages to the ESP8266 without any problem.
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#ifndef STASSID
#define STASSID "MyWifi"
#define STAPSK "MyPSK"
#endif
WiFiUDP UDP;
void setup() {
Serial.begin(57600);
WiFi.mode(WIFI_STA);
WiFi.begin(STASSID, STAPSK);
while (WiFi.status() != WL_CONNECTED) {
Serial.print('.');
delay(500);
}
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());
Serial.printf("UDP server on port %d\n", localPort);
Serial.println("");
Serial.println("Connecting to UDP");
if (UDP.beginMulticast(WiFi.localIP(), IPAddress(239, 2, 2, 7), 30994) == 1) {
Serial.println("Connection successful");
} else {
Serial.println("Connection failed");
}
}
uint8_t messagePos = 0; // Track current message read position
uint8_t messageBuffer[259]; // Max message length for Moppy messages is 259
void loop() {
// Handle UDP packets
int packetSize = UDP.parsePacket();
if (packetSize) {
Serial.println("");
Serial.print("Received packet of size ");
Serial.println(packetSize);
Serial.print("From ");
IPAddress remote = UDP.remoteIP();
for (int i = 0; i < 4; i++) {
Serial.print(remote[i], DEC);
if (i < 3) {
Serial.print(".");
}
}
Serial.print(", port ");
Serial.println(UDP.remotePort());
// read the packet into messageBuffer
int messageLength = UDP.read(messageBuffer, 259);
UDP.flush(); // Just incase we got a really long packet
}
}
If other software can send UDP to the microcontroller without issue, it sounds like it might be a problem on the Java/Controller side of things. Do you have any UDP tools you can use to test receiving the UDP messages from the Controller? A packet sniffer would work for this too.
Could be a Windows Firewall thing?