Untitled
unknown
c_cpp
2 years ago
2.3 kB
4
Indexable
esp_sleep_enable_timer_wakeup(time_in_us); time_awoken = millis(); } void loop() { if(pServer->getConnectedCount()) { //Everything related to power management NimBLEService* pBatriSvc = pServer->getServiceByUUID(BATTERY_PWR_SRVI_UUID); if(pBatriSvc) { NimBLECharacteristic* pChr = pBatriSvc->getCharacteristic(BATTERY_PWR_VLTG_CHAR_UUID); log_i("%s","We got the Batri service"); int btriVoltage = 0; if(pChr) { //We don't want to communicate a negative value (?) if(btriVoltage == BATTERY_NOT_CONNECTED_CODE) { pChr->setValue("0"); } else { pChr->setValue(std::to_string(0)); } log_i("%s",CCIDDesc->getStringValue()); if(pChr->getSubscribedCount()>0) { pChr->notify(true); } } NimBLECharacteristic * pBtriWarnChar = pBatriSvc->getCharacteristic(BATTERY_PWR_WARN_CHAR_UUID); //We now check to see if we should warn the client of the low battery power if(pBtriWarnChar) { if(btriVoltage<BATTERY_THRESHOLD && btriVoltage != BATTERY_NOT_CONNECTED_CODE) { pBtriWarnChar->setValue("1"); pBtriWarnChar->notify(true); } else if (pBtriWarnChar->getValue() == "1") { pBtriWarnChar->setValue("0"); pBtriWarnChar->notify(true); } } } NimBLEService * pSWCSvc = pServer->getServiceByUUID(SWC_SRVI_UUID); if(pSWCSvc) { NimBLECharacteristic* pSWCReadChr = pSWCSvc->getCharacteristic(SWC_VWC_CHAR_UUID); if(pSWCReadChr->getSubscribedCount()>0) { pSWCReadChr->notify(0); } } Serial.println(millis() - time_awoken ); if(millis() - time_awoken > (60*1000)) { esp_deep_sleep_start(); }
Editor is loading...