Skip to content

Commit

Permalink
update cWifi library
Browse files Browse the repository at this point in the history
  • Loading branch information
hasenradball committed Dec 1, 2024
1 parent c17b245 commit b5c31b6
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 28 deletions.
96 changes: 71 additions & 25 deletions lib/cWIFI/cWIFI.cpp
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Microcontroller: ESP8266 / ESP32
Date: 27.11.2024
Issuer: Frank Häfele
*/

#include "cWIFI.h"
Expand Down Expand Up @@ -177,6 +179,21 @@ bool Wifi::Wifi_Connect(bool static_ip) {
return false;
}

#ifdef ESP8266
/**
* @brief set wifi to mode WIFI_OFF
*
* @return true
* @return false
*/
bool Wifi::Wifi_Stop(void) {
bool status {WiFi.mode(WIFI_OFF)};
DBG__PRINT("WiFi mode set to WIFI_OFF: ", status);
while (WiFi.status() != WL_DISCONNECTED) {
yield();
}
return status;
}

/**
* @brief gets the actual wifi status
Expand All @@ -187,7 +204,6 @@ wl_status_t Wifi::Wifi_Status(void) const {
// keep in mind
/*
WL_NO_SHIELD = 255, // for compatibility with WiFi Shield library
WL_STOPPED = 254, // ESP32
WL_IDLE_STATUS = 0,
WL_NO_SSID_AVAIL = 1,
WL_SCAN_COMPLETED = 2,
Expand All @@ -201,11 +217,6 @@ wl_status_t Wifi::Wifi_Status(void) const {
if (status == WL_NO_SHIELD) {
DBG__PRINT(F("\n WiFI.status = NO_SHIELD"));
}
#ifdef ESP32
else if (status == WL_STOPPED) {
DBG__PRINT(F("\n WiFI.status = WL_STOPPED"));
}
#endif
else if (status == WL_IDLE_STATUS) {
DBG__PRINT(F("\n WiFI.status = IDLE_STATUS"));
}
Expand All @@ -224,11 +235,9 @@ wl_status_t Wifi::Wifi_Status(void) const {
else if (status == WL_CONNECTION_LOST) {
DBG__PRINT(F("\n WiFI.status = CONNECTION_LOST"));
}
#ifndef ESP32
else if (status == WL_WRONG_PASSWORD) {
DBG__PRINT(F("\n WiFI.status = WRONG_PASSWORD"));
}
#endif
else if (status == WL_DISCONNECTED) {
DBG__PRINT(F("\n WiFI.status = DISCONNECTED"));
}
Expand All @@ -237,7 +246,61 @@ wl_status_t Wifi::Wifi_Status(void) const {
}
return status;
}
#endif

#ifdef ESP32
/**
* @brief gets the actual wifi status
*
* @return wl_status_t
*/
wl_status_t Wifi::Wifi_Status(void) const {
// keep in mind
/*
WL_NO_SHIELD = 255, // for compatibility with WiFi Shield library
WL_NO_STOPPED = 254,
WL_IDLE_STATUS = 0,
WL_NO_SSID_AVAIL = 1,
WL_SCAN_COMPLETED = 2,
WL_CONNECTED = 3,
WL_CONNECT_FAILED = 4,
WL_CONNECTION_LOST = 5,
WL_DISCONNECTED = 6
*/
wl_status_t status = WiFi.status();
if (status == WL_NO_SHIELD) {
DBG__PRINT(F("\n WiFI.status = NO_SHIELD"));
}
else if (status == WL_STOPPED) {
DBG__PRINT(F("\n WiFI.status = IDLE_STOPPED"));
}
else if (status == WL_IDLE_STATUS) {
DBG__PRINT(F("\n WiFI.status = IDLE_STATUS"));
}
else if (status == WL_NO_SSID_AVAIL) {
DBG__PRINT(F("\n WiFI.status = NO_SSID_AVAIL"));
}
else if (status == WL_SCAN_COMPLETED) {
DBG__PRINT(F("\n WiFI.status = SCAN_COMPLETED"));
}
else if (status == WL_CONNECTED) {
DBG__PRINT(F("\n WiFI.status = CONNECTED"));
}
else if (status == WL_CONNECT_FAILED) {
DBG__PRINT(F("\n WiFI.status = CONNECT_FAILED"));
}
else if (status == WL_CONNECTION_LOST) {
DBG__PRINT(F("\n WiFI.status = CONNECTION_LOST"));
}
else if (status == WL_DISCONNECTED) {
DBG__PRINT(F("\n WiFI.status = DISCONNECTED"));
}
else {
DBG__PRINT(F("\n No appropriate Status available!"));
}
return status;
}
#endif

/**
* @brief start of wifi access point
Expand All @@ -253,23 +316,6 @@ bool Wifi::Wifi_AP_Start(void) {
return status;
}

#ifdef ESP8266
/**
* @brief set wifi to mode WIFI_OFF
*
* @return true
* @return false
*/
bool Wifi::Wifi_Stop(void) {
bool status {WiFi.mode(WIFI_OFF)};
DBG__PRINT("WiFi mode set to WIFI_OFF: ", status);
while (WiFi.status() != WL_DISCONNECTED) {
yield();
}
return status;
}
#endif

/**
* @brief print wifi information like ssid, ip, gateway, etc..
*
Expand Down
5 changes: 3 additions & 2 deletions lib/cWIFI/cWIFI.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,13 @@ class Wifi {
wl_status_t Wifi_Status(void) const;
bool Wifi_Connect(bool static_ip = false);
bool Wifi_AP_Start(void);

bool IsConnected(void) const {return WiFi.isConnected();};
int32_t Wifi_rssi(void) const {return WiFi.RSSI();};

#ifdef ESP8266
bool Wifi_Stop(void);

/**
* @brief wifi disconnect function
*
Expand All @@ -60,7 +61,7 @@ class Wifi {
* @return true
* @return false
*/
bool Wifi_Disconnect(bool setWifiOff = false, bool eraseCredentials = false) {
bool Wifi_Disconnect(bool setWifiOff, bool eraseCredentials) {
return WiFi.disconnect(setWifiOff, eraseCredentials);
};
#endif
Expand Down
2 changes: 1 addition & 1 deletion lib/cWIFI/library.json
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cWIFI",
"version": "2.3.8",
"version": "2.3.9",
"description": "class for using WIFI functions with ESP8266 and ESP32",
"keywords": ["esp8266wifi", "wifi", "esp32"],
"authors":
Expand Down

0 comments on commit b5c31b6

Please sign in to comment.