Giter Club home page Giter Club logo

Comments (1)

flodmotorgrodan avatar flodmotorgrodan commented on August 16, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.