I have a problem that i am trying to connect my nodemcu with my phpoc(P47s-347) using the PHPOC as AP, and send data from the arduino(PHPOC) to the nodemcu using UDP, but on my nodemcu(esp8266) i recieve nothing.
UDP.beginPacket("192.168.1.184", 4210); // this is a static ip address of the nodemcu
UDP.write("hello User");
UDP.endPacket();
----------------------------------------------------------------
This is the code for the Nodemcu
#define WIFI_SSID "ph_1234"
#define WIFI_PASS "123456789"
#define UDP_PORT 4210
// UDP
WiFiUDP UDP;
char packet[255];
// Set my Static IP address
IPAddress local_IP(192,168,1,184);
// Set my Gateway IP address
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8);
IPAddress secondaryDNS(8, 8, 4, 4);
void setup() {
// Setup serial port
Serial.begin(115200);
Serial.println();
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");
}
// Begin WiFi
WiFi.begin(WIFI_SSID, WIFI_PASS);
// Connecting to WiFi...
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
// Loop continuously while WiFi is not connected
while (WiFi.status() != WL_CONNECTED)
{
delay(100);
Serial.print(".");
}
// Connected to WiFi
Serial.println();
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());
// Begin listening to UDP port
UDP.begin(UDP_PORT);
Serial.print("Listening on UDP port ");
Serial.println(UDP_PORT);
}
void loop() {
int packetSize = UDP.parsePacket();
Serial.println(packetSize);
if (packetSize)
{
Serial.println("we are in");
// receive incoming UDP packets
//Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
int len = UDP.read(packet, 255);
if (len > 0)
{
packet[len] = 0 ;
}
Serial.print("Packet received: ");
Serial.println(packet);
}
}
Any help would be apperiated.
Thanks
UDP.beginPacket("192.168.1.184", 4210); // this is a static ip address of the nodemcu
UDP.write("hello User");
UDP.endPacket();
----------------------------------------------------------------
This is the code for the Nodemcu
#define WIFI_SSID "ph_1234"
#define WIFI_PASS "123456789"
#define UDP_PORT 4210
// UDP
WiFiUDP UDP;
char packet[255];
// Set my Static IP address
IPAddress local_IP(192,168,1,184);
// Set my Gateway IP address
IPAddress gateway(192, 168, 1, 1);
IPAddress subnet(255, 255, 0, 0);
IPAddress primaryDNS(8, 8, 8, 8);
IPAddress secondaryDNS(8, 8, 4, 4);
void setup() {
// Setup serial port
Serial.begin(115200);
Serial.println();
if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
Serial.println("STA Failed to configure");
}
// Begin WiFi
WiFi.begin(WIFI_SSID, WIFI_PASS);
// Connecting to WiFi...
Serial.print("Connecting to ");
Serial.print(WIFI_SSID);
// Loop continuously while WiFi is not connected
while (WiFi.status() != WL_CONNECTED)
{
delay(100);
Serial.print(".");
}
// Connected to WiFi
Serial.println();
Serial.print("Connected! IP address: ");
Serial.println(WiFi.localIP());
// Begin listening to UDP port
UDP.begin(UDP_PORT);
Serial.print("Listening on UDP port ");
Serial.println(UDP_PORT);
}
void loop() {
int packetSize = UDP.parsePacket();
Serial.println(packetSize);
if (packetSize)
{
Serial.println("we are in");
// receive incoming UDP packets
//Serial.printf("Received %d bytes from %s, port %d\n", packetSize, Udp.remoteIP().toString().c_str(), Udp.remotePort());
int len = UDP.read(packet, 255);
if (len > 0)
{
packet[len] = 0 ;
}
Serial.print("Packet received: ");
Serial.println(packet);
}
}
Any help would be apperiated.
Thanks
Comment