Add support for WiFi long range mode (#3190)
* Add support for WiFi long range mode * Update WiFiGeneric.cpp
This commit is contained in:
parent
e50613622e
commit
0cdfb0b193
@ -47,7 +47,6 @@ extern "C" {
|
|||||||
|
|
||||||
#include "esp32-hal-log.h"
|
#include "esp32-hal-log.h"
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "sdkconfig.h"
|
#include "sdkconfig.h"
|
||||||
|
|
||||||
static xQueueHandle _network_event_queue;
|
static xQueueHandle _network_event_queue;
|
||||||
@ -133,24 +132,19 @@ static bool wifiLowLevelDeinit(){
|
|||||||
|
|
||||||
static bool _esp_wifi_started = false;
|
static bool _esp_wifi_started = false;
|
||||||
|
|
||||||
static bool espWiFiStart(bool persistent){
|
static bool espWiFiStart(){
|
||||||
if(_esp_wifi_started){
|
if(_esp_wifi_started){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(!wifiLowLevelInit(persistent)){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
esp_err_t err = esp_wifi_start();
|
esp_err_t err = esp_wifi_start();
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
log_e("esp_wifi_start %d", err);
|
log_e("esp_wifi_start %d", err);
|
||||||
wifiLowLevelDeinit();
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
_esp_wifi_started = true;
|
_esp_wifi_started = true;
|
||||||
system_event_t event;
|
system_event_t event;
|
||||||
event.event_id = SYSTEM_EVENT_WIFI_READY;
|
event.event_id = SYSTEM_EVENT_WIFI_READY;
|
||||||
WiFiGenericClass::_eventCallback(nullptr, &event);
|
WiFiGenericClass::_eventCallback(nullptr, &event);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -190,6 +184,7 @@ wifi_event_id_t WiFiEventCbList::current_id = 1;
|
|||||||
static std::vector<WiFiEventCbList_t> cbEventList;
|
static std::vector<WiFiEventCbList_t> cbEventList;
|
||||||
|
|
||||||
bool WiFiGenericClass::_persistent = true;
|
bool WiFiGenericClass::_persistent = true;
|
||||||
|
bool WiFiGenericClass::_long_range = false;
|
||||||
wifi_mode_t WiFiGenericClass::_forceSleepLastMode = WIFI_MODE_NULL;
|
wifi_mode_t WiFiGenericClass::_forceSleepLastMode = WIFI_MODE_NULL;
|
||||||
|
|
||||||
WiFiGenericClass::WiFiGenericClass()
|
WiFiGenericClass::WiFiGenericClass()
|
||||||
@ -471,6 +466,16 @@ void WiFiGenericClass::persistent(bool persistent)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* enable WiFi long range mode
|
||||||
|
* @param enable
|
||||||
|
*/
|
||||||
|
void WiFiGenericClass::enableLongRange(bool enable)
|
||||||
|
{
|
||||||
|
_long_range = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set new mode
|
* set new mode
|
||||||
* @param m WiFiMode_t
|
* @param m WiFiMode_t
|
||||||
@ -482,7 +487,7 @@ bool WiFiGenericClass::mode(wifi_mode_t m)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if(!cm && m){
|
if(!cm && m){
|
||||||
if(!espWiFiStart(_persistent)){
|
if(!wifiLowLevelInit(_persistent)){
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} else if(cm && !m){
|
} else if(cm && !m){
|
||||||
@ -495,6 +500,25 @@ bool WiFiGenericClass::mode(wifi_mode_t m)
|
|||||||
log_e("Could not set mode! %d", err);
|
log_e("Could not set mode! %d", err);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if(_long_range){
|
||||||
|
if(m & WIFI_MODE_STA){
|
||||||
|
err = esp_wifi_set_protocol(WIFI_IF_STA, WIFI_PROTOCOL_LR);
|
||||||
|
if(err != ESP_OK){
|
||||||
|
log_e("Could not enable long range on STA! %d", err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(m & WIFI_MODE_AP){
|
||||||
|
err = esp_wifi_set_protocol(WIFI_IF_AP, WIFI_PROTOCOL_LR);
|
||||||
|
if(err != ESP_OK){
|
||||||
|
log_e("Could not enable long range on AP! %d", err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!espWiFiStart()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -504,7 +528,7 @@ bool WiFiGenericClass::mode(wifi_mode_t m)
|
|||||||
*/
|
*/
|
||||||
wifi_mode_t WiFiGenericClass::getMode()
|
wifi_mode_t WiFiGenericClass::getMode()
|
||||||
{
|
{
|
||||||
if(!_esp_wifi_started){
|
if(!lowLevelInitDone){
|
||||||
return WIFI_MODE_NULL;
|
return WIFI_MODE_NULL;
|
||||||
}
|
}
|
||||||
wifi_mode_t mode;
|
wifi_mode_t mode;
|
||||||
|
@ -83,6 +83,7 @@ class WiFiGenericClass
|
|||||||
int32_t channel(void);
|
int32_t channel(void);
|
||||||
|
|
||||||
void persistent(bool persistent);
|
void persistent(bool persistent);
|
||||||
|
void enableLongRange(bool enable);
|
||||||
|
|
||||||
static bool mode(wifi_mode_t);
|
static bool mode(wifi_mode_t);
|
||||||
static wifi_mode_t getMode();
|
static wifi_mode_t getMode();
|
||||||
@ -100,6 +101,7 @@ class WiFiGenericClass
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
static bool _persistent;
|
static bool _persistent;
|
||||||
|
static bool _long_range;
|
||||||
static wifi_mode_t _forceSleepLastMode;
|
static wifi_mode_t _forceSleepLastMode;
|
||||||
|
|
||||||
static int setStatusBits(int bits);
|
static int setStatusBits(int bits);
|
||||||
|
Loading…
Reference in New Issue
Block a user