Announcement

Collapse
No announcement yet.

sending data using UDP from phpoc to nodemcu using arduino IDE,PHPOC as softAP

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • sending data using UDP from phpoc to nodemcu using arduino IDE,PHPOC as softAP

    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

  • #2
    Hi there,

    One possible reason for your issue is that your nodeMCU and PHPoC board are not yet connected via Wi-Fi network, let alone the UDP connection.

    By default, a PHPoC board in Soft AP mode will operate with the IP address 192.168.0.1 (not 192.168.1.1).
    I guess you may need to check the IP configuration in your nodeMCU to avoid network configuration mismatches.

    Anyway, it is recommended to test your application by connecting your nodeMCU and PHPoC board to an existing Wi-Fi network
    (PHPoC board operating in Infrastructure mode instead of Soft AP).
    If it works, then we can be sure that only the network configuration has caused the current problem in your application.

    Cheers

    Comment


    • #3
      i am operating the phpoc as infrastructure mode and it is working and i checked and i can see it connected to the router, and i can also see the nodemcu connected to router.

      can u still help me cause i am still can't recieve the data from phpoc using this code( sending from the phpoc) :

      UDP.beginPacket("192.168.1.184", 4210); // this is a static ip address of the nodemcu

      UDP.write("hello User");

      UDP.endPacket();



      and i use this code on the node mcu to recieve the data, code:


      this is the void loop:
      ,
      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);
      }
      }


      for the phpoc to send data to the nodemcu( i gave the nodemcu a static address but still the nodemcu keep giving me 0 ( which means the packet size recieved is 0).
      Last edited by Ahmed youssef; 10-11-2021, 09:13 PM.

      Comment


      • #4
        Hello again.

        Did the UDP connection work well when you connect your nodeMCU and PHPoC board in infrastructure mode?

        Could you please check your IP setting parameters on your nodeMCU?
        As in the previous reply, the IP address of the PHPoC board in Soft AP mode is 192.168.0.1.
        I guess you may try to set your nodeMCU to an IP address 192.168.0.XXX rather than 192.168.1.184 and test your application.
        Please double-check every network parameter in your case.

        Cheers

        Comment

        Working...
        X