1

I'm trying to transfer data from ESP8266(NodeMCU ESP12E) to my laptop. I'm coding ESP using Arduino IDE. I am able to receive correct packets (each containing 400 bytes) on a visual basic console program. However, to see whether the transmission is continuous or not, I have toggled an output pin whenever UDP.endpacket() returns 1. I observed waveforms on DSO. I found that UDP.endpacket() does NOT return 1 many times and the there is no transmission from ESP for a significant amount of time (milliseconds). Refer attached waveforms.

Why does UDP.endpacket() return 0 for such long time? Why is UDP transmission getting interrupted? How can I solve this? Please feel free to ask for more details if necessary.

Code :

#include <ESP8266WiFi.h>
#include <WiFiUdp.h>

const char* ssid = "Connectify-me33";
const char* password = "donfour276"; 

WiFiUDP Udp;
unsigned int localUdpPort = 65000; 

unsigned int dest_port = 11000;

unsigned char clientBuf[400];
int clientBuf_len=0;

#define test_pin 5    

int return_udp_fcn = 0;


void setup()
{

  WiFi.begin(ssid, password);
  delay(5000);

  Udp.begin(localUdpPort);


  pinMode(test_pin, OUTPUT);
  digitalWrite(test_pin, HIGH); 

  pinMode(LED_BUILTIN, OUTPUT);     
  digitalWrite(LED_BUILTIN, LOW); 
  delay(1000);
  digitalWrite(LED_BUILTIN, HIGH); 
  delay(1000);
  digitalWrite(LED_BUILTIN, LOW); 
  delay(1000);
  digitalWrite(LED_BUILTIN, HIGH); 
  delay(1000);


}


void loop()
{
        digitalWrite(test_pin, HIGH); 

        //filling up buffer
        for(clientBuf_len = 0; clientBuf_len<=399; clientBuf_len++)
        {
            clientBuf[clientBuf_len] = 0x7E;
        }

        //UDP transmit
        Udp.beginPacket("172.22.0.1", dest_port); 
        Udp.write((const uint8_t *)clientBuf, 400);
        return_udp_fcn = 0;
        return_udp_fcn = Udp.endPacket();
        if(return_udp_fcn){
          digitalWrite(test_pin, LOW); 
        }
        delayMicroseconds(100);

}

test-pin waveform : interruptions can be observed

1

I think you need a delay(1); after your call to write().

There is/was a bug where the underlying buffer files up and can't get time to clear. It looks like it will require a change to the ESP8266 firmware from the manufacturers before it will get fixed properly.

See what you think:

https://github.com/esp8266/Arduino/issues/1696

https://github.com/esp8266/Arduino/issues/2285

|improve this answer|||||
  • Thank you for your quick response. I tried again with a delay after write. I got the same results. I also tried with multiple delays after each line in the code. The problem still persists. – Pushkar Chaudhari Aug 10 '17 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.