Issues when upgrading EnergyMeterPulseSensor from 1.5.x to 2.3.2



  • Hi,

    I have upgraded a few sensors and MySensors GW to 2.3.2 but when it comes to my EnergyMeterPulseSensor (which has a light sensor on top of the diod since >3 years) I face issues

    The original 1.5.x sketch looks like

    // 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.
    
    #include <SPI.h>
    #include <MySensor.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 = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
    MySensor gw;
    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.1");
    
      // 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);
      attachInterrupt(INTERRUPT, onPulse, FALLING); // JOCKE
      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) { //JOCKE: Always send
          // 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) { // JOCKE: Always send
          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++;
    }
    

    The 2.3.2 upgraded sketch looks like:

    // 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.
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    #include <MySensors.h>
    
    #define DIGITAL_INPUT_SENSOR 3  // The digital input you attached your light sensor.  (Only 2 and 3 generates interrupt!)
    #define PULSE_FACTOR 1000       // Number of blinks per kWh of your meter. Normally 1000.
    #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 filters outliers.
    // OLD  - #define INTERRUPT DIGITAL_INPUT_SENSOR-2 // Usually the interrupt = pin -2 (on uno/nano anyway)
    #define CHILD_ID 1              // Id of the sensor child
    
    uint32_t SEND_FREQUENCY =
        20000; // Minimum time between send (in milliseconds). We don't want to spam the gateway.
    double ppwh = ((double)PULSE_FACTOR) / 1000; // Pulses per watt hour
    bool pcReceived = false;
    volatile uint32_t pulseCount = 0;
    volatile uint32_t lastBlinkmicros = 0;
    volatile uint32_t lastBlinkmillis = 0;
    volatile uint32_t watt = 0;
    uint32_t oldPulseCount = 0;
    uint32_t oldWatt = 0;
    double oldkWh;
    uint32_t lastSend;
    MyMessage wattMsg(CHILD_ID, V_WATT);
    MyMessage kWhMsg(CHILD_ID, V_KWH);
    MyMessage pcMsg(CHILD_ID, V_VAR1);
    
    #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
    #define IRQ_HANDLER_ATTR ICACHE_RAM_ATTR
    #else
    #define IRQ_HANDLER_ATTR
    #endif
    
    // --------OLD To investigate ----------
    //volatile unsigned long lastBlink = 0;
    // -------------------------------------
    
    void IRQ_HANDLER_ATTR onPulse()
    {
      if (!SLEEP_MODE) {
        uint32_t newBlinkmicros = micros();
        uint32_t newBlinkmillis = millis();
        uint32_t intervalmicros = newBlinkmicros - lastBlinkmicros;
        uint32_t intervalmillis = newBlinkmillis - lastBlinkmillis;
        if (intervalmicros < 10000L && intervalmillis < 10L) { // Sometimes we get interrupt on RISING
          return;
        }
        if (intervalmillis < 360000) { // Less than an hour since last pulse, use microseconds
          watt = (3600000000.0 / intervalmicros) / ppwh;
        } else {
          watt = (3600000.0 / intervalmillis) /
                 ppwh; // more thAn an hour since last pulse, use milliseconds as micros will overflow after 70min
        }
        lastBlinkmicros = newBlinkmicros;
        lastBlinkmillis = newBlinkmillis;
      }
      pulseCount++;
    }
    
    
    void setup()
    {
      // Fetch last known pulse count value from gw
      request(CHILD_ID, V_VAR1);
    
      // Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output
      // If no pullup is used, the reported usage will be too high because of the floating pin
      pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
    
      attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, FALLING);
      // OLD one
      ////  attachInterrupt(INTERRUPT, onPulse, RISING);
      //attachInterrupt(INTERRUPT, onPulse, FALLING); // JOCKE
    
      lastSend = millis();
    }
    
    void presentation()
    {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(F("Energy Meter"), F("2.3.2"));
    
      // Register this device as power sensor
      present(CHILD_ID, S_POWER);
    }
    
    void loop()
    {
      uint32_t 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 don't get unreasonable large watt value, which
          // could happen when long wraps or false interrupt triggered
          if (watt < ((uint32_t)MAX_WATT)) {
            send(wattMsg.set(watt));  // Send watt value to gw
          }
          Serial.print("Watt:");
          Serial.println(watt);
          oldWatt = watt;
        }
    
        // Pulse count value has changed
        if (pulseCount != oldPulseCount) {
          send(pcMsg.set(pulseCount));  // Send pulse count value to gw
          double kWh = ((double)pulseCount / ((double)PULSE_FACTOR));
          oldPulseCount = pulseCount;
          if (kWh != oldkWh) {
            send(kWhMsg.set(kWh, 4));  // Send kWh value to gw
            oldkWh = kWh;
          }
        }
        lastSend = now;
      } else if (sendTime && !pcReceived) {
        // No pulse count value received from controller. Try requesting it again.
        request(CHILD_ID, V_VAR1);
        lastSend = now;
      }
    
      if (SLEEP_MODE) {
        sleep(SEND_FREQUENCY, false);
      }
    }
    
    void receive(const MyMessage &message)
    {
      if (message.getType()==V_VAR1) {
        pulseCount = oldPulseCount = message.getLong();
        Serial.print("Received last pulse count value from gw:");
        Serial.println(pulseCount);
        pcReceived = true;
      }
    }
    

    It seems it get stuck on requesting V_VAR1

    ece7136b-2086-4cf2-928e-5d758ff17c61-image.png

    From the serial monitor I get:

    
     __  __       ____
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.3.2
    
    16 MCO:BGN:INIT NODE,CP=RNNNA---,FQ=16,REL=255,VER=2.3.2
    26 TSM:INIT
    28 TSF:WUR:MS=0
    34 TSM:INIT:TSP OK
    36 TSF:SID:OK,ID=6
    37 TSM:FPAR
    41 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2050 !TSM:FPAR:NO REPLY
    2052 TSM:FPAR
    2056 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    4063 !TSM:FPAR:NO REPLY
    4065 TSM:FPAR
    4069 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    6076 !TSM:FPAR:NO REPLY
    6078 TSM:FPAR
    6082 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    8089 !TSM:FPAR:FAIL
    8090 TSM:FAIL:CNT=1
    8092 TSM:FAIL:DIS
    8094 TSF:TDI:TSL
    18096 TSM:FAIL:RE-INIT
    18098 TSM:INIT
    18104 TSM:INIT:TSP OK
    18106 TSF:SID:OK,ID=6
    18108 TSM:FPAR
    18113 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    20120 !TSM:FPAR:NO REPLY
    20122 TSM:FPAR
    20126 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    22134 !TSM:FPAR:NO REPLY
    22136 TSM:FPAR
    22140 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    24148 !TSM:FPAR:NO REPLY
    24151 TSM:FPAR
    24155 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    26162 !TSM:FPAR:FAIL
    26163 TSM:FAIL:CNT=2
    26165 TSM:FAIL:DIS
    26167 TSF:TDI:TSL
    36170 TSM:FAIL:RE-INIT
    36172 TSM:INIT
    36178 TSM:INIT:TSP OK
    36180 TSF:SID:OK,ID=6
    36183 TSM:FPAR
    36188 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    38195 !TSM:FPAR:NO REPLY
    38197 TSM:FPAR
    38201 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    38636 TSF:MSG:READ,0-0-6,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    38641 TSF:MSG:FPAR OK,ID=0,D=1
    40208 TSM:FPAR:OK
    

    I also tried to ClearEepromConfig, only gave it a new node ID.

    Do you have any tips and tricks to get it working.



  • What happens after the TSM:FPAR:OK ? It seems like the interesting stuffs happens after that part?



  • Here is the full log until I closed it

     
     __  __       ____
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.3.2
    
    16 MCO:BGN:INIT NODE,CP=RNNNA---,FQ=16,REL=255,VER=2.3.2
    26 TSM:INIT
    28 TSF:WUR:MS=0
    34 TSM:INIT:TSP OK
    36 TSF:SID:OK,ID=6
    37 TSM:FPAR
    41 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2050 !TSM:FPAR:NO REPLY
    2052 TSM:FPAR
    2056 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    4063 !TSM:FPAR:NO REPLY
    4065 TSM:FPAR
    4069 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    6076 !TSM:FPAR:NO REPLY
    6078 TSM:FPAR
    6082 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    8089 !TSM:FPAR:FAIL
    8090 TSM:FAIL:CNT=1
    8092 TSM:FAIL:DIS
    8094 TSF:TDI:TSL
    18096 TSM:FAIL:RE-INIT
    18098 TSM:INIT
    18104 TSM:INIT:TSP OK
    18106 TSF:SID:OK,ID=6
    18108 TSM:FPAR
    18113 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    20120 !TSM:FPAR:NO REPLY
    20122 TSM:FPAR
    20126 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    22134 !TSM:FPAR:NO REPLY
    22136 TSM:FPAR
    22140 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    24148 !TSM:FPAR:NO REPLY
    24151 TSM:FPAR
    24155 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    26162 !TSM:FPAR:FAIL
    26163 TSM:FAIL:CNT=2
    26165 TSM:FAIL:DIS
    26167 TSF:TDI:TSL
    36170 TSM:FAIL:RE-INIT
    36172 TSM:INIT
    36178 TSM:INIT:TSP OK
    36180 TSF:SID:OK,ID=6
    36183 TSM:FPAR
    36188 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    38195 !TSM:FPAR:NO REPLY
    38197 TSM:FPAR
    38201 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    38636 TSF:MSG:READ,0-0-6,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    38641 TSF:MSG:FPAR OK,ID=0,D=1
    40208 TSM:FPAR:OK
    40209 TSM:ID
    40211 TSM:ID:OK
    40212 TSM:UPL
    40249 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=NACK:1
    42257 TSM:UPL
    42294 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=1,st=NACK:1
    44301 TSM:UPL
    44338 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=2,st=NACK:1
    46345 TSM:UPL
    46382 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=3,st=NACK:1
    48389 !TSM:UPL:FAIL
    48390 TSM:FPAR
    48395 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=4,st=OK:
    50402 !TSM:FPAR:NO REPLY
    50404 TSM:FPAR
    50408 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    52415 !TSM:FPAR:NO REPLY
    52417 TSM:FPAR
    52421 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    54429 !TSM:FPAR:NO REPLY
    54431 TSM:FPAR
    54435 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    54663 TSF:MSG:READ,0-0-6,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    54668 TSF:MSG:FPAR OK,ID=0,D=1
    56442 TSM:FPAR:OK
    56443 TSM:ID
    56445 TSM:ID:OK
    56446 TSM:UPL
    56483 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=NACK:1
    58492 TSM:UPL
    58529 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=1,st=NACK:1
    60536 TSM:UPL
    60573 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=2,st=NACK:1
    62580 TSM:UPL
    62617 !TSF:MSG:SEND,6-6-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=3,st=NACK:1
    64624 !TSM:UPL:FAIL
    64625 TSM:FPAR
    64630 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=4,st=OK:
    66637 !TSM:FPAR:NO REPLY
    66639 TSM:FPAR
    66643 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    68651 !TSM:FPAR:NO REPLY
    68653 TSM:FPAR
    68657 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    70665 !TSM:FPAR:NO REPLY
    70667 TSM:FPAR
    70671 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    72678 !TSM:FPAR:FAIL
    72679 TSM:FAIL:CNT=3
    72681 TSM:FAIL:DIS
    72683 TSF:TDI:TSL
    82686 TSM:FAIL:RE-INIT
    82689 TSM:INIT
    82695 TSM:INIT:TSP OK
    82697 TSF:SID:OK,ID=6
    82699 TSM:FPAR
    82704 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    84711 !TSM:FPAR:NO REPLY
    84713 TSM:FPAR
    84717 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    86724 !TSM:FPAR:NO REPLY
    86726 TSM:FPAR
    86730 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    88737 !TSM:FPAR:NO REPLY
    88739 TSM:FPAR
    88743 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    90752 !TSM:FPAR:FAIL
    90753 TSM:FAIL:CNT=4
    90755 TSM:FAIL:DIS
    90757 TSF:TDI:TSL
    100760 TSM:FAIL:RE-INIT
    100762 TSM:INIT
    100768 TSM:INIT:TSP OK
    100771 TSF:SID:OK,ID=6
    100773 TSM:FPAR
    100777 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    102786 !TSM:FPAR:NO REPLY
    102788 TSM:FPAR
    102792 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    104800 !TSM:FPAR:NO REPLY
    104802 TSM:FPAR
    104806 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    106814 !TSM:FPAR:NO REPLY
    106816 TSM:FPAR
    106820 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    108828 !TSM:FPAR:FAIL
    108830 TSM:FAIL:CNT=5
    108832 TSM:FAIL:DIS
    108834 TSF:TDI:TSL
    118836 TSM:FAIL:RE-INIT
    118838 TSM:INIT
    118844 TSM:INIT:TSP OK
    118847 TSF:SID:OK,ID=6
    118849 TSM:FPAR
    118853 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    120861 !TSM:FPAR:NO REPLY
    120863 TSM:FPAR
    120867 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    122876 !TSM:FPAR:NO REPLY
    122878 TSM:FPAR
    122883 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    124891 !TSM:FPAR:NO REPLY
    124893 TSM:FPAR
    124897 ?TSF:MSG:SEND,6-6-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    126905 !TSM:FPAR:FAIL
    126907 TSM:FAIL:CNT=6
    126909 TSM:FAIL:DIS
    126911 TSF:TDI:TSL
    136913 TSM:FAIL:RE-INIT
    


  • Not really sure what to make of the log. To me it looks like it isn't connecting properly with the gateway but the picture from MYSController (I have never tried the software) looks promising as it has exchanged information about sketch name, version and so on. I'm also new to MySensors so i'm not able to say what has changed from the two versions. What was the default parameters for nRF24 in 1.5? Amplification and so on.

    Hopefully someone else could be of more help...


  • Mod

    @jocke4u you changed a lot to your sketch when going from 1.5.x to 2.3.2, including e.g. the interrupt handler.
    I would advise to first convert your sketch to 2.3.2 only (following e.g. https://forum.mysensors.org/topic/4276/converting-a-sketch-from-1-5-x-to-2-0-x) and then, if that works correctly, start changing other parts of the sketch (e.g. the interrupt handling).
    You could also flash a basic sketch to test if the hardware performs correctly (I can only hope you didn't switch hardware when going to 2.3.2 😬 )

    The log files you posted don't seem to match the screenshot -- there are no internal messages in the log, while the screenshot shows e.g. even the sketch name being transmitted.



  • @Yveaux Thanks for your input.
    The hardware is unchanged 😉

    The sketch is pretty "stock" from example at the time at 1.5.4 and with 2.3.2 I went for the example as well and just secured the pins were the same etc.
    I will give your suggestion a try, just modify the pieces needed to use 2.3.2 and then leave the rest as is.
    (I wasn't sure if anything were encapsulated in 2.3.2 MySensor so that's why)


  • Mod

    @jocke4u how about the log files don't match the screenshot?



  • So I followed @Yveaux good advice to port the MySensors sketch as plain as possible from 1.5.4 to 2.3.2.
    I think the logs are in synk now also @Yveaux
    The sketch now looks like:

    // =======================================================
    // Node 49 Energy Sensor
    // Measure Total Energy 
    // Sending every 20 sec
    // =======================================================
    // 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.
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    
    #include <MySensors.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 = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
    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 presentation()  
    { 
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Energy Meter", "2.3.2");
    
      // Register this device as power sensor
      present(CHILD_ID, S_POWER);  
    }
    
    void setup()  
    {  
      //begin(incomingMessage);
    
      // Fetch last known pulse count value from gw
      request(CHILD_ID, V_VAR1);
      
    //  attachInterrupt(INTERRUPT, onPulse, RISING);
      attachInterrupt(INTERRUPT, onPulse, FALLING); // JOCKE
      lastSend=millis();
    }
    
    
    void loop()     
    { 
      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) { //JOCKE: Always send
          // Check that we dont get unresonable large watt value. 
          // could hapen when long wraps or false interrupt triggered
          if (watt<((unsigned long)MAX_WATT)) {
            send(wattMsg.set(watt));  // Send watt value to gw 
          }  
          Serial.print("Watt:");
          Serial.println(watt);
          oldWatt = watt;
    //    }
      
        // Pulse cout has changed
    //    if (pulseCount != oldPulseCount) { // JOCKE: Always send
          send(pcMsg.set(pulseCount));  // Send pulse count value to gw 
          double kwh = ((double)pulseCount/((double)PULSE_FACTOR));     
          oldPulseCount = pulseCount;
          if (kwh != oldKwh) {
            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
        request(CHILD_ID, V_VAR1);
        lastSend=now;
      }
      
      if (SLEEP_MODE) {
        sleep(SEND_FREQUENCY);
      }
    }
    
    void receive(const MyMessage &message) {
    //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++;
    }
    

    I cleared the Eeprom on the sensor first and when kicking the Serial Monitor in "Arduino Studio" I get the logs as follows

     
     __  __       ____
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.3.2
    
    16 MCO:BGN:INIT NODE,CP=RNNNA---,FQ=16,REL=255,VER=2.3.2
    26 TSM:INIT
    28 TSF:WUR:MS=0
    34 TSM:INIT:TSP OK
    36 TSF:SID:OK,ID=7
    37 TSM:FPAR
    41 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2050 !TSM:FPAR:NO REPLY
    2052 TSM:FPAR
    2056 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    4063 !TSM:FPAR:NO REPLY
    4065 TSM:FPAR
    4069 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    6076 !TSM:FPAR:NO REPLY
    6078 TSM:FPAR
    6082 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    8089 !TSM:FPAR:FAIL
    8090 TSM:FAIL:CNT=1
    8092 TSM:FAIL:DIS
    8094 TSF:TDI:TSL
    18096 TSM:FAIL:RE-INIT
    18098 TSM:INIT
    18104 TSM:INIT:TSP OK
    18106 TSF:SID:OK,ID=7
    18108 TSM:FPAR
    18113 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    20120 !TSM:FPAR:NO REPLY
    20122 TSM:FPAR
    20126 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    22134 !TSM:FPAR:NO REPLY
    22136 TSM:FPAR
    22140 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    24148 !TSM:FPAR:NO REPLY
    24151 TSM:FPAR
    24155 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    26162 !TSM:FPAR:FAIL
    26163 TSM:FAIL:CNT=2
    26165 TSM:FAIL:DIS
    26167 TSF:TDI:TSL
    36170 TSM:FAIL:RE-INIT
    36172 TSM:INIT
    36178 TSM:INIT:TSP OK
    36180 TSF:SID:OK,ID=7
    36183 TSM:FPAR
    36188 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    38195 !TSM:FPAR:NO REPLY
    38197 TSM:FPAR
    38201 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    38844 TSF:MSG:READ,0-0-7,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    38849 TSF:MSG:FPAR OK,ID=0,D=1
    40209 TSM:FPAR:OK
    40210 TSM:ID
    40212 TSM:ID:OK
    40213 TSM:UPL
    40250 !TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=NACK:1
    42258 TSM:UPL
    42295 !TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=1,st=NACK:1
    44302 TSM:UPL
    44339 !TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=2,st=NACK:1
    46346 TSM:UPL
    46383 !TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=3,st=NACK:1
    48390 !TSM:UPL:FAIL
    48391 TSM:FPAR
    48396 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=4,st=OK:
    50403 !TSM:FPAR:NO REPLY
    50405 TSM:FPAR
    50409 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    52416 !TSM:FPAR:NO REPLY
    52418 TSM:FPAR
    52422 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    54430 !TSM:FPAR:NO REPLY
    54432 TSM:FPAR
    54436 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    56444 !TSM:FPAR:FAIL
    56445 TSM:FAIL:CNT=3
    56448 TSM:FAIL:DIS
    56450 TSF:TDI:TSL
    66453 TSM:FAIL:RE-INIT
    66455 TSM:INIT
    66461 TSM:INIT:TSP OK
    66463 TSF:SID:OK,ID=7
    66465 TSM:FPAR
    66470 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    68478 !TSM:FPAR:NO REPLY
    68481 TSM:FPAR
    68485 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    70492 !TSM:FPAR:NO REPLY
    70494 TSM:FPAR
    70498 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    72506 !TSM:FPAR:NO REPLY
    72508 TSM:FPAR
    72512 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    74519 !TSM:FPAR:FAIL
    74520 TSM:FAIL:CNT=4
    74522 TSM:FAIL:DIS
    74524 TSF:TDI:TSL
    84527 TSM:FAIL:RE-INIT
    84529 TSM:INIT
    84535 TSM:INIT:TSP OK
    84537 TSF:SID:OK,ID=7
    84539 TSM:FPAR
    84544 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    86551 !TSM:FPAR:NO REPLY
    86553 TSM:FPAR
    86557 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    88564 !TSM:FPAR:NO REPLY
    88566 TSM:FPAR
    88570 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    90578 !TSM:FPAR:NO REPLY
    90580 TSM:FPAR
    90585 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    92592 !TSM:FPAR:FAIL
    92593 TSM:FAIL:CNT=5
    92595 TSM:FAIL:DIS
    92597 TSF:TDI:TSL
    102600 TSM:FAIL:RE-INIT
    102602 TSM:INIT
    102608 TSM:INIT:TSP OK
    102611 TSF:SID:OK,ID=7
    102614 TSM:FPAR
    102618 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    104626 !TSM:FPAR:NO REPLY
    104628 TSM:FPAR
    104632 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    106640 !TSM:FPAR:NO REPLY
    106642 TSM:FPAR
    106646 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    108654 !TSM:FPAR:NO REPLY
    108656 TSM:FPAR
    108660 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    110668 !TSM:FPAR:FAIL
    110670 TSM:FAIL:CNT=6
    110672 TSM:FAIL:DIS
    110674 TSF:TDI:TSL
    120676 TSM:FAIL:RE-INIT
    120678 TSM:INIT
    120684 TSM:INIT:TSP OK
    120687 TSF:SID:OK,ID=7
    120689 TSM:FPAR
    120693 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    122701 !TSM:FPAR:NO REPLY
    122703 TSM:FPAR
    122707 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    124716 !TSM:FPAR:NO REPLY
    124718 TSM:FPAR
    124722 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    126730 !TSM:FPAR:NO REPLY
    126732 TSM:FPAR
    126736 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    128744 !TSM:FPAR:FAIL
    128746 TSM:FAIL:CNT=7
    128748 TSM:FAIL:DIS
    128750 TSF:TDI:TSL
    188752 TSM:FAIL:RE-INIT
    188754 TSM:INIT
    188761 TSM:INIT:TSP OK
    188764 TSF:SID:OK,ID=7
    188766 TSM:FPAR
    188770 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    190778 !TSM:FPAR:NO REPLY
    190780 TSM:FPAR
    190784 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    192792 !TSM:FPAR:NO REPLY
    192794 TSM:FPAR
    192798 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    194806 !TSM:FPAR:NO REPLY
    194808 TSM:FPAR
    194812 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    196822 !TSM:FPAR:FAIL
    196824 TSM:FAIL:CNT=7
    196826 TSM:FAIL:DIS
    196828 TSF:TDI:TSL
    256830 TSM:FAIL:RE-INIT
    256832 TSM:INIT
    256838 TSM:INIT:TSP OK
    256841 TSF:SID:OK,ID=7
    256843 TSM:FPAR
    256847 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    258856 !TSM:FPAR:NO REPLY
    258859 TSM:FPAR
    258863 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    260871 !TSM:FPAR:NO REPLY
    260873 TSM:FPAR
    260877 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    262885 !TSM:FPAR:NO REPLY
    262887 TSM:FPAR
    262891 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    264899 !TSM:FPAR:FAIL
    264901 TSM:FAIL:CNT=7
    264903 TSM:FAIL:DIS
    264905 TSF:TDI:TSL
    324907 TSM:FAIL:RE-INIT
    324909 TSM:INIT
    324915 TSM:INIT:TSP OK
    324918 TSF:SID:OK,ID=7
    324920 TSM:FPAR
    324924 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    326932 !TSM:FPAR:NO REPLY
    326934 TSM:FPAR
    326938 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    328946 !TSM:FPAR:NO REPLY
    328948 TSM:FPAR
    328952 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    330961 !TSM:FPAR:NO REPLY
    330963 TSM:FPAR
    330968 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    332976 !TSM:FPAR:FAIL
    332978 TSM:FAIL:CNT=7
    332980 TSM:FAIL:DIS
    332982 TSF:TDI:TSL
    392984 TSM:FAIL:RE-INIT
    392986 TSM:INIT
    392992 TSM:INIT:TSP OK
    392995 TSF:SID:OK,ID=7
    392997 TSM:FPAR
    393001 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    395010 !TSM:FPAR:NO REPLY
    395012 TSM:FPAR
    395016 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    397024 !TSM:FPAR:NO REPLY
    397026 TSM:FPAR
    397030 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    399038 !TSM:FPAR:NO REPLY
    399040 TSM:FPAR
    399044 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    401052 !TSM:FPAR:FAIL
    401054 TSM:FAIL:CNT=7
    401056 TSM:FAIL:DIS
    401058 TSF:TDI:TSL
    461060 TSM:FAIL:RE-INIT
    461062 TSM:INIT
    461068 TSM:INIT:TSP OK
    461071 TSF:SID:OK,ID=7
    461073 TSM:FPAR
    461077 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    463085 !TSM:FPAR:NO REPLY
    463087 TSM:FPAR
    463091 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    465099 !TSM:FPAR:NO REPLY
    465101 TSM:FPAR
    465105 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    467115 !TSM:FPAR:NO REPLY
    467117 TSM:FPAR
    467121 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    469129 !TSM:FPAR:FAIL
    469131 TSM:FAIL:CNT=7
    469133 TSM:FAIL:DIS
    469135 TSF:TDI:TSL
    529137 TSM:FAIL:RE-INIT
    529139 TSM:INIT
    529145 TSM:INIT:TSP OK
    529148 TSF:SID:OK,ID=7
    529150 TSM:FPAR
    529155 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    531163 !TSM:FPAR:NO REPLY
    531165 TSM:FPAR
    531169 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    533177 !TSM:FPAR:NO REPLY
    533179 TSM:FPAR
    533183 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    535191 !TSM:FPAR:NO REPLY
    535193 TSM:FPAR
    535197 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    537205 !TSM:FPAR:FAIL
    537207 TSM:FAIL:CNT=7
    537209 TSM:FAIL:DIS
    537211 TSF:TDI:TSL
    597213 TSM:FAIL:RE-INIT
    597215 TSM:INIT
    597221 TSM:INIT:TSP OK
    597224 TSF:SID:OK,ID=7
    597226 TSM:FPAR
    597230 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    599238 !TSM:FPAR:NO REPLY
    599240 TSM:FPAR
    599244 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    601252 !TSM:FPAR:NO REPLY
    601254 TSM:FPAR
    601259 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    603267 !TSM:FPAR:NO REPLY
    603269 TSM:FPAR
    603273 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    605281 !TSM:FPAR:FAIL
    605283 TSM:FAIL:CNT=7
    605285 TSM:FAIL:DIS
    605287 TSF:TDI:TSL
    665289 TSM:FAIL:RE-INIT
    665291 TSM:INIT
    665297 TSM:INIT:TSP OK
    665300 TSF:SID:OK,ID=7
    665303 TSM:FPAR
    665307 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    667315 !TSM:FPAR:NO REPLY
    667317 TSM:FPAR
    667321 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    669329 !TSM:FPAR:NO REPLY
    669331 TSM:FPAR
    669335 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    671343 !TSM:FPAR:NO REPLY
    671345 TSM:FPAR
    671349 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    671833 TSF:MSG:READ,0-0-7,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    671838 TSF:MSG:FPAR OK,ID=0,D=1
    673357 TSM:FPAR:OK
    673358 TSM:ID
    673360 TSM:ID:OK
    673361 TSM:UPL
    673399 !TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=NACK:1
    675406 TSM:UPL
    675443 !TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=1,st=NACK:1
    677450 TSM:UPL
    677487 !TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=2,st=NACK:1
    679494 TSM:UPL
    679531 !TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=3,st=NACK:1
    681538 !TSM:UPL:FAIL
    681540 TSM:FPAR
    681544 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=4,st=OK:
    683551 !TSM:FPAR:NO REPLY
    683553 TSM:FPAR
    683557 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    685566 !TSM:FPAR:NO REPLY
    685569 TSM:FPAR
    685573 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    687581 !TSM:FPAR:NO REPLY
    687583 TSM:FPAR
    687587 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    689595 !TSM:FPAR:FAIL
    689597 TSM:FAIL:CNT=7
    689599 TSM:FAIL:DIS
    689601 TSF:TDI:TSL
    749603 TSM:FAIL:RE-INIT
    749605 TSM:INIT
    749612 TSM:INIT:TSP OK
    749615 TSF:SID:OK,ID=7
    749617 TSM:FPAR
    749621 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    751629 !TSM:FPAR:NO REPLY
    751631 TSM:FPAR
    751635 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    753643 !TSM:FPAR:NO REPLY
    753645 TSM:FPAR
    753649 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    755657 !TSM:FPAR:NO REPLY
    755659 TSM:FPAR
    755663 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    757672 !TSM:FPAR:FAIL
    757675 TSM:FAIL:CNT=7
    757677 TSM:FAIL:DIS
    757679 TSF:TDI:TSL
    817681 TSM:FAIL:RE-INIT
    817683 TSM:INIT
    817689 TSM:INIT:TSP OK
    817692 TSF:SID:OK,ID=7
    817694 TSM:FPAR
    817698 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    819706 !TSM:FPAR:NO REPLY
    819708 TSM:FPAR
    819713 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    821721 !TSM:FPAR:NO REPLY
    821723 TSM:FPAR
    821727 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    823735 !TSM:FPAR:NO REPLY
    823737 TSM:FPAR
    823741 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    825749 !TSM:FPAR:FAIL
    825751 TSM:FAIL:CNT=7
    825753 TSM:FAIL:DIS
    825755 TSF:TDI:TSL
    

    And the corresponding logs in MYSController looks like:

    d8c980a9-e3a6-4070-9b46-e205890ae6f6-image.png

    And I observe a number of C_REQ like:

    2ee42f8c-0ff8-4cd3-a67d-d3241b15af55-image.png



  • Ok, still trying to get this to work.
    Added som more print-outs and I don't understand why none of the prints gets into the Serial Monitor.
    Is it stuck into MySensors so the sketch isn't started correctly, or what happens?!

    The ugly Sketch

    // =======================================================
    // Node Total Energy Sensor
    // Sending every 20 sec
    // =======================================================
    // 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.
    
    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    
    #include <MySensors.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 = 20000; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
    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 presentation()  
    { 
      Serial.println("### Start Present");
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("Energy Meter", "2.3.2");
    
      // Register this device as power sensor
      present(CHILD_ID, S_POWER);  
      Serial.println("### End Present");
    }
    
    void setup()  
    {  
      Serial.println("### Start Setup");
      //begin(incomingMessage);
    
      // Fetch last known pulse count value from gw
      request(CHILD_ID, V_VAR1);
      
    //  attachInterrupt(INTERRUPT, onPulse, RISING);
      attachInterrupt(INTERRUPT, onPulse, FALLING); // JOCKE
      lastSend=millis();
      Serial.println("### End Setup");
    }
    
    void loop()     
    { 
      Serial.println("### Loop");
      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)) {
        // Check that we dont get unresonable large watt value. 
        // could hapen when long wraps or false interrupt triggered
        if (watt<((unsigned long)MAX_WATT)) {
          Serial.println("");
          Serial.print("### Sending WATTS: ");
          Serial.println(watt);
          send(wattMsg.set(watt));  // Send watt value to gw 
        }  
        oldWatt = watt;
      
        send(pcMsg.set(pulseCount));  // Send pulse count value to gw 
        double kwh = ((double)pulseCount/((double)PULSE_FACTOR));     
        oldPulseCount = pulseCount;
        if (kwh != oldKwh) {
          Serial.println("");
          Serial.print("### Sending kWh: ");
          Serial.println(kwh);
          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
        request(CHILD_ID, V_VAR1);
        lastSend=now;
      }
      
      if (SLEEP_MODE) {
        sleep(SEND_FREQUENCY);
      }
    }
    
    //void incomingMessage(const MyMessage &message) {
    void receive(const MyMessage &message) {
      if (message.type==V_VAR1) {  
        pulseCount = oldPulseCount = message.getLong();
        Serial.println("");
        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;
      } 
      Serial.print(" . ");
      pulseCount++;
    }
    

    The output from Serial Monitor:

     
     __  __       ____
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.3.2
    
    16 MCO:BGN:INIT NODE,CP=RNNNA---,FQ=16,REL=255,VER=2.3.2
    26 TSM:INIT
    28 TSF:WUR:MS=0
    34 TSM:INIT:TSP OK
    36 TSF:SID:OK,ID=7
    37 TSM:FPAR
    41 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    2050 !TSM:FPAR:NO REPLY
    2052 TSM:FPAR
    2056 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    4063 !TSM:FPAR:NO REPLY
    4065 TSM:FPAR
    4069 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    6076 !TSM:FPAR:NO REPLY
    6078 TSM:FPAR
    6082 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    8089 !TSM:FPAR:FAIL
    8090 TSM:FAIL:CNT=1
    8092 TSM:FAIL:DIS
    8094 TSF:TDI:TSL
    18096 TSM:FAIL:RE-INIT
    18098 TSM:INIT
    18104 TSM:INIT:TSP OK
    18106 TSF:SID:OK,ID=7
    18108 TSM:FPAR
    18113 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    20120 !TSM:FPAR:NO REPLY
    20122 TSM:FPAR
    20126 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    22134 !TSM:FPAR:NO REPLY
    22136 TSM:FPAR
    22140 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    24148 !TSM:FPAR:NO REPLY
    24151 TSM:FPAR
    24155 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    26162 !TSM:FPAR:FAIL
    26163 TSM:FAIL:CNT=2
    26165 TSM:FAIL:DIS
    26167 TSF:TDI:TSL
    36170 TSM:FAIL:RE-INIT
    36172 TSM:INIT
    36178 TSM:INIT:TSP OK
    36180 TSF:SID:OK,ID=7
    36183 TSM:FPAR
    36188 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    38195 !TSM:FPAR:NO REPLY
    38197 TSM:FPAR
    38201 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    40209 !TSM:FPAR:NO REPLY
    40211 TSM:FPAR
    40215 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    
    

  • Mod

    @jocke4u the node is unable to find a path to your gateway, so it never reaches loop()

    Could you post the log from your gateway and the gateway sketch?

    Do you still have your 1.x gateway running? Is it using the same channel?



  • Thanks Mikael (@mfalkvidd )
    The GW is running 2.3.2 and have not changed the channel ( I skipped the RPi approach as we discussed in another thread)
    I hooked up my gateway to Arduino Serial Monitor and during this time I also restarted this sensor.
    Please note that I have other sensors reporting correctly.
    Log log shows:

    0 MCO:BGN:INIT GW,CP=RNNGA---,FQ=16,REL=255,VER=2.3.2
    4 TSM:INIT
    5 TSF:WUR:MS=0
    12 TSM:INIT:TSP OK
    13 TSM:INIT:GW MODE
    15 TSM:READY:ID=0,PAR=0,DIS=0
    18 MCO:REG:NOT NEEDED
    580 GWT:TIN:IP=192.168.1.11
    1584 MCO:BGN:STP
    1586 MCO:BGN:INIT OK,TSP=1
    1588 TSM:READY:NWD REQ
    1593 ?TSF:MSG:SEND,0-0-255-255,s=255,c=3,t=20,pt=0,l=0,sg=0,ft=0,st=OK:
    2140 TSF:MSG:READ,7-7-0,s=255,c=3,t=21,pt=1,l=1,sg=0:0
    14924 TSF:MSG:READ,7-7-0,s=1,c=2,t=24,pt=0,l=0,sg=0:
    34877 TSF:MSG:READ,7-7-0,s=1,c=2,t=24,pt=0,l=0,sg=0:
    54829 TSF:MSG:READ,7-7-0,s=1,c=2,t=24,pt=0,l=0,sg=0:
    80115 TSF:MSG:READ,7-7-255,s=255,c=3,t=7,pt=0,l=0,sg=0:
    80120 TSF:MSG:BC
    80122 TSF:MSG:FPAR REQ,ID=7
    80124 TSF:PNG:SEND,TO=0
    80128 TSF:CKU:OK
    80129 TSF:MSG:GWL OK
    80392 TSF:MSG:SEND,0-0-7-7,s=255,c=3,t=8,pt=1,l=1,sg=0,ft=0,st=OK:0
    82126 TSF:MSG:READ,7-7-0,s=255,c=3,t=24,pt=1,l=1,sg=0:1
    82131 TSF:MSG:PINGED,ID=7,HP=1
    82136 TSF:MSG:SEND,0-0-7-7,s=255,c=3,t=25,pt=1,l=1,sg=0,ft=0,st=OK:1
    82149 TSF:MSG:READ,7-7-0,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    82156 TSF:MSG:SEND,0-0-7-7,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    82163 TSF:MSG:READ,7-7-0,s=255,c=0,t=17,pt=0,l=5,sg=0:2.3.2
    82171 TSF:MSG:READ,7-7-0,s=255,c=3,t=6,pt=1,l=1,sg=0:0
    82180 GWT:TSA:ETH OK
    82184 GWT:RFC:MSG=7;255;3;0;6;M
    82189 TSF:MSG:SEND,0-0-7-7,s=255,c=3,t=6,pt=0,l=1,sg=0,ft=0,st=OK:M
    82196 TSF:MSG:READ,7-7-0,s=255,c=3,t=11,pt=0,l=12,sg=0:Energy Meter
    82205 TSF:MSG:READ,7-7-0,s=255,c=3,t=12,pt=0,l=5,sg=0:2.3.2
    82213 TSF:MSG:READ,7-7-0,s=1,c=0,t=13,pt=0,l=0,sg=0:
    82224 TSF:MSG:READ,7-7-0,s=255,c=3,t=26,pt=1,l=1,sg=0:2
    82233 TSF:MSG:SEND,0-0-7-7,s=255,c=3,t=27,pt=1,l=1,sg=0,ft=0,st=OK:1
    82241 TSF:MSG:READ,7-7-0,s=1,c=2,t=24,pt=0,l=0,sg=0:
    102202 TSF:MSG:READ,7-7-0,s=1,c=2,t=24,pt=0,l=0,sg=0:
    110822 TSF:MSG:READ,2-2-0,s=1,c=1,t=0,pt=7,l=5,sg=0:22.1
    122153 TSF:MSG:READ,7-7-0,s=1,c=2,t=24,pt=0,l=0,sg=0:
    
    

    The Sketch of GW looks like:

    /*
     * 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-2019 Sensnology AB
     * Full contributor list: https://github.com/mysensors/MySensors/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
     * Contribution by a-lurker and Anticimex
     * Contribution by Norbert Truchsess <norbert.truchsess@t-online.de>
     * Contribution by Tomas Hozza <thozza@gmail.com>
     *
     *
     * DESCRIPTION
     * The EthernetGateway sends data received from sensors to the ethernet link.
     * The gateway also accepts input on ethernet interface, which is then sent out to the radio network.
     *
     * The GW code is designed for Arduino 328p / 16MHz.  ATmega168 does not have enough memory to run this program.
     *
     * LED purposes:
     * - To use the feature, uncomment MY_DEFAULT_xxx_LED_PIN in the sketch below
     * - RX (green) - blink fast on radio message received. In inclusion mode will blink fast only on presentation received
     * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
     * - ERR (red) - fast blink on error during transmission error or receive crc error
     *
     * See http://www.mysensors.org/build/ethernet_gateway for wiring instructions.
     *
     */
    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    // Enable gateway ethernet module type
    #define MY_GATEWAY_W5100
    
    // W5100 Ethernet module SPI enable (optional if using a shield/module that manages SPI_EN signal)
    //#define MY_W5100_SPI_EN 4
    
    // Enable Soft SPI for NRF radio (note different radio wiring is required)
    // The W5100 ethernet module seems to have a hard time co-operate with
    // radio on the same spi bus.
    #if !defined(MY_W5100_SPI_EN) && !defined(ARDUINO_ARCH_SAMD)
    #define MY_SOFTSPI
    #define MY_SOFT_SPI_SCK_PIN 14
    #define MY_SOFT_SPI_MISO_PIN 16
    #define MY_SOFT_SPI_MOSI_PIN 15
    #endif
    
    // When W5100 is connected we have to move CE/CSN pins for NRF radio
    #ifndef MY_RF24_CE_PIN
    #define MY_RF24_CE_PIN 5
    #endif
    #ifndef MY_RF24_CS_PIN
    #define MY_RF24_CS_PIN 6
    #endif
    
    // Enable UDP communication
    //#define MY_USE_UDP  // If using UDP you need to set MY_CONTROLLER_IP_ADDRESS or MY_CONTROLLER_URL_ADDRESS below
    
    // Enable MY_IP_ADDRESS here if you want a static ip address (no DHCP)
    #define MY_IP_ADDRESS 192,168,1,11
    
    // If using static ip you can define Gateway and Subnet address as well
    //#define MY_IP_GATEWAY_ADDRESS 192,168,178,1
    //#define MY_IP_SUBNET_ADDRESS 255,255,255,0
    
    // Renewal period if using DHCP
    //#define MY_IP_RENEWAL_INTERVAL 60000
    
    // The port to keep open on node server mode / or port to contact in client mode
    #define MY_PORT 5003
    
    // Controller ip address. Enables client mode (default is "server" mode).
    // Also enable this if MY_USE_UDP is used and you want sensor data sent somewhere.
    //#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 254
    //#define MY_CONTROLLER_URL_ADDRESS "my.controller.org"
    
    // The MAC address can be anything you want but should be unique on your network.
    // Newer boards have a MAC address printed on the underside of the PCB, which you can (optionally) use.
    // Note that most of the Arduino examples use  "DEAD BEEF FEED" for the MAC address.
    #define MY_MAC_ADDRESS 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
    
    
    // Enable inclusion mode
    #define MY_INCLUSION_MODE_FEATURE
    // Enable Inclusion mode button on gateway
    //#define MY_INCLUSION_BUTTON_FEATURE
    // Set inclusion mode duration (in seconds)
    #define MY_INCLUSION_MODE_DURATION 60
    // Digital pin used for inclusion mode button
    //#define MY_INCLUSION_MODE_BUTTON_PIN  3
    
    // Set blinking period
    #define MY_DEFAULT_LED_BLINK_PERIOD 300
    
    // Flash leds on rx/tx/err
    // Uncomment to override default HW configurations
    #define MY_DEFAULT_ERR_LED_PIN 7  // Error led pin
    #define MY_DEFAULT_RX_LED_PIN  8  // Receive led pin
    #define MY_DEFAULT_TX_LED_PIN  9  // Transmit led pin
    
    #if defined(MY_USE_UDP)
    #include <EthernetUdp.h>
    #endif
    #include <Ethernet.h>
    #include <MySensors.h>
    
    void setup()
    {
      // Setup locally attached sensors
    }
    
    void presentation()
    {
      // Present locally attached sensors here
    }
    
    void loop()
    {
      // Send locally attached sensors data here
    }
    

  • Mod

    When looking in the log parser, I notice the following:

    • At 14924, 34877, 54829, node 7 is requesting data from node 0:
    	Received Message
    Sender: 7
    Last Node: 7
    Destination: 0
    Sensor Id: 1
    Command: REQ
    Message Type: V_VAR1
    Payload Type: P_STRING
    Payload Length: 0
    Signing: 0
    Payload: 
    

    This probably corresponds to this code in the node:

        // No count received. Try requesting it again
        request(CHILD_ID, V_VAR1);
    

    My guess is that the node expects this variable to be available at the controller. I don't have much experience with requesting variables so I don't have any good suggestions unfortunately.

    • The log also shows that the FPAR requests that failed earlier work fine now:
    Sent Message
    Sender: 0
    Last Node: 0
    Next Node: 7
    Destination: 7
    Sensor Id: 255
    Command: INTERNAL
    Message Type:I_FIND_PARENT_RESPONSE
    Payload Type: P_BYTE
    Payload Length: 1
    Signing: 0
    Failed uplink counter: 0
    Status: OK (OK=success, NACK=no radio ACK received)
    Payload: 0
    


  • First day of vacation and it is raining = MySensors time 🙂
    I brought this power sensor with TSL237 to the office since I suspected some issues with HW. And yes it seems the TSL237 is broken so tested with a new one. The sensor seems to work fine (using a flashlight).

    But I can't get the reply of the V_VAR1 from the GW.
    Any idea why?

    The Sketch:

    // Enable debug prints
    #define MY_DEBUG
    
    // Enable and select radio type attached
    #define MY_RADIO_RF24
    //#define MY_RADIO_NRF5_ESB
    //#define MY_RADIO_RFM69
    //#define MY_RADIO_RFM95
    
    #include <MySensors.h>
    
    #define DIGITAL_INPUT_SENSOR 3  // The digital input you attached your light sensor.  (Only 2 and 3 generates interrupt!)
    #define PULSE_FACTOR 1000       // Number of blinks per kWh of your meter. Normally 1000.
    #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 filters outliers.
    #define CHILD_ID 1              // Id of the sensor child
    
    uint32_t SEND_FREQUENCY =
        20000; // Minimum time between send (in milliseconds). We don't want to spam the gateway.
    double ppwh = ((double)PULSE_FACTOR) / 1000; // Pulses per watt hour
    bool pcReceived = false;
    volatile uint32_t pulseCount = 0;
    volatile uint32_t lastBlinkmicros = 0;
    volatile uint32_t lastBlinkmillis = 0;
    volatile uint32_t watt = 0;
    uint32_t oldPulseCount = 0;
    uint32_t oldWatt = 0;
    double oldkWh;
    uint32_t lastSend;
    MyMessage wattMsg(CHILD_ID, V_WATT);
    MyMessage kWhMsg(CHILD_ID, V_KWH);
    MyMessage pcMsg(CHILD_ID, V_VAR1);
    
    #if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
    #define IRQ_HANDLER_ATTR ICACHE_RAM_ATTR
    #else
    #define IRQ_HANDLER_ATTR
    #endif
    
    void IRQ_HANDLER_ATTR onPulse()
    {
    	if (!SLEEP_MODE) {
    		uint32_t newBlinkmicros = micros();
    		uint32_t newBlinkmillis = millis();
    		uint32_t intervalmicros = newBlinkmicros - lastBlinkmicros;
    		uint32_t intervalmillis = newBlinkmillis - lastBlinkmillis;
    		if (intervalmicros < 10000L && intervalmillis < 10L) { // Sometimes we get interrupt on RISING
    			return;
    		}
    		if (intervalmillis < 360000) { // Less than an hour since last pulse, use microseconds
    			watt = (3600000000.0 / intervalmicros) / ppwh;
    		} else {
    			watt = (3600000.0 / intervalmillis) /
    			       ppwh; // more thAn an hour since last pulse, use milliseconds as micros will overflow after 70min
    		}
    		lastBlinkmicros = newBlinkmicros;
    		lastBlinkmillis = newBlinkmillis;
    	}
      Serial.println("### Pulse");
    	pulseCount++;
    }
    
    void setup()
    {
      Serial.println("### Start Setup");
    	// Fetch last known pulse count value from gw
    	request(CHILD_ID, V_VAR1);
    
    	// Use the internal pullup to be able to hook up this sketch directly to an energy meter with S0 output
    	// If no pullup is used, the reported usage will be too high because of the floating pin
    	pinMode(DIGITAL_INPUT_SENSOR, INPUT_PULLUP);
    
    	attachInterrupt(digitalPinToInterrupt(DIGITAL_INPUT_SENSOR), onPulse, RISING);
    	lastSend = millis();
      Serial.println("### End Setup");
    }
    
    void presentation()
    {
      Serial.println("### Start Present");
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo(F("Energy Meter"), F("2.3.2"));
    
    	// Register this device as power sensor
    	present(CHILD_ID, S_POWER);
      Serial.println("### End Present");
    }
    
    void loop()
    {
    	uint32_t 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 don't get unreasonable large watt value, which
    			// could happen when long wraps or false interrupt triggered
    			if (watt < ((uint32_t)MAX_WATT)) {
    				send(wattMsg.set(watt));  // Send watt value to gw
    			}
    			Serial.print("### Watt:");
    			Serial.println(watt);
    			oldWatt = watt;
    		}
    
    		// Pulse count value has changed
    		if (pulseCount != oldPulseCount) {
    			send(pcMsg.set(pulseCount));  // Send pulse count value to gw
    			double kWh = ((double)pulseCount / ((double)PULSE_FACTOR));
    			oldPulseCount = pulseCount;
    			if (kWh != oldkWh) {
    				send(kWhMsg.set(kWh, 4));  // Send kWh value to gw
    				oldkWh = kWh;
    			}
    		}
    		lastSend = now;
    	} else if (sendTime && !pcReceived) {
    		// No pulse count value received from controller. Try requesting it again.
    		request(CHILD_ID, V_VAR1);
    		lastSend = now;
    	}
    
    	if (SLEEP_MODE) {
    		sleep(SEND_FREQUENCY, false);
    	}
    }
    
    void receive(const MyMessage &message)
    {
      Serial.println("### NEW Received message of type: ");
      Serial.println(message.getType());
      Serial.println("### Expected: ");
      Serial.println(V_VAR1);
    	if (message.getType()==V_VAR1) {
    		Serial.println("");
    		Serial.print("### Received last pulse count value from gw:");
        pulseCount = oldPulseCount = message.getLong();    
    		Serial.println(pulseCount);
    		pcReceived = true;
    	}
    }
    

    Log from serial monitor:

     __  __       ____
    |  \/  |_   _/ ___|  ___ _ __  ___  ___  _ __ ___
    | |\/| | | | \___ \ / _ \ `_ \/ __|/ _ \| `__/ __|
    | |  | | |_| |___| |  __/ | | \__ \  _  | |  \__ \
    |_|  |_|\__, |____/ \___|_| |_|___/\___/|_|  |___/
            |___/                      2.3.2
    
    16 MCO:BGN:INIT NODE,CP=RNNNA---,FQ=16,REL=255,VER=2.3.2
    26 TSM:INIT
    28 TSF:WUR:MS=0
    34 TSM:INIT:TSP OK
    36 TSF:SID:OK,ID=7
    37 TSM:FPAR
    41 ?TSF:MSG:SEND,7-7-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
    962 TSF:MSG:READ,0-0-7,s=255,c=3,t=8,pt=1,l=1,sg=0:0
    967 TSF:MSG:FPAR OK,ID=0,D=1
    2050 TSM:FPAR:OK
    2051 TSM:ID
    2052 TSM:ID:OK
    2054 TSM:UPL
    2057 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=OK:1
    2068 TSF:MSG:READ,0-0-7,s=255,c=3,t=25,pt=1,l=1,sg=0:1
    2073 TSF:MSG:PONG RECV,HP=1
    2076 TSM:UPL:OK
    2077 TSM:READY:ID=7,PAR=0,DIS=1
    2086 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
    2094 TSF:MSG:READ,0-0-7,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
    2106 TSF:MSG:SEND,7-7-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=OK:2.3.2
    2116 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=0,st=OK:0
    2137 TSF:MSG:READ,0-0-7,s=255,c=3,t=6,pt=0,l=1,sg=0:M
    ### Start Present
    2166 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=11,pt=0,l=12,sg=0,ft=0,st=OK:Energy Meter
    2183 TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=12,pt=0,l=5,sg=0,ft=0,st=OK:2.3.2
    2193 TSF:MSG:SEND,7-7-0-0,s=1,c=0,t=13,pt=0,l=0,sg=0,ft=0,st=OK:
    ### End Present
    2199 MCO:REG:REQ
    2238 !TSF:MSG:SEND,7-7-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=0,st=NACK:2
    2244 TSF:MSG:READ,0-0-7,s=255,c=3,t=27,pt=1,l=1,sg=0:1
    2249 MCO:PIM:NODE REG=1
    2252 MCO:BGN:STP
    ### Start Setup
    2255 TSF:MSG:SEND,7-7-0-0,s=1,c=2,t=24,pt=0,l=0,sg=0,ft=1,st=OK:
    ### End Setup
    2262 MCO:BGN:INIT OK,TSP=1
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    42265 TSF:MSG:SEND,7-7-0-0,s=1,c=1,t=17,pt=5,l=4,sg=0,ft=0,st=OK:2263
    ### Watt:2263
    42276 TSF:MSG:SEND,7-7-0-0,s=1,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:7
    42290 TSF:MSG:SEND,7-7-0-0,s=1,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:0.0070
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    ### Pulse
    62271 TSF:MSG:SEND,7-7-0-0,s=1,c=1,t=17,pt=5,l=4,sg=0,ft=0,st=OK:2103
    ### Watt:2103
    62279 TSF:MSG:SEND,7-7-0-0,s=1,c=1,t=24,pt=5,l=4,sg=0,ft=0,st=OK:19
    62290 TSF:MSG:SEND,7-7-0-0,s=1,c=1,t=18,pt=7,l=5,sg=0,ft=0,st=OK:0.0190
    

    Screenshot from MYSController
    f414c520-079c-4b4d-a8de-309ab431898c-image.png



  • V_Var1 is variable(your total pulses) stored in the controller - HomeAssistant, Domoticz etc....
    Assuming you have controller shut down you have to send that value from MYSController.

    This request will be fulfilled by controller after you configure it to use node's 7 child 1



  • @Sasquatch Thanks, it was a connection issue with HomeAssistant to MySensors GW.
    Now it is time to clean up the sketch and put it to operation again.

    Also thanks you other guys that have been helpful @mfalkvidd @Yveaux @niclas


Log in to reply
 

Suggested Topics

0
Online

11.4k
Users

11.1k
Topics

112.6k
Posts