Skip to content

ESP8266WifiMulti bugs #386

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
av1024 opened this issue Jun 5, 2015 · 3 comments
Closed

ESP8266WifiMulti bugs #386

av1024 opened this issue Jun 5, 2015 · 3 comments

Comments

@av1024
Copy link

av1024 commented Jun 5, 2015

As far as I know C, there is several bugs in ESP8266WiFiMulti::APlistAdd:

bool ESP8266WiFiMulti::APlistAdd(const char* ssid, const char *passphrase) {

    WifiAPlist_t newAP;

    //!!! check for NULL/empty ssid required (causes "malloc(0) error" on empty strings)
    //+++
    if (!ssid || !*ssid) return false

    newAP.ssid = (char*) malloc(strlen(ssid));  // !!! should be strlen+1 OR strdup(ssid)

    if(!newAP.ssid) {
        return false;
    }

    strcpy(newAP.ssid, ssid);

    if(passphrase && *passphrase != 0x00) {
        newAP.passphrase = (char*) malloc(strlen(passphrase));  // !!! should be strlen+1 OR strdup(passphrase)
    }

    // looks like never add SSID with empty password
    if(!newAP.passphrase) {
        free(newAP.ssid);
        return false;
    }

    strcpy(newAP.passphrase, passphrase);

    APlist.push_back(newAP);
    return true;
}

BTW, I think it is not good idea to rescan wifi points every time. run() freezes for several seconds if no valid SSID available

@Links2004
Copy link
Collaborator

fixed, if the freezes is good or bad is depends on the application.
have some ideas to run the scan in background but for this some changes on the ESP8266WiFiClass class are needed. for this i need some free time to test this out.

@av1024
Copy link
Author

av1024 commented Jun 5, 2015

Hmm...
154: if(!ssid || strlen(ssid) > 31: You still allow to pass empty SSID here

using strdup(ssid) instedad of strlen+malloc saves 16bytes per call for me and looks potentially a bit faster (http://www.vanheusden.com/misc/strdup/strdup_v_SlMalMemc.php)

About freezes: (as an idea) For now I wrote "alternate" version of wifiMulti - only cycle between added SSID's without scanning and RSSI analyzing. The simple use case is: two known AP's, for example at home and at work. So I do need only connect to known SSID, not to select th best ))

@Links2004
Copy link
Collaborator

the compare of time is for an x68 cpu. the implementation on the ESP is like (strlen + malloc + memcpy):

char* ICACHE_FLASH_ATTR strdup(const char *str) {

so faster i not think so, but it will save some bytes yes :)

yes you can try "blue forcing" the right AP. but you use case is much simpler the one i have.
I have 5 different WiFi on 3 different locations with multiple APs. so scanning ones if faster the try 5 times a may possible WiFi. The ESP do a scan internally be WiFi connect.

coding half sleeping is a bad idea

@igrr igrr closed this as completed in 078efcb Jun 5, 2015
igrr pushed a commit that referenced this issue Oct 29, 2015
igrr pushed a commit that referenced this issue Oct 29, 2015
use strdup to save some flash

#386 part 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants