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)
#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)
#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