Skip to content
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

ESP32 compatibility and some fixes #20

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
6 changes: 3 additions & 3 deletions library.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
Expand Down
6 changes: 3 additions & 3 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name=JustWifi
version=2.0.2
version=2.0.3
author=Xose Pérez <[email protected]>
maintainer=Xose Pérez <[email protected]>
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
60 changes: 48 additions & 12 deletions src/JustWifi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;

Expand All @@ -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
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -847,15 +879,19 @@ 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;
_state = STATE_IDLE;
}

void JustWifi::turnOn() {
WiFi.forceSleepWake();
#if defined(ARDUINO_ARCH_ESP8266)
WiFi.forceSleepWake();
#endif
delay(1);
setReconnectTimeout(0);
_doCallback(MESSAGE_TURNING_ON);
Expand Down
15 changes: 10 additions & 5 deletions src/JustWifi.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,21 @@ along with the JustWifi library. If not, see <http://www.gnu.org/licenses/>.

#include <functional>
#include <vector>
#if defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#elif defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
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 <core_version.h>
#if defined(JUSTWIFI_ENABLE_WPS) && defined(ARDUINO_ESP8266_RELEASE_2_4_2) && not defined(NO_EXTRA_4K_HEAP)
Expand Down Expand Up @@ -221,4 +226,4 @@ class JustWifi {

extern JustWifi jw;

#endif
#endif