Diaoul / arduino-ESP8266

An Arduino library to manage the ESP8266.
MIT License
68 stars 46 forks source link

Avoid mix block with different ID #14

Open tprochazka opened 9 years ago

tprochazka commented 9 years ago

I tried to solve problem with mixing +IPD blocks with different id to one stream. The most easiest solution is limit all read() method to only one +IPD block, then user will call available() again and get another block, it can be with the same or another ID. What is you onion on this?

I also removed infinite loop in read() a peek() method because it is unsafe and against Stream class documentation. For example if user of library will do some blocking operation during data arrive, it can skip some data on RX pin and the your implementation end in infinite loop, because available() was still return non zero value, but no additional data will arrive, there is no way to leave this deadlock.

I also fixes several compilation warning, like compare signed and unsigned variables, deprecated string conversion, etc.

I found interesting think. It is not possible to use readString(), because it it too slow and cause skip some data on the SoftwareSerialPort with 9600bps

lasselukkari commented 9 years ago

I don't think there is a software cure for this problem until the AT firmware has a software based flow control. There is nothing we can do without really large buffers on the Arduino side = not a real solution.

tprochazka commented 9 years ago

@lasselukkari If you mean create multiple Streams I agree, it is probably not possible without buffers, especially on software emulated UART :-( It is funny that ESP8266 itself has much more memory and power than Arduino itself ;-) Better solution is control arduino from EPS not ESP from Arduino :-)

tprochazka commented 9 years ago

Btw. Just question.

ESP8622Client is also Stream implementation. Does that make sense to have two implementation?

Yes. I know that ESP8622 is main library and ESP8622Client is only to allow use ESP8266 in standard way compatible with Arduino Ethernet and Wifi Library. But why then have duplicated Stream methods in the ESP8622 class itself. If I will use it, I will never can change to another transport layer like Ethernet and it should be main benefit to use ESP8622Client. Doesn't make sense to have Stream related functions only in ESP8622Client and common ESP8266 control (AT) methods in main class?