Using the new Arduino IDE for ESP8266 and found bugs, report them here

Moderator: igrr

User avatar
By gerardwr
#13642
robertnash30 wrote:For posterity, this issue has been solved on the GitHub page. Simply use a different instance of WiFiUDP for sending data.


I'm puzzled !

Did you actually see this working? When yes, how?

I tried it, and after sending data to the 2nd UDP instance the receiving of data continued, so that's solved.

But the written data did not arrive at my Mac (used "nc -u 192.168.1.100 2390").

I tried using remoteIP() and remotePort() for the 2nd UDP instance, and I tried hardcoding. Both "replies" did not reach my Mac. Maybe the issues is on my Mac?
User avatar
By robertnash30
#13666 I've tried it now and it seems to be working for me on Windows; using the code below if it helps.

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

WiFiClient client;
WiFiUDP port;
WiFiUDP port2;

char packetBuffer[255];
unsigned int localPort = 9999;
IPAddress serverIP(192, 168, 1, 117);


void setup() {
  Serial.begin(9600);
  WiFi.begin("xxxxxxxxxxxxxx", "xxxxxxxxxxxxx");
  port.begin(9999);
  pinMode(2, OUTPUT);
  digitalWrite(2,LOW);
}

void loop() {
  int packetSize = port.parsePacket();
  Serial.println(packetSize);
  if (packetSize) {
    int len = port.read(packetBuffer, 255);
    if (len > 0) packetBuffer[len] = 0;
    Serial.println(packetBuffer);
    handleMessage(String(packetBuffer));
  }
  delay(500);
}

void handleMessage(String data) {
  if(data=="on"){
    digitalWrite(2,HIGH);
    Serial.println("ON");
    sendMessage("light on");
  }
  if(data=="off"){
    digitalWrite(2,LOW);
    Serial.write("OFF");
    sendMessage("light off");
  }
}

void sendMessage(char data[]) {
  port2.beginPacket(serverIP,localPort);
  port2.write(data);
  port2.endPacket();
}
User avatar
By gerardwr
#13717
robertnash30 wrote:I've tried it now and it seems to be working for me on Windows; using the code below if it helps.


Thanks for the example.

I suppose it works when you start a separate UDP-server and UDP-browser on your Windows, right?

A real UDP implementation should be bi-directional, with 1 application on each "end", apparently this is not possible in the current Arduino-ESP environment.

In the current situation a sketch where an ESP client would access an NTP server, and get the NTP-time as reply would not be possible.

I still feel this is "a bug".
User avatar
By robertnash30
#13729
gerardwr wrote:I suppose it works when you start a separate UDP-server and UDP-browser on your Windows, right?


I seem to be able to get it to work with a python programme with bi-directional communication although I might be misunderstanding you. This code below sends "on" every two seconds and I can see the reply("light on") from the ESP being printed by the programme every two seconds as well.

Code: Select allimport socket
import time

UDP_IP = "192.168.1.119"
UDP_PORT = 9999

sock = socket.socket(socket.AF_INET, # Internet
                     socket.SOCK_DGRAM) # UDP
sock.bind(('', UDP_PORT))
sock.setblocking(False);
while 1:
    sock.sendto("on", (UDP_IP, UDP_PORT))
    try:
        data = sock.recv(4096)
        print data
    except:
        pass
    time.sleep(2)