diff --git a/src/main.cpp b/src/main.cpp index 6249282..9d5d230 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -91,6 +91,7 @@ Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10085); DHT dht(DHT22_PIN, DHTTYPE); SDS011 sds; volatile unsigned long geiger_counts = 0; +unsigned long geiger_previousMillis; unsigned long last_wifi_activity = 0; unsigned long last_dhcp = 0; IPAddress ip, dns, gateway, subnet; @@ -169,8 +170,13 @@ void ICACHE_FLASH_ATTR sendValues() { // sds.sleep(); - sd.radioactivity = -1; - sd.cpm = geigeraverage.getAverage()*10; + if (millis() - geiger_previousMillis > 60000) { + sd.cpm = geiger_counts * 60000 / (millis() - geiger_previousMillis); + geiger_previousMillis = millis(); + geiger_counts = 0; + geigeraverage.addValue(sd.cpm); + } + //geiger_runningaverage = geigeraverage.getAverage()*10; float constexpr own_cpm = OWN_BACKGROUND_CPS * 60; sd.radioactivity = (sd.cpm - own_cpm) * CONV_FACTOR; @@ -374,13 +380,6 @@ void ICACHE_RAM_ATTR ISR_geiger_impulse() { geiger_counts++; } -// will be called every 6 seconds -void timerCallback(void *pArg) { - //DEBUG_MSG("running average counts: %d average: %6.2f\n", geiger_counts, geigeraverage.getAverage()); - geigeraverage.addValue(geiger_counts); - geiger_counts = 0; -} - void setup() { #ifdef USERDEBUG @@ -404,9 +403,6 @@ void setup() { attachInterrupt(digitalPinToInterrupt(GEIGER_PIN), ISR_geiger_impulse, FALLING); geigeraverage.clear(); - geigeraverage.addValue(2); - os_timer_setfn(&Timer1, timerCallback, NULL); - os_timer_arm(&Timer1, 6000, true); DEBUG_MSG("ready.\n"); Serial.flush(); }