-->
Page 1 of 1

Problem with Server.Write()

PostPosted: Thu Aug 20, 2015 8:57 am
by Bipin
Hello Everybody,

I am facing an issue with Server.Write() function.

The setup that i am using is an ESP8266 (Coding in Arduino IDE) connected to custom AVR development Kit.

The requirement is to append mac address to the data received on ESP8266 serial port (from the AVR) to the connected clients.

For eg. say the Data received serially is 0x05 0x03 0x00 0x04 0xB5 0x8D

The required to be transmitted is 0x1A 0x22 0x33 0x44 0x55 0x66 0x05 0x03 0x00 0x04 0xB5 0x8D where 0x1A 0x22 0x33 0x44 0x55 0x66 is the mac ID.

The byte mac[6] contains the MAC address.

PROBLEM

The data received by the TCP/IP client is 0x1A 0x22 0x33 0x44 0x55 0x66 0x05 0x1A 0x22 0x33 0x44 0x55 0x66 0x03 0x00 0x04 0xB5 0x8D

Please note that the mac id is repeated twice.

Few things which i tried but in vain:

1. Suffix the mac instead of prefix
2. Try with just one byte of data to suffix or perfix
3. Add delay (1 ms to 1000ms) between subsequent server.write()
4. Getting both the buffers (sbuf and mac) to a third buffer

Has any body faced similar issue? Could you help me to understand this problem please?

Code: Select all//check UART for data
  if(Serial.available()){
    size_t len = Serial.available();
    uint8_t sbuf[len];
     
    Serial.readBytes(sbuf,len);
 
    //push UART data to all connected telnet clients
    for(i = 0; i < MAX_SRV_CLIENTS; i++)
    {
        if (serverClients[i] && serverClients[i].connected())
        {             
           
             serverClients[i].write(mac[0]);           
            serverClients[i].write(mac[1]);           
            serverClients[i].write(mac[2]);           
            serverClients[i].write(mac[3]);           
            serverClients[i].write(mac[4]);           
            serverClients[i].write(mac[5]);         
            serverClients[i].write(sbuf, len); 
            delay(1);
      }
    }