Browse Source

replace millis()

main
Hendrik Langer 7 years ago
parent
commit
55aad5f16b
  1. 23
      src/main.cpp

23
src/main.cpp

@ -111,6 +111,15 @@ struct __attribute__((packed)) SENSOR_DATA {
float rssi; float rssi;
} sd; } sd;
static uint32_t cal = system_rtc_clock_cali_proc(); // WARNING: UPDATING THIS WILL MAKE THE rtcMillis() RETURN A LOWER VALUE THEN BEFORE, EVEN IF TIME PASSED, BREAKING INTERVAL CHECKS!
unsigned long rtcMillis() {
uint64_t rtc_t = system_get_rtc_time();
// uint32_t timemicrosec = rtc_t*((uint64) ((cal * 1000) >> 12));
// Serial.printf("cal: %d.%d \r\n", ((cal*1000)>>12)/1000, ((cal*1000)>>12)%1000 );
// Serial.printf("cal: %u\n", cal);
return ((uint64_t)(rtc_t*(uint64_t)cal) >> 12)/1000;
}
/* /*
void sendESPNOW() { void sendESPNOW() {
// unsigned long espnowmillis = millis(); // unsigned long espnowmillis = millis();
@ -170,9 +179,9 @@ void ICACHE_FLASH_ATTR sendValues() {
// sds.sleep(); // sds.sleep();
if (millis() - geiger_previousMillis > 60000) { if (rtcMillis() - geiger_previousMillis > 60000) {
sd.cpm = geiger_counts * 60000 / (millis() - geiger_previousMillis); sd.cpm = geiger_counts * 60000 / (rtcMillis() - geiger_previousMillis);
geiger_previousMillis = millis(); geiger_previousMillis = rtcMillis();
geiger_counts = 0; geiger_counts = 0;
geigeraverage.addValue(sd.cpm); geigeraverage.addValue(sd.cpm);
} }
@ -255,7 +264,7 @@ void ICACHE_FLASH_ATTR sendValues() {
if ( ip != INADDR_NONE && dns != INADDR_NONE && gateway != INADDR_NONE && subnet != INADDR_NONE if ( ip != INADDR_NONE && dns != INADDR_NONE && gateway != INADDR_NONE && subnet != INADDR_NONE
&& ((ip[0] == 192 && ip[1] == 168) || (ip[0] == 172 && ip[1] == 16)) && ((ip[0] == 192 && ip[1] == 168) || (ip[0] == 172 && ip[1] == 16))
&& strlen(ssid) > 0 && strlen(password) > 0 && strlen(ssid) > 0 && strlen(password) > 0
&& (millis() - last_dhcp < dhcp_interval) && (rtcMillis() - last_dhcp < dhcp_interval)
) { ) {
DEBUG_MSG("static ip\n"); DEBUG_MSG("static ip\n");
@ -303,7 +312,7 @@ void ICACHE_FLASH_ATTR sendValues() {
subnet = WiFi.subnetMask(); subnet = WiFi.subnetMask();
strncpy(ssid, WiFi.SSID().c_str(), 64); strncpy(ssid, WiFi.SSID().c_str(), 64);
strncpy(password, WiFi.psk().c_str(), 64); strncpy(password, WiFi.psk().c_str(), 64);
last_dhcp = millis(); last_dhcp = rtcMillis();
} }
sd.rssi = WiFi.RSSI(); sd.rssi = WiFi.RSSI();
@ -367,7 +376,7 @@ void ICACHE_FLASH_ATTR sendValues() {
} }
loop_count++; loop_count++;
last_wifi_activity = millis(); last_wifi_activity = rtcMillis();
WiFi.disconnect(); WiFi.disconnect();
WiFi.mode(WIFI_OFF); WiFi.mode(WIFI_OFF);
WiFi.forceSleepBegin(); WiFi.forceSleepBegin();
@ -408,7 +417,7 @@ void setup() {
} }
void loop() { void loop() {
//DEBUG_MSG("%d\n", millis() - last_wifi_activity); //DEBUG_MSG("%d\n", rtcMillis() - last_wifi_activity);
sendValues(); sendValues();
delay(postingInterval); delay(postingInterval);
} }

Loading…
Cancel
Save