Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. General Discussion
  3. Send the average value

Send the average value

Scheduled Pinned Locked Moved General Discussion
3 Posts 3 Posters 985 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    moskovskiy82
    wrote on last edited by
    #1

    I have the following code for my sensor and was wondering if it is possilbe to send the average value collected for the
    DHT_interval which is set in the beginning?

    
      unsigned long DHT_Current_Millis = millis();
      if(DHT_Current_Millis - DHT_Millis > DHT_interval)
        {
        DHT_Millis = DHT_Current_Millis; 
        delay(dht.getMinimumSamplingPeriod());
      float temperature = dht.getTemperature();
      if (isnan(temperature)) 
        { Serial.println("Failed reading temperature from DHT"); } 
        else if (temperature != lastTemp) 
          {
          lastTemp = temperature;
          gw.send(msgTemp.set(temperature, 2));
          Serial.print("T: ");
          Serial.println(temperature);
          }
    float humidity = dht.getHumidity();
      if (isnan(humidity)) 
      { Serial.println("Failed reading humidity from DHT"); } 
      else if (humidity != lastHum) 
        {
    	lastHum = humidity;
    	gw.send(msgHum.set(humidity, 2));
    	Serial.print("H: ");
    	Serial.println(humidity);
    	}
    }```
    B mfalkviddM 2 Replies Last reply
    0
    • M moskovskiy82

      I have the following code for my sensor and was wondering if it is possilbe to send the average value collected for the
      DHT_interval which is set in the beginning?

      
        unsigned long DHT_Current_Millis = millis();
        if(DHT_Current_Millis - DHT_Millis > DHT_interval)
          {
          DHT_Millis = DHT_Current_Millis; 
          delay(dht.getMinimumSamplingPeriod());
        float temperature = dht.getTemperature();
        if (isnan(temperature)) 
          { Serial.println("Failed reading temperature from DHT"); } 
          else if (temperature != lastTemp) 
            {
            lastTemp = temperature;
            gw.send(msgTemp.set(temperature, 2));
            Serial.print("T: ");
            Serial.println(temperature);
            }
      float humidity = dht.getHumidity();
        if (isnan(humidity)) 
        { Serial.println("Failed reading humidity from DHT"); } 
        else if (humidity != lastHum) 
          {
      	lastHum = humidity;
      	gw.send(msgHum.set(humidity, 2));
      	Serial.print("H: ");
      	Serial.println(humidity);
      	}
      }```
      B Offline
      B Offline
      boozz
      wrote on last edited by
      #2

      @moskovskiy82
      you could use the runningaverage library for this. see here made by Rob Tillaart.

      Then you still need some mechanism to fill the average. This could be done by executing code at an interval which is e.g. 1/10 or 1/20 of the DHT_interval value. This also defines the arraylength myRA(xxx) as in the example below. 1/10: myRA(10); 1/20: myRA(20);

      Good luck with it,

      Boozz

      //
      //    FILE: runningAverageTest.pde
      //  AUTHOR: Rob Tillaart
      //    DATE: 2012-12-30
      //
      // PUPROSE: show working of runningAverage
      //
      
      #include "RunningAverage.h"
      
      RunningAverage myRA(10);
      int samples = 0;
      
      void setup(void) 
      {
        Serial.begin(115200);
        Serial.println("Demo RunningAverage lib");
        Serial.print("Version: ");
        Serial.println(RUNNINGAVERAGE_LIB_VERSION);
        myRA.clear(); // explicitly start clean
      }
      
      void loop(void) 
      {
        long rn = random(0, 1000);
        myRA.addValue(rn * 0.001);
        samples++;
        Serial.print("Running Average: ");
        Serial.println(myRA.getAverage(), 3);
      
        if (samples == 300)
        {
          samples = 0;
          myRA.clear();
        }
        delay(100);
      }
      
      1 Reply Last reply
      0
      • M moskovskiy82

        I have the following code for my sensor and was wondering if it is possilbe to send the average value collected for the
        DHT_interval which is set in the beginning?

        
          unsigned long DHT_Current_Millis = millis();
          if(DHT_Current_Millis - DHT_Millis > DHT_interval)
            {
            DHT_Millis = DHT_Current_Millis; 
            delay(dht.getMinimumSamplingPeriod());
          float temperature = dht.getTemperature();
          if (isnan(temperature)) 
            { Serial.println("Failed reading temperature from DHT"); } 
            else if (temperature != lastTemp) 
              {
              lastTemp = temperature;
              gw.send(msgTemp.set(temperature, 2));
              Serial.print("T: ");
              Serial.println(temperature);
              }
        float humidity = dht.getHumidity();
          if (isnan(humidity)) 
          { Serial.println("Failed reading humidity from DHT"); } 
          else if (humidity != lastHum) 
            {
        	lastHum = humidity;
        	gw.send(msgHum.set(humidity, 2));
        	Serial.print("H: ");
        	Serial.println(humidity);
        	}
        }```
        mfalkviddM Offline
        mfalkviddM Offline
        mfalkvidd
        Mod
        wrote on last edited by
        #3

        @moskovskiy82 could you describe why you want the average?

        Are you sure the median wouldn't be a better choice? Or letting the controller handle averaging, since it will have access to past events even if the sensor is restarted.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        10

        Online

        11.7k

        Users

        11.2k

        Topics

        113.0k

        Posts


        Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • MySensors
        • OpenHardware.io
        • Categories
        • Recent
        • Tags
        • Popular