SparkFun_ESP8266_AT_Arduino_Library icon indicating copy to clipboard operation
SparkFun_ESP8266_AT_Arduino_Library copied to clipboard

print doesn't write full buffer

Open yycho0108 opened this issue 8 years ago • 0 comments

In SparkFunESP8266WiFi.cpp, in function: int16_t ESP8266Class::tcpSend(uint8_t linkID, const uint8_t *buf, size_t size),

print((const char *)buf) (line 526) ignores the size parameter that was passed to tcpSend, and stops sending at the null byte (treating it as a string).

Because of this, I couldn't transmit the full message when I had null bytes in my message (I was sending structures & serialized data, not just strings, so it had some zero bytes)

to fix this, I replaced print((const char *)buf) with Print::write((const char *)buf, size). (prepended namespace to avoid conflicts with ESP8266Class::write)

This is a somewhat minor fix, though.

//

On a side note, ESP8266Client::connected() seems to return false even when connection is established. That is, when I run:

if (!client.connected()) res = client.connect(ip,port),

it outputs 2 (already connected) even though it just indicated that the client was not connected.

Can you double check on this? It seems that either ESP8266Client::connected() or ESP8266Class::status() is doing something strange since ESP8266Class::status() never really returns ESP8266_STATUS_CONNECTED (which would make more sense if status() returned _status.stat instead of 0/1).

yycho0108 avatar Jun 20 '16 01:06 yycho0108