Started development of ESP-NOW
Also, added WiFi.begin("none") to make sure all WiFi data is erased when requested.
This commit is contained in:
parent
8975ec9922
commit
4a4a5f8a6b
|
|
@ -34,6 +34,7 @@
|
|||
#include <esp_task_wdt.h>
|
||||
#include <esp_sntp.h>
|
||||
#include <esp_ota_ops.h>
|
||||
#include <esp_now.h>
|
||||
|
||||
#include "HomeSpan.h"
|
||||
#include "HAP.h"
|
||||
|
|
@ -138,6 +139,12 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
|
|||
|
||||
Serial.printf("\nPartition: %s",esp_ota_get_running_partition()->label);
|
||||
|
||||
if(espNowEnabled){
|
||||
WiFi.mode(WIFI_AP_STA); // set mode to mixed AP/STA. AP mode will not be started, but WiFi will be properly configured for use with ESP-NOW
|
||||
esp_now_init(); // initialize ESP NOW
|
||||
Serial.print("\nESP-NOW: ENABLED");
|
||||
}
|
||||
|
||||
Serial.print("\n\nDevice Name: ");
|
||||
Serial.print(displayName);
|
||||
Serial.print("\n\n");
|
||||
|
|
@ -440,7 +447,8 @@ void Span::checkConnect(){
|
|||
|
||||
connected++;
|
||||
|
||||
addWebLog(true,"WiFi Connected! IP Address = %s\n",WiFi.localIP().toString().c_str());
|
||||
addWebLog(true,"WiFi Connected! IP Address = %s",WiFi.localIP().toString().c_str());
|
||||
Serial.printf("MAC Address = %s, Channel = %d\n",WiFi.macAddress().c_str(),WiFi.channel());
|
||||
|
||||
if(connected>1) // Do not initialize everything below if this is only a reconnect
|
||||
return;
|
||||
|
|
@ -825,6 +833,7 @@ void Span::processSerialCommand(const char *c){
|
|||
statusLED->off();
|
||||
nvs_erase_all(wifiNVS);
|
||||
nvs_commit(wifiNVS);
|
||||
WiFi.begin("none");
|
||||
Serial.print("\n*** WiFi Credentials ERASED! Re-starting...\n\n");
|
||||
delay(1000);
|
||||
ESP.restart(); // re-start device
|
||||
|
|
@ -870,6 +879,7 @@ void Span::processSerialCommand(const char *c){
|
|||
nvs_commit(charNVS);
|
||||
nvs_erase_all(otaNVS);
|
||||
nvs_commit(otaNVS);
|
||||
WiFi.begin("none");
|
||||
Serial.print("\n*** FACTORY RESET! Restarting...\n\n");
|
||||
delay(1000);
|
||||
ESP.restart();
|
||||
|
|
|
|||
|
|
@ -185,6 +185,7 @@ class Span{
|
|||
char pairingCodeCommand[12]=""; // user-specified Pairing Code - only needed if Pairing Setup Code is specified in sketch using setPairingCode()
|
||||
String lastClientIP="0.0.0.0"; // IP address of last client accessing device through encrypted channel
|
||||
boolean newCode; // flag indicating new application code has been loaded (based on keeping track of app SHA256)
|
||||
boolean espNowEnabled=false; // flag indicating if ESP-NOW is enabled
|
||||
|
||||
int connected=0; // WiFi connection status (increments upon each connect and disconnect)
|
||||
unsigned long waitTime=60000; // time to wait (in milliseconds) between WiFi connection attempts
|
||||
|
|
@ -283,6 +284,7 @@ class Span{
|
|||
void setApFunction(void (*f)()){apFunction=f;} // sets an optional user-defined function to call when activating the WiFi Access Point
|
||||
void enableAutoStartAP(){autoStartAPEnabled=true;} // enables auto start-up of Access Point when WiFi Credentials not found
|
||||
void setWifiCredentials(const char *ssid, const char *pwd); // sets WiFi Credentials
|
||||
void enableEspNOW(){espNowEnabled=true;}; // enables ESP-NOW
|
||||
|
||||
void setPairingCode(const char *s){sprintf(pairingCodeCommand,"S %9s",s);} // sets the Pairing Code - use is NOT recommended. Use 'S' from CLI instead
|
||||
void deleteStoredValues(){processSerialCommand("V");} // deletes stored Characteristic values from NVS
|
||||
|
|
|
|||
Loading…
Reference in New Issue