Pulse power meter flooding gateway



  • I have built the pulse power meter using the code on this page and it is working great, but when I look at the domoticz log it looks like the sensor is flooding the controller with values.

    General/kWh (Elförbrukning)
    2015-10-21 06:54:52.664 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:54:52.708 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:54:52.903 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:54:52.947 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:54:52.993 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:07.057 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 06:55:12.648 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:12.694 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:12.738 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:12.933 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:12.977 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:13.023 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:32.680 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:32.725 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:32.768 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:32.964 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:33.008 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:33.053 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:37.196 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 06:55:52.710 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:52.756 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:52.801 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:52.995 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:53.039 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:53.085 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:56:07.427 Hardware Monitor: Fetching data (System sensors)
    

    What is the cause of this problem?


  • Hardware Contributor

    Strange. I have the same setup and it works. What did you set the sleep time to in the sketch ? I'm changed to 15 minutes.


  • Mod

    @Cliff-Karlsson said:

    I have built the pulse power meter using the code on this page and it is working great, but when I look at the domoticz log it looks like the sensor is flooding the controller with values.

    General/kWh (Elförbrukning)
    2015-10-21 06:54:52.664 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:54:52.708 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:54:52.903 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:54:52.947 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:54:52.993 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:07.057 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 06:55:12.648 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:12.694 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:12.738 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:12.933 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:12.977 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:13.023 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:32.680 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:32.725 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:32.768 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:32.964 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:33.008 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:33.053 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:37.196 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 06:55:52.710 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:52.756 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:52.801 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:52.995 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:53.039 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:55:53.085 (Mysensors.org) General/kWh (Elförbrukning)
    2015-10-21 06:56:07.427 Hardware Monitor: Fetching data (System sensors)
    

    What is the cause of this problem?

    What sensor are you using to count the pulses? The signal might need denouncing...



  • I am using the same sensor as in the build example, the biggest sensor.


  • Hardware Contributor

    And the code is unchanged from the website?



  • Damn, I removed the sensor and re-uploaded the original sketch and now I get the same error as I struggled with for several days. I get no values from the sensor and it is reported 3 times after every power-cycle.

    2015-10-21 18:06:21.225 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:06:51.365 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:07:21.504 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:07:51.643 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:08:15.844 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:08:15.889 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:08:15.935 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:08:15.984 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:08:16.028 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:08:16.071 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:08:21.782 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:08:51.250 Incoming connection from: 192.168.0.24
    2015-10-21 18:08:52.000 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:09:22.271 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:09:52.490 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:10:22.632 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:10:52.787 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:11:22.930 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:11:34.322 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:11:34.366 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:11:34.411 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:11:34.460 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:11:34.504 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:11:34.547 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:11:53.069 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:12:23.208 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:12:47.029 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:12:47.073 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:12:47.119 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:12:47.168 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:12:47.212 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:12:47.255 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:12:53.347 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:13:23.486 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:13:53.628 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:14:23.768 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:14:53.908 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:15:24.049 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:15:54.187 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:16:15.120 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:16:15.164 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:16:15.209 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:16:15.258 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:16:15.302 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:16:15.345 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:16:24.331 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:16:54.475 Hardware Monitor: Fetching data (System sensors)
    

    And this is the code, I have only added the RFM69 stuff:

    /**
     * The MySensors Arduino library handles the wireless radio link and protocol
     * between your home built sensors/actuators and HA controller of choice.
     * The sensors forms a self healing radio network with optional repeaters. Each
     * repeater and gateway builds a routing tables in EEPROM which keeps track of the
     * network topology allowing messages to be routed to nodes.
     *
     * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
     * Copyright (C) 2013-2015 Sensnology AB
     * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
     *
     * Documentation: http://www.mysensors.org
     * Support Forum: http://forum.mysensors.org
     *
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * version 2 as published by the Free Software Foundation.
     *
     *******************************
     *
     * REVISION HISTORY
     * Version 1.0 - Henrik EKblad
     * 
     * DESCRIPTION
     * This sketch provides an example how to implement a distance sensor using HC-SR04 
     * Use this sensor to measure KWH and Watt of your house meeter
     * You need to set the correct pulsefactor of your meeter (blinks per KWH).
     * The sensor starts by fetching current KWH value from gateway.
     * Reports both KWH and Watt back to gateway.
     *
     * Unfortunately millis() won't increment when the Arduino is in 
     * sleepmode. So we cannot make this sensor sleep if we also want 
     * to calculate/report watt-number.
     * http://www.mysensors.org/build/pulse_power
     */
    
    #include <SPI.h>
    #include <MySensor.h>  
    #include <MyTransportRFM69.h>
    #define DIGITAL_INPUT_SENSOR 3  // The digital input you attached your light sensor.  (Only 2 and 3 generates interrupt!)
    #define PULSE_FACTOR 1000       // Nummber of blinks per KWH of your meeter
    #define SLEEP_MODE false        // Watt-value can only be reported when sleep mode is false.
    #define MAX_WATT 10000          // Max watt value to report. This filetrs outliers.
    #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define CHILD_ID 1              // Id of the sensor child
    unsigned long SEND_FREQUENCY = 30000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
    MyTransportRFM69 transport(RFM69_FREQUENCY, RFM69_NETWORKID, RF69_SPI_CS, RF69_IRQ_PIN, false, RF69_IRQ_NUM);
    MySensor gw(transport);
    double ppwh = ((double)PULSE_FACTOR)/1000; // Pulses per watt hour
    boolean pcReceived = false;
    volatile unsigned long pulseCount = 0;   
    volatile unsigned long lastBlink = 0;
    volatile unsigned long watt = 0;
    unsigned long oldPulseCount = 0;   
    unsigned long oldWatt = 0;
    double oldKwh;
    unsigned long lastSend;
    MyMessage wattMsg(CHILD_ID,V_WATT);
    MyMessage kwhMsg(CHILD_ID,V_KWH);
    MyMessage pcMsg(CHILD_ID,V_VAR1);
    
    
    void setup()  
    {  
      gw.begin(incomingMessage);
    
      // Send the sketch version information to the gateway and Controller
      gw.sendSketchInfo("Energy Meter", "1.0");
    
      // Register this device as power sensor
      gw.present(CHILD_ID, S_POWER);
    
      // Fetch last known pulse count value from gw
      gw.request(CHILD_ID, V_VAR1);
      
      attachInterrupt(INTERRUPT, onPulse, RISING);
      lastSend=millis();
    }
    
    
    void loop()     
    { 
      gw.process();
      unsigned long now = millis();
      // Only send values at a maximum frequency or woken up from sleep
      bool sendTime = now - lastSend > SEND_FREQUENCY;
      if (pcReceived && (SLEEP_MODE || sendTime)) {
        // New watt value has been calculated  
        if (!SLEEP_MODE && watt != oldWatt) {
          // Check that we dont get unresonable large watt value. 
          // could hapen when long wraps or false interrupt triggered
          if (watt<((unsigned long)MAX_WATT)) {
            gw.send(wattMsg.set(watt));  // Send watt value to gw 
          }  
          Serial.print("Watt:");
          Serial.println(watt);
          oldWatt = watt;
        }
      
        // Pulse cout has changed
        if (pulseCount != oldPulseCount) {
          gw.send(pcMsg.set(pulseCount));  // Send pulse count value to gw 
          double kwh = ((double)pulseCount/((double)PULSE_FACTOR));     
          oldPulseCount = pulseCount;
          if (kwh != oldKwh) {
            gw.send(kwhMsg.set(kwh, 4));  // Send kwh value to gw 
            oldKwh = kwh;
          }
        }    
        lastSend = now;
      } else if (sendTime && !pcReceived) {
        // No count received. Try requesting it again
        gw.request(CHILD_ID, V_VAR1);
        lastSend=now;
      }
      
      if (SLEEP_MODE) {
        gw.sleep(SEND_FREQUENCY);
      }
    }
    
    void incomingMessage(const MyMessage &message) {
      if (message.type==V_VAR1) {  
        pulseCount = oldPulseCount = message.getLong();
        Serial.print("Received last pulse count from gw:");
        Serial.println(pulseCount);
        pcReceived = true;
      }
    }
    
    void onPulse()     
    { 
      if (!SLEEP_MODE) {
        unsigned long newBlink = micros();  
        unsigned long interval = newBlink-lastBlink;
        if (interval<10000L) { // Sometimes we get interrupt on RISING
          return;
        }
        watt = (3600000000.0 /interval) / ppwh;
        lastBlink = newBlink;
      } 
      pulseCount++;
    }
    
    
    
    

  • Hardware Contributor

    I cant see anything strange with the code - but i dont know that RFM69 stuff... the code should not send presentation three times, so can it be something with your radio?



  • Ahhh, got it to work again finally. I straightened the curled RFM69 antenna in desperation and moved it around in the room where I have the meeter. Could it be interference as I got alot of cables and electric stuff around the sensor and also a big ass thick pipe that is placed right next to the sensor and is located between the sensor and gateway?

    Now I get this instead:

    2015-10-21 18:53:05.095 MySensors: Node: 7, Sketch Name: Energy Meter
    2015-10-21 18:53:05.108 MySensors: Node: 7, Sketch Version: 1.0
    2015-10-21 18:53:05.723 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:53:35.192 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:53:35.221 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:53:35.944 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:54:05.239 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:54:05.267 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:54:06.085 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:54:35.284 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:54:35.313 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:54:36.228 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:55:05.330 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:55:05.362 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:55:06.378 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:55:35.375 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:55:35.403 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:55:36.519 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:56:05.435 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:56:06.658 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:56:35.466 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:56:35.494 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:56:36.797 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:57:05.526 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:57:06.938 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:57:35.557 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:57:35.585 (Mysensors.org) General/kWh (Meter)
    2015-10-21 18:57:37.079 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:58:05.618 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 18:58:07.220 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:58:35.648 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 18:58:35.676 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 18:58:37.364 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:59:05.694 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 18:59:05.722 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 18:59:07.504 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 18:59:35.739 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 18:59:35.767 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 18:59:37.646 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 19:00:05.784 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 19:00:05.812 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 19:00:07.787 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 19:00:35.830 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 19:00:35.858 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 19:00:37.927 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 19:01:05.875 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 19:01:05.903 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 19:01:08.163 Hardware Monitor: Fetching data (System sensors)
    2015-10-21 19:01:35.934 (Mysensors.org) General/kWh (Elmätare)
    2015-10-21 19:01:38.305 Hardware Monitor: Fetching data (System sensors)
    

    The most of the time the sensor sends twice every time, could it still be the pipe or other things that bounches the signal? Or would the pipe not affect the radio in that way.


  • Mod

    @Cliff-Karlsson said:

    I am using the same sensor as in the build example, the biggest sensor.

    And by 'biggest sensor' you mean the 'LM393 Light Sensor' ?

    I use a comparable sensor (same pcb) with a LDR and had to debounce its readings or multiple pulses were detected on each blink.
    Anyway, from the sketch I see sensor values should only be sent every 30 seconds, so that can't cause you gateway-spamming issue.

    The sketch will try to receive the old absolute counter value on startup, so it can continue counting where it left off:

      // Fetch last known pulse count value from gw
      gw.request(CHILD_ID, V_VAR1);
    

    IKf it doesn't get an answer, it will retry forever:

      } else if (sendTime && !pcReceived) {
        // No count received. Try requesting it again
        gw.request(CHILD_ID, V_VAR1);
        lastSend=now;
      }
    

    Could it be that that mechanism is bugging you?
    You could also connect to the sensor's serial port an see what it has to tell you.


Log in to reply
 

Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.7k
Posts