jnthas/Improv-WiFi-Library

ESP8266 compatibility

aypopa opened this issue · 7 comments

Hi, I like this library and would love to try it on my ESP8266s. From the documentation it seems it might be compatible, but unfortunately your example does not compile for Generic ESP8266 Module (tried 3.1.2 and 2.6.1), Arduino IDE 1.8.15. Is it compatible with ESP8266?

I am having the same problem. I have tried to compile with many ESP8266 and it doesn't work. For ESP32 compile okay, but in the docs it says it is possible to change the chip family to CF_ESP8266, but it doesn't seem to work.

I get the error:

Arduino:1.8.19 (Mac OS X), Board:"LOLIN(WEMOS) D1 R2 & mini, 80 MHz, Flash, Disabled (new aborts on oom), Disabled, All SSL ciphers (most compatible), 32KB cache + 32KB IRAM (balanced), Use pgm_read macros for IRAM/PROGMEM, 4MB (FS:2MB OTA:~1019KB), v2 Lower Memory, Disabled, None, Only Sketch, 921600"

/var/folders/my/x7wn15qs0v9cw7q47mhqxvr00000gn/T/arduino_modified_sketch_5600/SimpleWebServer.ino: In function 'void onImprovWiFiErrorCb(ImprovTypes::Error)':
SimpleWebServer:16:10: error: 'class WiFiServer' has no member named 'stop'
16 | server.stop();
| ^~~~
/var/folders/my/x7wn15qs0v9cw7q47mhqxvr00000gn/T/arduino_modified_sketch_5600/SimpleWebServer.ino: In function 'bool connectWifi(const char*, const char*)':
SimpleWebServer:29:14: error: invalid conversion from 'const char*' to 'char*' [-fpermissive]
29 | WiFi.begin(ssid, password);
| ^~~~
| |
| const char*
In file included from /var/folders/my/x7wn15qs0v9cw7q47mhqxvr00000gn/T/arduino_modified_sketch_5600/SimpleWebServer.ino:4:
/private/var/folders/my/x7wn15qs0v9cw7q47mhqxvr00000gn/T/AppTranslocation/694FC21A-04A5-4EE0-9BF7-B73090C281B8/d/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:79:21: note: initializing argument 1 of 'int WiFiClass::begin(char*, const char*)'
79 | int begin(char* ssid, const char passphrase);
| ~~~~~~^~~~
/var/folders/my/x7wn15qs0v9cw7q47mhqxvr00000gn/T/arduino_modified_sketch_5600/SimpleWebServer.ino: In function 'void setup()':
SimpleWebServer:44:8: error: 'class WiFiClass' has no member named 'mode'
44 | WiFi.mode(WIFI_STA);
| ^~~~
SimpleWebServer:44:13: error: 'WIFI_STA' was not declared in this scope
44 | WiFi.mode(WIFI_STA);
| ^~~~~~~~
/var/folders/my/x7wn15qs0v9cw7q47mhqxvr00000gn/T/arduino_modified_sketch_5600/SimpleWebServer.ino: In function 'void handleHttpRequest()':
SimpleWebServer:99:30: error: 'class EspClass' has no member named 'getChipModel'; did you mean 'getChipId'?
99 | client.println(ESP.getChipModel());
| ^~~~~~~~~~~~
| getChipId
SimpleWebServer:101:30: error: 'class EspClass' has no member named 'getChipCores'
101 | client.println(ESP.getChipCores());
| ^~~~~~~~~~~~
SimpleWebServer:103:30: error: 'class EspClass' has no member named 'getChipRevision'
103 | client.println(ESP.getChipRevision());
| ^~~~~~~~~~~~~~~
SimpleWebServer:111:42: error: no matching function for call to 'WiFiClass::macAddress()'
111 | client.println(WiFi.macAddress());
| ^
In file included from /var/folders/my/x7wn15qs0v9cw7q47mhqxvr00000gn/T/arduino_modified_sketch_5600/SimpleWebServer.ino:4:
/private/var/folders/my/x7wn15qs0v9cw7q47mhqxvr00000gn/T/AppTranslocation/694FC21A-04A5-4EE0-9BF7-B73090C281B8/d/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:137:14: note: candidate: 'uint8_t
WiFiClass::macAddress(uint8_t*)'
137 | uint8_t* macAddress(uint8_t* mac);
| ^~~~~~~~~~
/private/var/folders/my/x7wn15qs0v9cw7q47mhqxvr00000gn/T/AppTranslocation/694FC21A-04A5-4EE0-9BF7-B73090C281B8/d/Arduino.app/Contents/Java/libraries/WiFi/src/WiFi.h:137:14: note: candidate expects 1 argument, 0 provided
exit status 1
'class WiFiServer' has no member named 'stop'

Hey folks. I will test the lib with ESP8266 this weekend and let you all know about.

Hi, I played with the library a bit and made it work for me locally. Unfortunately, my ESP8266 mods most likely break the ESP32 so it will require a proper fix, but in essence:

  1. Naturally, <WiFi.h> is ESP32 library and needs to be replaced with <ESP8266WiFi.h>

  2. I am not sure about <Esp.h>, but the ESP.getChip... do not compile for me. I do not care about them so I was not investigating further. I just deleted.

  3. "WIFI_AUTH_OPEN" is an ESP32 flag, ESP8266 uses "ENC_TYPE_NONE" instead
    -> beyond this point the sketch was compiling, but the protocol did not work with ESP Web Tools yet.

  4. I added "0x0A" to the end of each response, otherwise the service did not react

  5. I removed the following condition:
    if (isConnected()) { setState(ImprovTypes::State::STATE_PROVISIONED); sendDeviceUrl(cmd.command); } else { setState(ImprovTypes::State::STATE_AUTHORIZED); }
    The service does not seem to catch-up if the ESP is not connected and the message is therefore not sent.

  6. I added following function for myself, feel free to adopt:
    void ImprovWiFi::handleSerialChar(char b) { if (parseImprovSerial(_position, b, _buffer)) { _buffer[_position++] = b; } else { _position = 0; } }
    I was already using Serial read in my sketch for other purposes, so the original handleSerial() would interfere big time.

-> At this stage all is working for me so far with the only remaining bug, my "fix" in 5 is causing the service to think that the ESP is connected to WiFi even if it is not, so a smarter fix is needed. EDIT: I no longer think it is caused by my edit, it looks like I was just handling the customConnectWiFiCallback wrong by immediately returning true;

hello I have a fork compiles on esp8266 and esp32 but I haven't test it yet feel free to test, one note is that I've used asyncwebserver
https://github.com/rjjrbatarao/Improv-WiFi-Library/tree/main

it works now on both esp8266 and esp32, it not a proper fix i've just added quick preprocessor handler to fix some compiler issues and crashes

Thank you @aypopa for the tips and @rjjrbatarao for the fix. I think I came with a similar one. The main branch is updated, could you test it please so that I can publish a new version on arduino library repository.

Guys, I'm going to close this issue and release a new version