Comments (1)
Reading without cheking .available()?
Yes an impressing library!
I was also was wondering about the delays.
The reason could be it fixed a problem with using readChar() in listenForIncomingMessage() where there is no check before reading the input stream.
I removed the delays completely and made a readCharW(ms)
char SerialESP8266wifi::readCharW(int timeout) {
if (_serialIn->available()) {
return readChar();
}
unsigned long stop = millis() + timeout;
do {
if (_serialIn->available()) {
return readChar();
}
} while (millis() < stop);
return 0;
}
..and used that wherever i found readChar() being used after a successful readCommand(). readCommand() finds a keyword, but you have no clue if there are more characters in the input buffer and should not read without checking .available() first.
Patrt 2 - What about integrating a Stream?
The accumulation of data in the send command was inventive. It got me thinking of using a Stream class as input instead. Then you can have the Stream point to the msgOut buffer and when you flush it some underlying code in the stream calls the send() method when stream tends to be near full as well.
Maybe some skilled developer can redesign the WiFi class to inherit from Stream or maybe expose a Stream property.
Here my send() function test:
//Something like this?..
bool SerialESP8266wifi::send(uint8_t channel, MemoryStream& stream){
watchdogConnect();
writeCommand(CIPSEND);
_serialOut -> print(channel);
writeCommand(COMMA);
_serialOut -> println(stream.available());
byte prompt = readCommand(1000, PROMPT, ERROR);
if (prompt != 2) {
while (stream.available())
{
_serialOut->write(stream.read());
}
byte sendStatus = readCommand(5000, SEND_OK, BUSY);
if (sendStatus == 1) {
//msgOut[0] = '\0';
if(channel == SERVER_CHAN)
flags.connectedToServer = true;
return true;
}
}
else
{
//ERROR Assume not connected
flags.connectedToServer = false;
}
#if WIFI_FOOTPRINT == 2
if(channel == SERVER_CHAN)
flags.connectedToServer = false;
else
_connections[channel-0x30].connected = false;
#endif
from esp8266wifi.
Related Issues (20)
- library.json is corrupt HOT 1
- can not connected to the server
- support chinese data transmission?
- ,
- can't stop client when client isn't receive data
- Sending string message to server via AP HOT 1
- Wrong names and links
- why not work
- Local Web Server, STM32 blue pill
- Error receiving a message from the server
- AT+CIPSTART link type error
- SerialESP8266wifi.h Listen to Incoming Message
- How configure SerialESP8266wifi.h as Client?
- Anomole
- Examples wont compile
- UDP
- Redeclaration of symbols When compiling
- Library Availability on Library Manager on Arduino IDE
- Error in downloading library HOT 2
- a
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from esp8266wifi.