@ -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 ( m illis( ) - geiger_previousMillis > 60000 ) {
if ( rtcM illis( ) - geiger_previousMillis > 60000 ) {
sd . cpm = geiger_counts * 60000 / ( m illis( ) - geiger_previousMillis ) ;
sd . cpm = geiger_counts * 60000 / ( rtcM illis( ) - geiger_previousMillis ) ;
geiger_previousMillis = m illis( ) ;
geiger_previousMillis = rtcM illis( ) ;
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
& & ( m illis( ) - last_dhcp < dhcp_interval )
& & ( rtcM illis( ) - 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 = m illis( ) ;
last_dhcp = rtcM illis( ) ;
}
}
sd . rssi = WiFi . RSSI ( ) ;
sd . rssi = WiFi . RSSI ( ) ;
@ -367,7 +376,7 @@ void ICACHE_FLASH_ATTR sendValues() {
}
}
loop_count + + ;
loop_count + + ;
last_wifi_activity = m illis( ) ;
last_wifi_activity = rtcM illis( ) ;
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", m illis() - last_wifi_activity);
//DEBUG_MSG("%d\n", rtcM illis() - last_wifi_activity);
sendValues ( ) ;
sendValues ( ) ;
delay ( postingInterval ) ;
delay ( postingInterval ) ;
}
}