-->
Page 1 of 2

problem with UDP link between 2 nodeMCU's

PostPosted: Wed Nov 23, 2016 3:31 pm
by ardlab
2 nodeMCU's (V1.0) exchange data by means of a UPD link.
the robot is the soft acces point, the remote control is the client.

I found the code on this site and it has always worked very reliable.

I've bought many nodeMCU (for multiple workshops I am planning) and now I see that this code does not work for all the nodeMCU's that I received.
I received a batch of 10 nodeMCU's and all 10 only work reliable as client but NONE work reliable as access point, the client transmits data every 0.5 second but the access point does not receive it, this is what I get in the serial monitor.

note that millis is not millis but a simple value that is incremented by 1 after a delay of 500 ms (just for test purposes to keep it simple)


Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 970
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 971
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 973
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 974
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 975
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 976
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 979
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 980
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 982
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 983
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 984
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 985
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 988
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 989
Recibido(IP/Size/Data): 192.168.4.10 / 13 / Millis: 990


Exactly the same code does give 100 % correct reception with all my other nodeMCU's (I have 50+).

I wonder how I can troubleshoot this, I only have rather limited esp knowledge.
I was thinking it could be a nodeMCU firmware version issue but I have no idea how to check the installed firmware (if possible at all).

I tried to flash a nodeMCU with the nodeMCUfirmware programmer, using INTERNAL://NODEMCU setting in the Config tab but without effect (nodeMCU not bricked but UDP access point still not working 100%).

Using OSX with Arduino IDE 1.6.12 and esp 2.3.0 but I have exactly the same problem with IDE 1.6.8 and esp2.2.0


Below the code for access point (robot) and station (remote control)

Any help would be greatly appreciated.



CODE FOR access point (ROBOT)
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

WiFiUDP Udp;
char packetBuffer[255];
unsigned int localPort = 9999;
const char *ssid = "WiFi Robot";
const char *password = "";

void setup() {
  Serial.begin(115200);
  Serial.print("\n start init");
  WiFi.softAP(ssid, password);
  Udp.begin(localPort);
  Serial.print("\n end init");
}

void loop() {
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    int len = Udp.read(packetBuffer, 255);
    if (len > 0) packetBuffer[len - 1] = 0;
    Serial.print("Recibido(IP/Size/Data): ");
    Serial.print(Udp.remoteIP()); Serial.print(" / ");
    Serial.print(packetSize); Serial.print(" / ");
    Serial.println(packetBuffer);

    Udp.beginPacket(Udp.remoteIP(), Udp.remotePort());
    Udp.write("recived: ");
    Udp.write(packetBuffer);
    Udp.write("\r\n");
    Udp.endPacket();
  }
}

// - See more at: http://www.esp8266.com/viewtopic.php?f=29&t=4006#sthash.i5nGIIyP.dpuf


CODE FOR CLIENT (= station mode)

Code: Select all#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

WiFiUDP Udp;
const char *ssid = "WiFi Robot";  //
const char *password = "";

char packetBuffer[255];
unsigned int localPort = 9999;
IPAddress ipServidor(192, 168, 4, 1);
IPAddress ipCliente(192, 168, 4, 10);
IPAddress Subnet(255, 255, 255, 0);


unsigned long Tiempo_Envio = millis();


void setup() {
  Serial.begin(115200);
  WiFi.begin(ssid, password);
  WiFi.mode(WIFI_STA); // para que solo sea STA y no genere la IP 192.168.4.1
  WiFi.config(ipCliente, ipServidor, Subnet);
  Udp.begin(localPort);
}

void loop() {

  //ENVIO
  Tiempo_Envio++;
  Udp.beginPacket(ipServidor, 9999);
  Udp.write("Millis: ");
  char buf[20];
  unsigned long testID = Tiempo_Envio;
  sprintf(buf, "%lu", testID);
  Udp.write(buf);
  Udp.write("\r\n");
  Udp.endPacket();
  Serial.print("enviando: "); Serial.println(buf);
  delay(10); // para que le de tiempo a recibir la respuesta al envio anterior

  //RECEPCION
  int packetSize = Udp.parsePacket();
  if (packetSize) {
    int len = Udp.read(packetBuffer, 255);
    if (len > 0) packetBuffer[len - 1] = 0;
    Serial.print("RECIBIDO(IP/Port/Size/Datos): ");
    Serial.print(Udp.remoteIP()); Serial.print(" / ");
    Serial.print(Udp.remotePort()); Serial.print(" / ");
    Serial.print(packetSize); Serial.print(" / ");
    Serial.println(packetBuffer);
  }
  Serial.println("");
  delay(500);
}
//- See more at: http://www.esp8266.com/viewtopic.php?f=29&t=4006#sthash.i5nGIIyP.dpuf

Re: problem with UDP link between 2 nodeMCU's

PostPosted: Tue Nov 29, 2016 12:16 pm
by mrburnette
This is the first I have heard of such an issue.

May I suggest that you use the ESP upload utility and flash "blank" into the EEPROM sections... then try your ArduinoIDE again.

It could be that the EEPROM used is crazy slow / defective (or just cheap!) The ESP8266 chip proper should not be an issue if it is indeed genuine.

Ray

Re: problem with UDP link between 2 nodeMCU's

PostPosted: Wed Nov 30, 2016 6:58 am
by ardlab
Ray,

Thanks for your answer.
Could you give me some additional info on how to flash "blank" into the EEPROM?
I do not know how to do this.

Can you advise me which pre-built binaries to use ?

Thanks

Hans

Re: problem with UDP link between 2 nodeMCU's

PostPosted: Sun Dec 04, 2016 9:10 am
by mrburnette
Sorry for the delay in answering .... traveling.
http://www.pratikpanda.com/completely-format-erase-esp8266-flash-memory/

Ray