From be0b027f1910b624475ab0f002a6440d215ae765 Mon Sep 17 00:00:00 2001 From: sametflo Date: Sat, 28 Mar 2020 17:38:10 +0100 Subject: [PATCH] ESP32 compatibility and some fixes --- CHANGELOG.md | 6 +++++ README.md | 4 ++-- library.json | 6 ++--- library.properties | 6 ++--- src/JustWifi.cpp | 60 ++++++++++++++++++++++++++++++++++++---------- src/JustWifi.h | 15 ++++++++---- 6 files changed, 72 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 806acde..b024504 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [2.0.3] 2020-03-26 +### Added +- ESP32 compatibility +### Fixed +- STA+AP mode simultanously + ## [2.0.2] 2018-09-13 ### Fixed - Check NO_EXTRA_4K_HEAP flag for WPS support on SDK 2.4.2 diff --git a/README.md b/README.md index ec8cab4..04ca178 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # JustWifi -JustWifi is a WIFI Manager library for the [Arduino Core for ESP8266][2]. The goal of the library is to manage ONLY the WIFI connection (no webserver, no mDNS,...) from code and in a reliable and flexible way. +JustWifi is a WIFI Manager library for the [Arduino Core for ESP8266 and ESP32][2]. The goal of the library is to manage ONLY the WIFI connection (no webserver, no mDNS,...) from code and in a reliable and flexible way. -[![version](https://img.shields.io/badge/version-2.0.2-brightgreen.svg)](CHANGELOG.md) +[![version](https://img.shields.io/badge/version-2.0.3-brightgreen.svg)](CHANGELOG.md) [![travis](https://travis-ci.org/xoseperez/justwifi.svg?branch=master)](https://travis-ci.org/xoseperez/justwifi) [![codacy](https://img.shields.io/codacy/grade/4ccbea0317c4415eb2d1c562feced407/master.svg)](https://www.codacy.com/app/xoseperez/justwifi/dashboard) [![license](https://img.shields.io/github/license/xoseperez/justwifi.svg)](LICENSE) diff --git a/library.json b/library.json index 8e26038..a35471b 100644 --- a/library.json +++ b/library.json @@ -1,16 +1,16 @@ { "name": "JustWifi", "keywords": "wifi,manager,scan,wps,smartconfig", - "description": "Wifi Manager for ESP8266, supports multiple wifi networks, scan for strongest signal, WPS and SmartConfig", + "description": "Wifi Manager for ESP8266 and ESP32, supports multiple wifi networks, scan for strongest signal, WPS and SmartConfig", "repository": { "type": "git", "url": "https://github.com/xoseperez/justwifi.git" }, - "version": "2.0.2", + "version": "2.0.3", "license": "LGPL-3.0", "exclude": "tests", "frameworks": "arduino", - "platforms": "espressif8266", + "platforms": ["espressif8266", "espressif32"], "authors": { "name": "Xose Perez", "email": "xose.perez@gmail.com", diff --git a/library.properties b/library.properties index 1b80a91..93c7de3 100644 --- a/library.properties +++ b/library.properties @@ -1,10 +1,10 @@ name=JustWifi -version=2.0.2 +version=2.0.3 author=Xose Pérez maintainer=Xose Pérez -sentence=Wifi Manager for ESP8266 +sentence=Wifi Manager for ESP8266 and ESP32 paragraph=Supports multiple wifi networks, scan for strongest signal, WPS and SmartConfig category=Communication url=https://github.com/xoseperez/justwifi.git -architectures=esp8266 +architectures=esp8266,esp32 includes=JustWifi.h diff --git a/src/JustWifi.cpp b/src/JustWifi.cpp index d52f826..32759e9 100644 --- a/src/JustWifi.cpp +++ b/src/JustWifi.cpp @@ -47,9 +47,17 @@ void _jw_wps_status_cb(wps_cb_status status) { JustWifi::JustWifi() { _softap.ssid = NULL; _timeout = 0; + + uint32_t chip_id; + #if defined(ARDUINO_ARCH_ESP32) + chip_id = ESP.getEfuseMac() & 0xFFFFFFFF; + #else + chip_id = ESP.getChipId(); + #endif + snprintf_P(_hostname, sizeof(_hostname), PSTR("ESP-%06X"), chip_id); + WiFi.enableAP(false); WiFi.enableSTA(false); - snprintf_P(_hostname, sizeof(_hostname), PSTR("ESP_%06X"), ESP.getChipId()); } JustWifi::~JustWifi() { @@ -126,11 +134,20 @@ uint8_t JustWifi::_sortByRSSI() { } String JustWifi::_encodingString(uint8_t security) { - if (security == ENC_TYPE_WEP) return String("WEP "); - if (security == ENC_TYPE_TKIP) return String("WPA "); - if (security == ENC_TYPE_CCMP) return String("WPA2"); - if (security == ENC_TYPE_AUTO) return String("AUTO"); - return String("OPEN"); + #if defined(ARDUINO_ARCH_ESP32) + if (security == WIFI_AUTH_WEP) return String("WEP "); + if (security == WIFI_AUTH_WPA_PSK) return String("WPA "); + if (security == WIFI_AUTH_WPA2_PSK) return String("WPA2 "); + if (security == WIFI_AUTH_WPA_WPA2_PSK) return String("WPA* "); + if (security == WIFI_AUTH_WPA2_ENTERPRISE) return String("WPA2E"); + if (security == WIFI_AUTH_MAX) return String("MAX "); + #else + if (security == ENC_TYPE_WEP) return String("WEP "); + if (security == ENC_TYPE_TKIP) return String("WPA "); + if (security == ENC_TYPE_CCMP) return String("WPA2 "); + if (security == ENC_TYPE_AUTO) return String("AUTO "); + #endif + return String("OPEN "); } uint8_t JustWifi::_populate(uint8_t networkCount) { @@ -148,12 +165,16 @@ uint8_t JustWifi::_populate(uint8_t networkCount) { uint8_t sec_scan; uint8_t* BSSID_scan; int32_t chan_scan; - bool hidden_scan; // Populate defined networks with scan data for (int8_t i = 0; i < networkCount; ++i) { - WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan, hidden_scan); + #if defined(ARDUINO_ARCH_ESP32) + WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan); + #else + bool hidden_scan; + WiFi.getNetworkInfo(i, ssid_scan, sec_scan, rssi_scan, BSSID_scan, chan_scan, hidden_scan); + #endif bool known = false; @@ -164,7 +185,11 @@ uint8_t JustWifi::_populate(uint8_t networkCount) { if (ssid_scan.equals(entry->ssid)) { // Check security - if ((sec_scan != ENC_TYPE_NONE) && (entry->pass == NULL)) continue; + #if defined(ARDUINO_ARCH_ESP32) + if ((sec_scan != WIFI_AUTH_OPEN) && (entry->pass == NULL)) continue; + #else + if ((sec_scan != ENC_TYPE_NONE) && (entry->pass == NULL)) continue; + #endif // In case of several networks with the same SSID // we want to get the one with the best RSSI @@ -226,7 +251,11 @@ uint8_t JustWifi::_doSTA(uint8_t id) { WiFi.persistent(false); _disable(); WiFi.enableSTA(true); - WiFi.hostname(_hostname); + #if defined(ARDUINO_ARCH_ESP32) + WiFi.setHostname(_hostname); + #else + WiFi.hostname(_hostname); + #endif // Configure static options if (!entry.dhcp) { @@ -296,6 +325,8 @@ uint8_t JustWifi::_doSTA(uint8_t id) { // Connected? if (WiFi.status() == WL_CONNECTED) { + WiFi.enableAP(false); + // Autoconnect only if DHCP, since it doesn't store static IP data WiFi.setAutoConnect(entry.dhcp); @@ -626,6 +657,7 @@ void JustWifi::_machine() { // --------------------------------------------------------------------- case STATE_FALLBACK: + WiFi.enableSTA(false); if (!_ap_connected & _ap_fallback_enabled) _doAP(); _timeout = millis(); _state = STATE_IDLE; @@ -847,7 +879,9 @@ void JustWifi::turnOff() { WiFi.disconnect(); WiFi.enableAP(false); WiFi.enableSTA(false); - WiFi.forceSleepBegin(); + #if defined(ARDUINO_ARCH_ESP8266) + WiFi.forceSleepBegin(); + #endif delay(1); _doCallback(MESSAGE_TURNING_OFF); _sta_enabled = false; @@ -855,7 +889,9 @@ void JustWifi::turnOff() { } void JustWifi::turnOn() { - WiFi.forceSleepWake(); + #if defined(ARDUINO_ARCH_ESP8266) + WiFi.forceSleepWake(); + #endif delay(1); setReconnectTimeout(0); _doCallback(MESSAGE_TURNING_ON); diff --git a/src/JustWifi.h b/src/JustWifi.h index 2fa190a..577f01c 100644 --- a/src/JustWifi.h +++ b/src/JustWifi.h @@ -26,16 +26,21 @@ along with the JustWifi library. If not, see . #include #include +#if defined(ARDUINO_ARCH_ESP32) +#include +#elif defined(ARDUINO_ARCH_ESP8266) #include +extern "C" { + #include "user_interface.h" +} +#else +#error "Non supported architecture!" +#endif #ifdef JUSTWIFI_ENABLE_ENTERPRISE #include "wpa2_enterprise.h" #endif -extern "C" { - #include "user_interface.h" -} - // Check NO_EXTRA_4K_HEAP build flag in SDK 2.4.2 #include #if defined(JUSTWIFI_ENABLE_WPS) && defined(ARDUINO_ESP8266_RELEASE_2_4_2) && not defined(NO_EXTRA_4K_HEAP) @@ -221,4 +226,4 @@ class JustWifi { extern JustWifi jw; -#endif +#endif \ No newline at end of file