Skip to content

Commit

Permalink
update cWifi class
Browse files Browse the repository at this point in the history
  • Loading branch information
hasenradball committed Dec 1, 2024
1 parent 85cea4f commit 714d2a7
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 21 deletions.
90 changes: 72 additions & 18 deletions lib/cWIFI/cWIFI.cpp
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
Projekt: wifi class wrapper for ESP8266 and ESP32
Microcontroller: ESP8266 / ESP32
Date: 18.11.2018
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 Down Expand Up @@ -218,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 @@ -231,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 @@ -247,21 +316,6 @@ bool Wifi::Wifi_AP_Start(void) {
return status;
}

/**
* @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 print wifi information like ssid, ip, gateway, etc..
*
Expand Down
27 changes: 25 additions & 2 deletions lib/cWIFI/cWIFI.h
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,35 @@ class Wifi {
wl_status_t Wifi_Status(void) const;
bool Wifi_Connect(bool static_ip = false);
bool Wifi_AP_Start(void);
bool Wifi_Stop(void);

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

#ifdef ESP8266
bool Wifi_Stop(void);

/**
* @brief wifi disconnect function
*
* @return true
* @return false
*/
bool Wifi_Disconnect() {return WiFi.disconnect()};
#endif

#ifdef ESP32
/**
* @brief wifi disconnect function
*
* @param setWifiOff set mode to WIFI_OFF
* @param eraseCredentials delete credentials
* @return true
* @return false
*/
bool Wifi_Disconnect(bool setWifiOff, bool eraseCredentials) {
return WiFi.disconnect(setWifiOff, eraseCredentials);
};
#endif
};

#endif
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 714d2a7

Please sign in to comment.