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); 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 fault->setVal(1); // set fault state
LOG1("Sensor %s update: FAULT\n",name); 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 #define I2C_ADD 0x48 // ICS Address to use for the Adafruit ADT7410
SpanPoint *mainDevice; 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() { void setup() {
@ -90,7 +90,7 @@ void setup() {
void loop() { void loop() {
if(millis()-timer>60000){ // only sample every 5 seconds if(millis()-timer>30000){ // only sample every 30 seconds
timer=millis(); timer=millis();
Wire.beginTransmission(I2C_ADD); // setup transmission Wire.beginTransmission(I2C_ADD); // setup transmission

View File

@ -60,8 +60,6 @@ void Span::begin(Category catID, const char *displayName, const char *hostNameBa
sprintf(this->category,"%d",(int)catID); sprintf(this->category,"%d",(int)catID);
SpanPoint::setAsHub(); 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 statusLED=new Blinker(statusDevice,autoOffLED); // create Status LED, even is statusDevice is NULL
@ -2183,6 +2181,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", 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); 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 init(); // initialize SpanPoint
peerInfo.channel=0; // 0 = matches current WiFi channel peerInfo.channel=0; // 0 = matches current WiFi channel
@ -2204,8 +2207,8 @@ void SpanPoint::init(const char *password){
if(initialized) if(initialized)
return; return;
if(WiFi.getMode()!=WIFI_AP_STA) if(WiFi.getMode()==WIFI_OFF)
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) WiFi.mode(WIFI_STA);
uint8_t hash[32]; uint8_t hash[32];
mbedtls_sha256_ret((const unsigned char *)password,strlen(password),hash,0); // produce 256-bit bit hash from password 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 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"); SpanPoint::setPassword("Hello Thert");
homeSpan.setLogLevel(1); 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)); 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"); 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 new SpanAccessory(); // Begin by creating a new Accessory using SpanAccessory(), which takes no arguments
@ -122,16 +123,16 @@ unsigned long alarmTime=0;
void loop(){ void loop(){
homeSpan.poll(); homeSpan.poll();
if(dev1->get(&message)) // if(dev1->get(&message))
Serial.printf("DEV1: '%s' %d %f %d\n",message.a,message.b,message.c,message.d); // Serial.printf("DEV1: '%s' %d %f %d\n",message.a,message.b,message.c,message.d);
if(dev2->get(&message)) // if(dev2->get(&message))
Serial.printf("DEV2: '%s' %d %f %d\n",message.a,message.b,message.c,message.d); // Serial.printf("DEV2: '%s' %d %f %d\n",message.a,message.b,message.c,message.d);
//
if(millis()-alarmTime>5000){ // if(millis()-alarmTime>5000){
alarmTime=millis(); // alarmTime=millis();
boolean success = dev2->send(&alarmTime); // boolean success = dev2->send(&alarmTime);
Serial.printf("Success = %d\n",success); // Serial.printf("Success = %d\n",success);
} // }
} // end of loop() } // end of loop()
@ -146,6 +147,8 @@ void myWiFiAP(){
void wifiEstablished(){ void wifiEstablished(){
Serial.print("IN CALLBACK FUNCTION\n\n"); Serial.print("IN CALLBACK FUNCTION\n\n");
Serial.printf("MODE = %d\n",WiFi.getMode());
} }
////////////////////////////////////// //////////////////////////////////////