Updated SpanPoint so that WiFi_AP_STA is only used if receiveSize>0

Next up: explore power-reducing modes and sleep modes for remote sensors to extend battery life.
This commit is contained in:
Gregg 2022-10-03 22:04:51 -05:00
parent 0d5d4a0ca0
commit 2d411bab82
4 changed files with 25 additions and 19 deletions

View File

@ -72,7 +72,7 @@ struct RemoteTempSensor : Service::TemperatureSensor {
LOG1("Sensor %s update: Temperature=%0.2f\n",name,temperature*9/5+32);
} else if(remoteTemp->time()>120000 && !fault->getVal()){ // else if it has been a while since last update (60 seconds), and there is no current fault
} else if(remoteTemp->time()>60000 && !fault->getVal()){ // else if it has been a while since last update (60 seconds), and there is no current fault
fault->setVal(1); // set fault state
LOG1("Sensor %s update: FAULT\n",name);
}

View File

@ -58,7 +58,7 @@
#define I2C_ADD 0x48 // ICS Address to use for the Adafruit ADT7410
SpanPoint *mainDevice;
uint32_t timer=0; // keep track of time since last update
uint32_t timer=-30000; // keep track of time since last update
void setup() {
@ -90,7 +90,7 @@ void setup() {
void loop() {
if(millis()-timer>60000){ // only sample every 5 seconds
if(millis()-timer>30000){ // only sample every 30 seconds
timer=millis();
Wire.beginTransmission(I2C_ADD); // setup transmission

View File

@ -61,8 +61,6 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
SpanPoint::setAsHub();
WiFi.mode(WIFI_AP_STA); // set mode to mixed AP/STA. This does not start any servers, just configures the WiFi radio to ensure it does not sleep (required for ESP-NOW)
statusLED=new Blinker(statusDevice,autoOffLED); // create Status LED, even is statusDevice is NULL
esp_task_wdt_delete(xTaskGetIdleTaskHandleForCPU(0)); // required to avoid watchdog timeout messages from ESP32-C3
@ -2184,6 +2182,11 @@ SpanPoint::SpanPoint(const char *macAddress, int sendSize, int receiveSize, int
Serial.printf("SpanPoint: Created link to device with MAC Address %02X:%02X:%02X:%02X:%02X:%02X. Send size=%d bytes, Receive size=%d bytes with queue depth=%d.\n",
peerInfo.peer_addr[0],peerInfo.peer_addr[1],peerInfo.peer_addr[2],peerInfo.peer_addr[3],peerInfo.peer_addr[4],peerInfo.peer_addr[5],sendSize,receiveSize,queueDepth);
if(receiveSize>0)
WiFi.mode(WIFI_AP_STA);
else if(WiFi.getMode()==WIFI_OFF)
WiFi.mode(WIFI_STA);
init(); // initialize SpanPoint
peerInfo.channel=0; // 0 = matches current WiFi channel
peerInfo.ifidx=WIFI_IF_STA; // must specify interface
@ -2204,8 +2207,8 @@ void SpanPoint::init(const char *password){
if(initialized)
return;
if(WiFi.getMode()!=WIFI_AP_STA)
WiFi.mode(WIFI_AP_STA); // set mode to mixed AP/STA. This does not start any servers, just configures the WiFi radio to ensure it does not sleep (required for ESP-NOW)
if(WiFi.getMode()==WIFI_OFF)
WiFi.mode(WIFI_STA);
uint8_t hash[32];
mbedtls_sha256_ret((const unsigned char *)password,strlen(password),hash,0); // produce 256-bit bit hash from password

View File

@ -52,16 +52,17 @@ void setup() {
homeSpan.enableWebLog(10,"pool.ntp.org","UTC","myLog"); // creates a web log on the URL /HomeSpan-[DEVICE-ID].local:[TCP-PORT]/myLog
SpanPoint::setChannelMask(1<<13);
SpanPoint::setPassword("Hello Thert");
homeSpan.setLogLevel(1);
dev1=new SpanPoint("AC:67:B2:77:42:20",sizeof(int),0);
dev2=new SpanPoint("7C:DF:A1:61:E4:A8",sizeof(int),sizeof(message_t));
dev1=new SpanPoint("AC:67:B2:77:42:20",sizeof(int),0);
homeSpan.begin(Category::Lighting,"HomeSpan Lamp Server","homespan");
SpanPoint::setChannelMask(1<<13);
new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments
@ -122,16 +123,16 @@ unsigned long alarmTime=0;
void loop(){
homeSpan.poll();
if(dev1->get(&message))
Serial.printf("DEV1: '%s' %d %f %d\n",message.a,message.b,message.c,message.d);
if(dev2->get(&message))
Serial.printf("DEV2: '%s' %d %f %d\n",message.a,message.b,message.c,message.d);
if(millis()-alarmTime>5000){
alarmTime=millis();
boolean success = dev2->send(&alarmTime);
Serial.printf("Success = %d\n",success);
}
// if(dev1->get(&message))
// Serial.printf("DEV1: '%s' %d %f %d\n",message.a,message.b,message.c,message.d);
// if(dev2->get(&message))
// Serial.printf("DEV2: '%s' %d %f %d\n",message.a,message.b,message.c,message.d);
//
// if(millis()-alarmTime>5000){
// alarmTime=millis();
// boolean success = dev2->send(&alarmTime);
// Serial.printf("Success = %d\n",success);
// }
} // end of loop()
@ -146,6 +147,8 @@ void myWiFiAP(){
void wifiEstablished(){
Serial.print("IN CALLBACK FUNCTION\n\n");
Serial.printf("MODE = %d\n",WiFi.getMode());
}
//////////////////////////////////////