Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. jocke4u
    3. Posts
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Posts made by jocke4u

    • RE: Issues when upgrading EnergyMeterPulseSensor from 1.5.x to 2.3.2

      @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

      posted in Development
      jocke4u
      jocke4u
    • RE: Issues when upgrading EnergyMeterPulseSensor from 1.5.x to 2.3.2

      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

      posted in Development
      jocke4u
      jocke4u
    • RE: Issues when upgrading EnergyMeterPulseSensor from 1.5.x to 2.3.2

      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
      }
      
      posted in Development
      jocke4u
      jocke4u
    • RE: Issues when upgrading EnergyMeterPulseSensor from 1.5.x to 2.3.2

      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:
      
      
      posted in Development
      jocke4u
      jocke4u
    • RE: Issues when upgrading EnergyMeterPulseSensor from 1.5.x to 2.3.2

      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

      posted in Development
      jocke4u
      jocke4u
    • RE: Issues when upgrading EnergyMeterPulseSensor from 1.5.x to 2.3.2

      @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)

      posted in Development
      jocke4u
      jocke4u
    • RE: Issues when upgrading EnergyMeterPulseSensor from 1.5.x to 2.3.2

      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
      
      posted in Development
      jocke4u
      jocke4u
    • 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.

      posted in Development
      jocke4u
      jocke4u
    • Two MySensor gateways to the same Home Assistant

      HI,

      As discussed here: https://forum.mysensors.org/topic/11181/parallel-gateways/8 I am planning to upgrade the MySensors GW from Arduino to Raspberry Pi and running them in parallel.

      I suppose it is possible to have several gateways configured in HA like:

      mysensors:
        gateways:
          - device: '192.168.1.11'
            persistence_file: './mysensors.json'
            tcp_port: 5003
          - device: '192.168.1.12'
            persistence_file: './mysensors2.json'
            tcp_port: 5003
        optimistic: false
        persistence: true
        retain: true
        version: 1.5
      

      Right?

      posted in Home Assistant
      jocke4u
      jocke4u
    • RE: Parallel Gateways

      @mfalkvidd Thanks, maybe a better approach since I anyway should upgrade the sensors since they haven't been touched for a very long time and running 1.5.x

      posted in General Discussion
      jocke4u
      jocke4u
    • RE: Parallel Gateways

      @mfalkvidd By using a different channel you mean that (1) get the GW up and running and then (2) migrate each sensor from GW1 to GW2, right?

      posted in General Discussion
      jocke4u
      jocke4u
    • RE: Parallel Gateways

      @rejoe2 I don't know, thats why I asked if I should expect problems 😉
      My thinking is to have Home Assistant connected to GW1 (mostly logging values not really acting) and develop/configure/test GW2 and using MysController to just watch the traffic i.e. my wish is to have all sensor messages to both GWs and when happy I reconfigure Home Assistant to GW2 and shut down GW1.

      I already have RPi hardware, radios etc on the shelf.

      In what sense do you consider RPi-Ethernet-GW to be more tricky than Arduino-Ethernet-GW?

      posted in General Discussion
      jocke4u
      jocke4u
    • Parallel Gateways

      Hi,

      I have an Arduino Ethernet Gateway with NRF24L01+ PA/LNA since several years. Now I want to switch over to Raspberry Pi Ethernet Gateway with the same type of radio.

      Is it possible to have two gateways running in parallel or will they interfere with each other and/or the sensors?
      Just to make the development/testing without much downtime.

      Are there any special issues to think of when doing a migration and/or actions that need to done?

      posted in General Discussion
      jocke4u
      jocke4u
    • RE: Migrating from openHAB to Home Assistant

      Thanks @electrik for the update 🙂
      I got it running.
      However I think I should make some work on the sensors.
      As it seems the Ethernet GW are running 2.1.1 but I think the sensors are running 1.5.x (seen in MysController)

      But I get plenty of :

      2020-05-28 19:29:47 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:30:22 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:30:57 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:31:32 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:32:07 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:33:17 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:33:51 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:34:26 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:35:01 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:35:36 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:36:11 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:36:46 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:37:21 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:38:31 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:39:06 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:39:41 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-28 19:40:50 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      

      Trying to get my dev environment correct to be able to recompile.

      EDIT: Since it have been so stable for a long time I am not up to date with the Arduino environment. My experience from the past is not without issues

      posted in Home Assistant
      jocke4u
      jocke4u
    • RE: Migrating from openHAB to Home Assistant

      Hmmm, could it be a problem that my old openHAB installation still is active?
      Will MySensors Gateway handle different "consumers"?

      posted in Home Assistant
      jocke4u
      jocke4u
    • RE: Migrating from openHAB to Home Assistant

      Tried to set

      mysensors:
        gateways:
          - device: '192.168.1.11'
            persistence_file: './mysensors.json'
            tcp_port: 5003
        optimistic: false
        persistence: true
        retain: true
        version: '2.1.1'
      

      But get in logs a lot of:

      2020-05-26 17:32:30 WARNING (MainThread) [mysensors] Node 49 is unknown
      2020-05-26 17:32:40 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-26 17:32:50 WARNING (MainThread) [mysensors] Node 49 is unknown
      2020-05-26 17:33:10 WARNING (MainThread) [mysensors] Node 49 is unknown
      2020-05-26 17:33:30 WARNING (MainThread) [mysensors] Node 49 is unknown
      2020-05-26 17:33:39 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-26 17:33:50 WARNING (MainThread) [mysensors] Node 49 is unknown
      2020-05-26 17:34:10 WARNING (MainThread) [mysensors] Node 49 is unknown
      2020-05-26 17:34:13 WARNING (MainThread) [mysensors] Node 3 is unknown
      2020-05-26 17:34:13 WARNING (MainThread) [mysensors] Node 3 is unknown
      2020-05-26 17:34:14 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-26 17:34:30 WARNING (MainThread) [mysensors] Node 49 is unknown
      2020-05-26 17:34:33 WARNING (MainThread) [mysensors] Node 4 is unknown
      2020-05-26 17:34:46 WARNING (MainThread) [mysensors] Node 3 is unknown
      2020-05-26 17:34:49 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-26 17:34:49 WARNING (MainThread) [mysensors] Node 49 is unknown
      2020-05-26 17:34:53 WARNING (MainThread) [mysensors] Node 4 is unknown
      2020-05-26 17:35:09 WARNING (MainThread) [mysensors] Node 49 is unknown
      2020-05-26 17:35:24 WARNING (MainThread) [mysensors] Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      2020-05-26 17:35:29 WARNING (MainThread) [mysensors] Node 49 is unknown
      2020-05-26 17:35:49 WARNING (MainThread) [mysensors] Node 49 is unknown
      2020-05-26 17:35:53 WARNING (MainThread) [mysensors] Node 3 is unknown
      

      But also

      Log Details (ERROR)
      Logger: homeassistant.components.sensor
      Source: components/mysensors/sensor.py:92
      Integration: Sensor (documentation, issues)
      First occurred: 6:46:09 PM (4 occurrences)
      Last logged: 6:46:50 PM
      
      Error while setting up mysensors platform for sensor
      Traceback (most recent call last):
        File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 186, in _async_setup_platform
          await asyncio.gather(*pending)
        File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 295, in async_add_entities
          await asyncio.gather(*tasks)
        File "/usr/src/homeassistant/homeassistant/helpers/entity_platform.py", line 446, in _async_add_entity
          entity.async_write_ha_state()
        File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 297, in async_write_ha_state
          self._async_write_ha_state()  # type: ignore
        File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 326, in _async_write_ha_state
          unit_of_measurement = self.unit_of_measurement
        File "/usr/src/homeassistant/homeassistant/components/mysensors/sensor.py", line 92, in unit_of_measurement
          float(self.gateway.protocol_version) >= 1.5
      ValueError: could not convert string to float: '2.1.1'
      
      posted in Home Assistant
      jocke4u
      jocke4u
    • Migrating from openHAB to Home Assistant

      Hi,

      I am migrating from openHAB to Home Assistant to today I took the the first steps towards MySensors network. MySensors are running in TCP mode on Arduino since a long time. I think I have 2.1.1 of MySensors...it have been so stable and have not patched it for a very long time.

      So installed the add-on and configured it as:

      mysensors:
        gateways:
          - device: '192.168.1.11'
            persistence_file: './mysensors.json'
            tcp_port: 5003
        optimistic: false
        persistence: true
        retain: true
      

      Restarted one sensor to ensure presentation but the only thing I get in HA logs is

      Log Details (WARNING)
      Logger: mysensors
      Source: __main__.py:356
      First occurred: 5:32:30 PM (20 occurrences)
      Last logged: 5:35:29 PM
      
      Node 49 is unknown
      Not a valid message: value must be float between 0.0 and 100.0 for dictionary value @ data['payload']
      Node 3 is unknown
      Node 4 is unknown
      

      Do you have any good hints/tips?

      posted in Home Assistant
      jocke4u
      jocke4u
    • GPS Tracker with Arduino

      Hi,

      Not really home automation related but still IoT ...
      I want to have a unit to place in the car to track the location.

      The unit shall boot when ignition is on in the car and start to track the location every approx 5 sec on a SD-card. Later this SD-card shall be "exported" to computer for driving journal.

      Since Arduino is quick in booting compared to Raspberry I primarily looking into Arduino - but can change to RPi.
      Though RPI has the advantage of SD-card built in and potential of WiFi to sync the data when at home.

      Do you have any good experience of GPS card and recommendation?
      I think I have at least one Arduino Mini and Nano available - but would it be better of with Uno, Mega,...or?

      Any tips and ideas are appreciated 🙂

      Regards
      Joacim

      posted in Hardware
      jocke4u
      jocke4u
    • Flood/water leak sensor

      Hey,

      I have a z-wave system (openHAB2) and mySensors network.
      Looking for a flood/water leakage sensors. Would need 3-4 sensors.

      Fibaro has a flood sensor but fairly expensive - what could be used instead with mySensors and/or z-wave?
      Ideas?

      / Joacim

      posted in Hardware
      jocke4u
      jocke4u
    • RE: openHAB 2.2 binding

      @timo Ok, so there is a plan to solve it in a better way than using rules?
      Do you have any guidance of using rules until then?

      posted in OpenHAB
      jocke4u
      jocke4u
    • RE: openHAB 2.2 binding

      @nickbuilder Check the code here and there is a SEND_FREQUENCY of 20 sec - would reduce the load quite a lot 🙂

      posted in OpenHAB
      jocke4u
      jocke4u
    • RE: openHAB 2.2 binding

      Hi @timo ,

      Here is the log when restarting the sensor:

      17:27:58.562 [DEBUG] [orsAbstractConnection$MySensorsReader] - Message from gateway received: 5;255;0;0;17;2.1.1
      17:27:58.573 [DEBUG] [ors.internal.gateway.MySensorsGateway] - Presentation Message received
      17:27:58.583 [WARN ] [ors.internal.gateway.MySensorsGateway] - Presented child is alredy present in gateway
      17:27:58.593 [DEBUG] [orsAbstractConnection$MySensorsReader] - Message from gateway received: 5;255;3;0;6;0
      17:27:58.603 [DEBUG] [ors.internal.gateway.MySensorsGateway] - I_CONFIG request received from M, answering: (is imperial?)false
      17:27:58.614 [DEBUG] [orsAbstractConnection$MySensorsWriter] - Sending to MySensors: 5;255;3;0;6;M
      17:27:58.674 [DEBUG] [orsAbstractConnection$MySensorsReader] - Message from gateway received: 5;255;3;0;11;Heater Energy
      17:27:58.682 [DEBUG] [orsAbstractConnection$MySensorsReader] - Message from gateway received: 5;255;3;0;12;2.0
      17:27:58.690 [DEBUG] [orsAbstractConnection$MySensorsReader] - Message from gateway received: 5;0;0;0;13;
      17:27:58.698 [DEBUG] [ors.internal.gateway.MySensorsGateway] - Presentation Message received
      17:27:58.705 [WARN ] [ors.internal.gateway.MySensorsGateway] - Presented child is alredy present in gateway
      17:27:58.719 [DEBUG] [orsAbstractConnection$MySensorsReader] - Message from gateway received: 5;0;2;0;24;
      17:27:58.727 [DEBUG] [ors.internal.gateway.MySensorsGateway] - Node 5 found in gateway
      17:27:58.735 [DEBUG] [ors.internal.gateway.MySensorsGateway] - Child 0 found in node 5
      17:27:58.743 [WARN ] [ors.internal.gateway.MySensorsGateway] - Request received, but variable state is not yet defined
      
      posted in OpenHAB
      jocke4u
      jocke4u
    • Power Sensor cannot get old pulse count from GW/OH2

      Hi,

      I have openHAB 2.2, Mysensors Ethernet GW 2.1.1 and a number of temperature sensors etc. I have issues to get my Power Sensor to work.

      It get stuck at reading the previous pulse count from GW/OH.

      The GW and the Power sensor is configured as:

      Bridge mysensors:bridge-eth:gateway [ ipAddress="192.168.1.11", tcpPort=5003, sendDelay=200 ] {
      	power 			sensor-air-pump-power 		[ nodeId=5, childId=0 ]	
      }
      

      The items looks like:

      Number CellarAirHeaterSensorWatt   "Airheater Watt" <energy> { channel="mysensors:power:gateway:sensor-air-pump-power:watt", mqtt=">[rabbitmq:/myhouse/airpump/sensor/power:state:*:Power,sensor=${itemName},location=airpump watt=${state} ]" }
      Number CellarAirHeaterSensorKwh    "Airheater Kwh" <energy>  { channel="mysensors:power:gateway:sensor-air-pump-power:kwh", mqtt=">[rabbitmq:/myhouse/airpump/sensor/power:state:*:Power,sensor=${itemName},location=airpump kwh=${state} ]" }
      Number CellarAirHeaterSensorVar    "Airheater Var" <energy>  { channel="mysensors:power:gateway:sensor-air-pump-power:var" }
      Number CellarAirHeaterSensorVar1   "Airheater Var1" <energy> { channel="mysensors:power:gateway:sensor-air-pump-power:var1" }
      Number CellarAirHeaterSensorVA     "Airheater VA" <energy>   { channel="mysensors:power:gateway:sensor-air-pump-power:va" }
      

      I have tested with different items to get it working.
      In the OH logs I see:

      2018-01-09 19:57:44.144 [DEBUG] [rs.internal.gateway.MySensorsGateway] - Node 5 found in gateway
      
      2018-01-09 19:57:44.147 [DEBUG] [rs.internal.gateway.MySensorsGateway] - Child 0 found in node 5
      
      2018-01-09 19:57:44.151 [WARN ] [rs.internal.gateway.MySensorsGateway] - Request received, but variable state is not yet defined
      
      2018-01-09 19:57:49.364 [DEBUG] [rsAbstractConnection$MySensorsReader] - Message from gateway received: 4;2;2;0;24;
      

      I cannot see the variable state being defined.

      What am I missing here?

      / Joacim

      posted in OpenHAB
      jocke4u
      jocke4u
    • RE: openHAB 2.2 binding

      I am moving the topic here as more appropriate 🙂 (old ref)

      I have OH v2.2 and latest MySensors 2.2.0 binding and my power sensors have stopped working.
      After some investigation it seems they cannot receive the old pulse count value and by that cannot start working.
      MySensors GW running 2.1.1 and the one power sensor I am testing also 2.1.1 (the rest 1.5.x)

      The debug (serial monitor) of the sensor shows that

      0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
      3 TSM:INIT
      4 TSF:WUR:MS=0
      11 TSM:INIT:TSP OK
      13 TSM:INIT:STATID=5
      14 TSF:SID:OK,ID=5
      16 TSM:FPAR
      52 TSF:MSG:SEND,5-5-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      2060 !TSM:FPAR:NO REPLY
      2062 TSM:FPAR
      2098 TSF:MSG:SEND,5-5-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      2983 TSF:MSG:READ,0-0-5,s=255,c=3,t=8,pt=1,l=1,sg=0:0
      2989 TSF:MSG:FPAR OK,ID=0,D=1
      4106 TSM:FPAR:OK
      4107 TSM:ID
      4108 TSM:ID:OK
      4110 TSM:UPL
      4147 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=NACK:1
      6154 TSM:UPL
      6159 TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=1,st=OK:1
      6168 TSF:MSG:READ,0-0-5,s=255,c=3,t=25,pt=1,l=1,sg=0:1
      6173 TSF:MSG:PONG RECV,HP=1
      6175 TSM:UPL:OK
      6177 TSM:READY:ID=5,PAR=0,DIS=1
      6182 TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
      6189 TSF:MSG:READ,0-0-5,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
      6232 !TSF:MSG:SEND,5-5-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=NACK:2.1.1
      6243 TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=1,st=OK:0
      6259 TSF:MSG:READ,0-0-5,s=255,c=3,t=6,pt=0,l=1,sg=0:M
      6305 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=11,pt=0,l=13,sg=0,ft=0,st=NACK:Heater Energy
      6349 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=1,st=NACK:2.0
      6391 !TSF:MSG:SEND,5-5-0-0,s=0,c=0,t=13,pt=0,l=0,sg=0,ft=2,st=NACK:
      6397 MCO:REG:REQ
      6435 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=3,st=NACK:2
      8476 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=4,st=NACK:2
      10486 TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=5,st=OK:2
      10493 TSF:MSG:READ,0-0-5,s=255,c=3,t=27,pt=1,l=1,sg=0:1
      10499 MCO:PIM:NODE REG=1
      10501 MCO:BGN:STP
      10528 TSF:MSG:SEND,5-5-0-0,s=0,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
      Got Pulse
      10534 MCO:BGN:INIT OK,TSP=1
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      No count received. Try requesting it again
      30570 !TSF:MSG:SEND,5-5-0-0,s=0,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=NACK:
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      No count received. Try requesting it again
      50546 TSF:MSG:SEND,5-5-0-0,s=0,c=2,t=24,pt=0,l=0,sg=0,ft=1,st=OK:
      Got Pulse
      

      The sketch looks like this:

      /**
       * 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
       */
      
      // Enable debug prints
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_NODE_ID 5
      #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 MAX_WATT 10000          // Max watt value to report. This filetrs outliers.
      
      #define CHILD_ID 0              // 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
      bool 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()
      {
       
        // 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();
      }
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Heater Energy", "2.0");
      
        // Register this device as power sensor
        present(CHILD_ID, S_POWER);
      }
      
      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 && sendTime) {
          // New watt value has been calculated
          if (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)) {
              send(wattMsg.set(watt));  // Send watt value to gw
            }
            Serial.print("Watt:");
            Serial.println(watt);
            oldWatt = watt;
          }
      
          // Pulse cout 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 count received. Try requesting it again
          Serial.println("No count received. Try requesting it again");
          request(CHILD_ID, V_VAR1);
          lastSend=now;
        }
      
      }
      
      void receive(const MyMessage &message)
      {
        Serial.print("MessageType:");
        Serial.println(message.type);
        Serial.print("Message:");
        Serial.println(message.getLong());
        if (message.type==V_VAR1) {
          pulseCount = oldPulseCount = message.getLong();
          Serial.print("Received last pulse count from gw:");
          Serial.println(pulseCount);
          pcReceived = true;
        }
      }
      
      void onPulse()
      {
        Serial.println("Got Pulse");
        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++;
      }
      

      Today I realized that I likely need to have item(s) created in OH to save the values - so created Var1 (and then added one after another with no success). Currently it looks like:

      Number CellarAirHeaterSensorWatt   "Airheater Watt" <energy> { channel="mysensors:power:gateway:sensor-air-pump-power:watt", mqtt=">[rabbitmq:/myhouse/airpump/sensor/power:state:*:Power,sensor=${itemName},location=airpump watt=${state} ]" }
      Number CellarAirHeaterSensorKwh    "Airheater Kwh" <energy> { channel="mysensors:power:gateway:sensor-air-pump-power:kwh", mqtt=">[rabbitmq:/myhouse/airpump/sensor/power:state:*:Power,sensor=${itemName},location=airpump kwh=${state} ]" }
      Number CellarAirHeaterSensorVar   "Airheater Var" <energy> { channel="mysensors:power:gateway:sensor-air-pump-power:var" }
      Number CellarAirHeaterSensorVar1   "Airheater Var1" <energy> { channel="mysensors:power:gateway:sensor-air-pump-power:var1" }
      Number CellarAirHeaterSensorVA   "Airheater VA" <energy> { channel="mysensors:power:gateway:sensor-air-pump-power:va" }
      

      Still no success!

      Do you have any idea what's wrong?

      posted in OpenHAB
      jocke4u
      jocke4u
    • RE: openHAB 2.2 binding

      Hi,

      I have issues with MySensors and specifically Energy Sensors where they request latest value.
      See this thread for details: https://forum.mysensors.org/topic/8833/power-sensors-stopped-working

      Any idea how to solve it?

      posted in OpenHAB
      jocke4u
      jocke4u
    • RE: Power sensors stopped working

      I guess so - using openHAB 2.2.0 stable and quite late snapshot mysensors-binding for 2.2.0.
      Maybe @TimO have an idea?

      posted in Development
      jocke4u
      jocke4u
    • RE: Power sensors stopped working

      I have been debugging a bit now and the sensor receives pulses but the issue seems to be that it doesn't receive the old pulse count from GW (Ethernet) and therefore doesn't send the values.

      I have upgraded the GW to 2.1.1 and with the sketch below

      /**
       * 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
       * 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 recieved. In inclusion mode will blink fast only on presentation recieved
       * - TX (yellow) - blink fast on radio message transmitted. In inclusion mode will blink slowly
       * - ERR (red) - fast blink on error during transmission error or recieve 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_NRF24
      //#define MY_RADIO_RFM69
      
      // 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 to UDP
      //#define MY_USE_UDP
      
      #define MY_IP_ADDRESS 192,168,1,11   // If this is disabled, DHCP is used to retrieve address
      // 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
      
      // 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 Ardunio 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()
      {
      }
      
      void loop()
      {
      }
      

      Do I need to have any other implementation to save pulses?

      The Sketch for the energy meter looks like below (currently some extra printout's):

      /**
       * 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
       */
      
      // Enable debug prints
      #define MY_DEBUG
      
      // Enable and select radio type attached
      #define MY_RADIO_NRF24
      //#define MY_RADIO_RFM69
      
      #define MY_NODE_ID 5
      #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 MAX_WATT 10000          // Max watt value to report. This filetrs outliers.
      
      #define CHILD_ID 0              // 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
      bool 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()
      {
       
        // 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();
      }
      
      void presentation()
      {
        // Send the sketch version information to the gateway and Controller
        sendSketchInfo("Heater Energy", "2.0");
      
        // Register this device as power sensor
        present(CHILD_ID, S_POWER);
      }
      
      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 && sendTime) {
          // New watt value has been calculated
          if (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)) {
              send(wattMsg.set(watt));  // Send watt value to gw
            }
            Serial.print("Watt:");
            Serial.println(watt);
            oldWatt = watt;
          }
      
          // Pulse cout 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 count received. Try requesting it again
          Serial.println("No count received. Try requesting it again");
          request(CHILD_ID, V_VAR1);
          lastSend=now;
        }
      
      }
      
      void receive(const MyMessage &message)
      {
        Serial.print("MessageType:");
        Serial.println(message.type);
        Serial.print("Message:");
        Serial.println(message.getLong());
        if (message.type==V_VAR1) {
          pulseCount = oldPulseCount = message.getLong();
          Serial.print("Received last pulse count from gw:");
          Serial.println(pulseCount);
          pcReceived = true;
        }
      }
      
      void onPulse()
      {
        Serial.println("Got Pulse");
        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 debug log looks like:

      0 MCO:BGN:INIT NODE,CP=RNNNA--,VER=2.1.1
      3 TSM:INIT
      4 TSF:WUR:MS=0
      11 TSM:INIT:TSP OK
      13 TSM:INIT:STATID=5
      14 TSF:SID:OK,ID=5
      16 TSM:FPAR
      52 TSF:MSG:SEND,5-5-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      2060 !TSM:FPAR:NO REPLY
      2062 TSM:FPAR
      2098 TSF:MSG:SEND,5-5-255-255,s=255,c=3,t=7,pt=0,l=0,sg=0,ft=0,st=OK:
      2983 TSF:MSG:READ,0-0-5,s=255,c=3,t=8,pt=1,l=1,sg=0:0
      2989 TSF:MSG:FPAR OK,ID=0,D=1
      4106 TSM:FPAR:OK
      4107 TSM:ID
      4108 TSM:ID:OK
      4110 TSM:UPL
      4147 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=0,st=NACK:1
      6154 TSM:UPL
      6159 TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=24,pt=1,l=1,sg=0,ft=1,st=OK:1
      6168 TSF:MSG:READ,0-0-5,s=255,c=3,t=25,pt=1,l=1,sg=0:1
      6173 TSF:MSG:PONG RECV,HP=1
      6175 TSM:UPL:OK
      6177 TSM:READY:ID=5,PAR=0,DIS=1
      6182 TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=15,pt=6,l=2,sg=0,ft=0,st=OK:0100
      6189 TSF:MSG:READ,0-0-5,s=255,c=3,t=15,pt=6,l=2,sg=0:0100
      6232 !TSF:MSG:SEND,5-5-0-0,s=255,c=0,t=17,pt=0,l=5,sg=0,ft=0,st=NACK:2.1.1
      6243 TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=6,pt=1,l=1,sg=0,ft=1,st=OK:0
      6259 TSF:MSG:READ,0-0-5,s=255,c=3,t=6,pt=0,l=1,sg=0:M
      6305 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=11,pt=0,l=13,sg=0,ft=0,st=NACK:Heater Energy
      6349 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=12,pt=0,l=3,sg=0,ft=1,st=NACK:2.0
      6391 !TSF:MSG:SEND,5-5-0-0,s=0,c=0,t=13,pt=0,l=0,sg=0,ft=2,st=NACK:
      6397 MCO:REG:REQ
      6435 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=3,st=NACK:2
      8476 !TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=4,st=NACK:2
      10486 TSF:MSG:SEND,5-5-0-0,s=255,c=3,t=26,pt=1,l=1,sg=0,ft=5,st=OK:2
      10493 TSF:MSG:READ,0-0-5,s=255,c=3,t=27,pt=1,l=1,sg=0:1
      10499 MCO:PIM:NODE REG=1
      10501 MCO:BGN:STP
      10528 TSF:MSG:SEND,5-5-0-0,s=0,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=OK:
      Got Pulse
      10534 MCO:BGN:INIT OK,TSP=1
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      No count received. Try requesting it again
      30570 !TSF:MSG:SEND,5-5-0-0,s=0,c=2,t=24,pt=0,l=0,sg=0,ft=0,st=NACK:
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      Got Pulse
      No count received. Try requesting it again
      50546 TSF:MSG:SEND,5-5-0-0,s=0,c=2,t=24,pt=0,l=0,sg=0,ft=1,st=OK:
      Got Pulse
      
      posted in Development
      jocke4u
      jocke4u
    • RE: How to set NodeID in 2.1.1

      Thanks - works just fine

      posted in Development
      jocke4u
      jocke4u
    • Power sensors stopped working

      Hi,

      I have 3 power sensors running (total, house heater and water heater). They have been working for a long time.
      Last weekend I had a power outage and they stopped working.
      Other sensors works.

      Watching in MYSController and power sensors reports V_VAR1 but message is empty.

      Any idea why?

      posted in Development
      jocke4u
      jocke4u
    • RE: How to set NodeID in 2.1.1

      Thanks, getting warnings that MY_NODE_ID is already declared

      #define MY_NODE_ID AUTO
      

      Is it a way to override that in a proper way?

      Tried:

      #ifndef MY_NODE_ID
      #define MY_NODE_ID 5 // my own ID is 5
      #endif
      

      Seems to work BUT is it correct way to do it?

      posted in Development
      jocke4u
      jocke4u
    • How to set NodeID in 2.1.1

      Hi,

      I have a mysensors network since a while and running 1.5 so now have started to upgrade to 2.1.1.

      In the sketches - how can I set the NodeID (not ChildNodeID)?

      / Joacim

      posted in Development
      jocke4u
      jocke4u
    • Getting "ver mismatch"

      Hi,

      I noticed that I am getting a lot of "ver mismatch"

      0;0;3;0;9;gateway started, id=0, parent=0, distance=0
      0;0;3;0;9;read: 0-0-0 s=0,c=0,t=0,pt=0,l=0,sg=0:
      0;0;3;0;9;ver mismatch
      0;0;3;0;9;read: 0-0-0 s=0,c=0,t=0,pt=0,l=0,sg=0:
      0;0;3;0;9;ver mismatch
      0;0;3;0;9;read: 0-1-0 s=0,c=0,t=0,pt=0,l=0,sg=0:
      0;0;3;0;9;ver mismatch
      ...etc
      

      The ethernet gateway is running Lib Ver 1.5 and sensors 1.4; is that the reason?

      How should I solve this?

      posted in Development
      jocke4u
      jocke4u
    • RE: Gateway stops working

      I hope it's resolved 🙂
      I had some extra hardware so bought a genuine Arduino Uno R3 which I assembled temporarily. It seems to work just fine.
      Different main board and different network card (still w5100).

      upload-69d27b1d-539e-4837-ab61-67e4271950a3

      The old gateway:
      upload-a0fc37e7-37b1-4232-b006-b88a0ceeed04

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Gateway stops working

      Nope...stopped again at 00:09 28/8

      • Faulty hardware?
      • Bug in the code?
      • Some other radio signal that breaks the gateway?
      • ...???
      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Gateway stops working

      Latest test, it was working from 07:55 25/8 to 17:06 27/8 (partly with MYSController connected but when it stopped)

      Now restarted it and 23:01 27/8 with MYSController connected.

      I love mysensors.org but stability is very important (no 1)

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Gateway stops working

      I have had it powered from http://www.electrokit.com/batterieliminator-312v-1500ma-stab-switchat.48611 but lately also tried Samsung USB charger....no difference.

      One noted difference this evening though....I had it completely offline (no power at all....OK maybe some from LAN) for approx 1h....and now it seems to run or at least so far.

      posted in Troubleshooting
      jocke4u
      jocke4u
    • Gateway stops working

      Hi,

      I have had my ethernet gateway (Arduino Uno, LAN sheild and NRF24L01+PA+LNA) up an running for some time and connected to Vera3.

      Then at some point I did a mistake and upgraded Vera to UI7 and after some few days I downgraded. Somewhere at this point I started to get problems with my gateway "stopping" but I cannot see the relation to upgrade/downgrade as such.

      Now I have the gateway on my desk and I can see problems.
      Either it doesn't care of handling of anything (nothing happens in output ...serial monitor) ....or it starts to process just fine and then it just stop (after a couple of minutes or longer). Nothing strange appears in the logs...it just stops.

      I have also tried to upgrade to v1.5 on gateway (not sensors) but the same problem.

      What is your guess?

      / Joacim

      posted in Troubleshooting
      jocke4u
      jocke4u
    • Video - "Getting Started with the nRF24L01 Transceiver"

      Found this:
      Getting Started with the nRF24L01 Transceiver – 14:06
      — ForceTronics

      posted in Hardware
      jocke4u
      jocke4u
    • RE: 230V power supply to Arduino

      @Hausner said:

      I have with succes used these:

      http://www.aliexpress.com/item/Travel-Convenient-EU-Plug-Wall-USB-Charger-Adapter-For-Samsung-Galaxy-S5-S4-S3-Note-3/32220133044.html

      They are really easy to dismatle, and the result is this - https://www.dropbox.com/s/ep43uyve5v0msv6/20141206_214210.jpg?dl=0

      At $1.10 I didn't even think about making my own PSU 🙂

      Yes, that is an option. I did it with one and it was pretty easy.

      Also found this https://github.com/openhardwarelabs/arduino-power-supply and I like some parts being isolated/encapsulated .

      https://raw.githubusercontent.com/openhardwarelabs/arduino-power-supply/master/pictures/IMG_8030.jpg

      posted in Hardware
      jocke4u
      jocke4u
    • 230V power supply to Arduino

      Hi,

      I have a number of sensors powered via 230V USB chargers and it works fine but I would like to have a similar power supply (great if encapsulated) with screw terminals to be placed in a small box.

      Do you have a good option to use? (and if it's easily available in Sweden it's very good 🙂 )

      posted in Hardware
      jocke4u
      jocke4u
    • AC 230V energy meter

      Hi,

      I have mounted a 3-phase energy meter on my water heater which has a S0 signal that I use in a modified version of http://www.mysensors.org/build/pulse_power
      It works just fine except for one small detail, it get stuck to the last watt value when it shuts off (0 watt) because no S0 signal and therefore no interrupt.
      The fix I have applied right now is to invalidate watt variable (set to 0) if it's more than 7 sec ago since last blink.

      I wonder if there are a better solution to this, do you have an idea?

      / Jocke

      posted in Development
      jocke4u
      jocke4u
    • RGBW LED strip current

      Hi,

      I have a stupid question 🙂 and since it's referenced in the "MySensor shop" I would like to post here 😉

      The LED strip on the "MySensor store" here http://rover.ebay.com/rover/1/711-53200-19255-0/1?icep_ff3=2&pub=5575069610&toolid=10001&campid=5337433187&customid=&icep_item=171158397695&ipn=psmain&icep_vectorid=229466&kwid=902099&mtid=824&kw=lg
      says

      Specifications:
      ● Color: RGBW Mixed
      ● View angle:120°
      ● Working Voltage: 24V DC
      ● LED Quantity: 300 leds/5 M(150pcs RGB LED and 150pcs White LED)
      ● Working Current/Meter: 6A
      ● Output power: 72W /5 Meter

      As I understand 5050 SMD LED have a standard power consumption of 0,24W/LED = 72W for the one above which seems ok. With 24V it should be 3 Amp for 5 m (72W/24V) and not 6A per meter as it says.

      Also it would be good to have a good recommendation on 12V LED driver as you also have 12V LED strips in the shop
      / Jocke

      posted in Hardware
      jocke4u
      jocke4u
    • RE: Unload/Load EEPROM

      @hek said:

      I doesn't. The node will try to fetch an id.

      Ok, thanks so then "You can safely revert to auto at a later stage." won't work if you previously had a static Node ID

      posted in Development
      jocke4u
      jocke4u
    • RE: Unload/Load EEPROM

      @hek said:

      No it does not write the static id to eeprom. You can safely revert to auto at a later stage.

      I have now replaced two sensors (from Uno -> Pro Mini) and used the begin(NULL, MY_CHILD_ID) to set the same Node Id and works fine.
      But I am not sure about what you wrote above.
      So if this won't be written to the EEPROM and if I change back the sketch to AUTO, how can it know the Node Id?

      posted in Development
      jocke4u
      jocke4u
    • RE: FTDI <=> Arduino Pro Mini

      @gregl said:

      i think on mine the solder pads are bridged... but i will check.

      I am pretty sure it's the same (5V as default) for me but will double check.

      posted in Hardware
      jocke4u
      jocke4u
    • RE: Unload/Load EEPROM

      Thanks for clarification. I will try it to see how it works.

      posted in Development
      jocke4u
      jocke4u
    • Unload/Load EEPROM

      Hi,

      Wouldn't it be useful to have a "Unload EEPROM" sketch to print the values in a readable manner and similar "Load EEPROM" where you can configure values to be written to EEPROM?

      Sample scenario
      If I have a Arduino sensor chip (let say a Nano) in use and I want to replace that with another (assume Pro Mini) but I don't want to have the device created again (in Vera).

      Another scenario could be if the node failed (e.g. stroke of lightning) but you have the EEPROM value to load.

      posted in Development
      jocke4u
      jocke4u
    • RE: FTDI <=> Arduino Pro Mini

      FYI
      I today received the new FTDI programmer referenced on this site (http://www.ebay.com/itm/320907184616) and now it works to program Pro Mini's 🙂

      posted in Hardware
      jocke4u
      jocke4u
    • RE: Light sensor calculation

      Ha 🙂 stupid me ...of course....thanks
      I however feel it get "0" (no light at all) with still some light and will remove that division to have a bit more "sensitivity".

      Would also be nice to have some comments in the source about these calculations to make it easier to understand the thought behind 😉

      posted in Development
      jocke4u
      jocke4u
    • Light sensor calculation

      Hi,

      I am looking at light sensor LM393 and wonder about the logic.

      int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
      

      First part ((1023-analogRead(LIGHT_SENSOR_ANALOG_PIN)) I understand the thinking to.... little light = low value and it's logical but for the division by 10.23 I cannot understand the reason.
      Can anyone enlighten me? 😉

      posted in Development
      jocke4u
      jocke4u
    • Dashboard

      Hi,

      A bit off of topic for this forum but related and some geeks hanging around 🙂 and I think others have interest in it.

      I have a Vera3 with MySensors and I would like to have a dashboard to be used on different devices but primarily a tablet and computer.
      Some initial non-functional requirements

      • Running in another place (on premise, not cloud), outside Vera and MySensors e.g. on the server (~24x7) or on a RPi (or similar)
      • Front end/UI to use HTML5 and JavaScript
      • Back end using Java (preferred but .NET can be considered)
      • Based on open source
      • Server side events (or similar) to update the UI e.g. when something happens (device turned on/off, energy consumption change,..)
      • ...and more

      I am not very much of a UI developer so wonder if you have stumbled upon some frameworks, guidance, examples, ..etc which can be a starting point ?

      I have seen this http://www.codeproject.com/Articles/616156/Simple-Dashboard but I guess there are more 🙂

      posted in General Discussion
      jocke4u
      jocke4u
    • RE: General advice

      @hek said:

      A question for everyone: Is there any Ethernet module working side-by-side with radio without tweaking SPI behavior? The ENC-module requires too much memory and the WizNet has problems hogging SPI.

      I bought SunFounder Uno + Ethernet shield and worked out of box
      http://www.ebay.com/itm/Sunfounder-UNO-R3-Ethernet-Schild-W5100-Starter-Kit-fur-Arduino-Mega-2560-Nano-/161382223691?pt=Wissenschaftliche_Geräte&hash=item2593214f4b

      posted in General Discussion
      jocke4u
      jocke4u
    • RE: Arduino 220V AC wattmeter

      @stofakiller said:

      I found module from DX that i want to try, i dont want to mess with 220v cables So i waiting for this one to come
      http://www.dx.com/p/yqj010504-single-phase-ac-current-sensor-module-w-active-output-deep-blue-5a-294209#.VDOyK2d_t8E

      Hmm, how can you get the 230V cable into the transformer without mess with it 😉
      You need to get a split core CT that you can open without touching high voltage lines; something like this (the blue one)
      http://openenergymonitor.org/emon/buildingblocks/ct-sensors-interface

      posted in My Project
      jocke4u
      jocke4u
    • RE: Ethernet Gateway problem

      My Ethernet Gateway doesn't show up in Netgear with Tomato firmware either but have not investigated why...
      But you can test if it's alive by ping command

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Perfboard and Arduino

      I also was soldering Arduino directly on board with wires but got crazy. Started to use pin headers for arduino + radio to be able to replace them easiliy and then I used a 3-lane strip board to be more easy to solder cables, capacitors etc

      upload-d1532ad4-ee64-4cb4-a295-3492f0d279fe
      http://www.conrad.com/ce/en/product/529618/WR-Rademacher-VK-C-790-5-Soldering-Strips-Grid-Board-WR-type-790-5-L-x-W-x-H-160-x-100-x-15-mm-Grid-pitch-254-mm-HP

      posted in Hardware
      jocke4u
      jocke4u
    • RE: Arduino 220V AC wattmeter

      I also have interest in building a AC watt meter and have been thinking of using a CT but maybe using a DIN module like this is better. Then getting the pulse and use the existing energy pulse sketch.

      Do you think this DIN module is more accurate than a CT?

      posted in My Project
      jocke4u
      jocke4u
    • RE: FTDI <=> Arduino Pro Mini

      I did the FTDI loop back test and so far I see the programmer doesn't work so ordered the one referenced on MySensors

      posted in Hardware
      jocke4u
      jocke4u
    • RE: FTDI <=> Arduino Pro Mini

      @bjornhallberg
      Thanks for the info/video, I will do another try before they go the same route as for @gregl ....trash bin 👎

      @hek I also have bought these from another Aliexpress supplier

      posted in Hardware
      jocke4u
      jocke4u
    • RE: Strange statstics with Ethernet GW and Vera

      @hek
      Yes I know about setVariableIfChanged preventing to set unchanged Vera variables but I log all setVariable calls (unless childId or serviceId is null) and have not seen this with serial GW so I thought Ethernet GW was sending duplicate messages.

      posted in Vera
      jocke4u
      jocke4u
    • RE: FTDI <=> Arduino Pro Mini

      @hek said:

      Are you guys saying they ship pro minis without any bootloader onboard?

      I have no idea but @gregl suspect that.

      posted in Hardware
      jocke4u
      jocke4u
    • Arduino and IoT with MQTT/Cloud @ IBM

      Hi,

      I saw IBM have published a interesting article
      Part 1: http://www.ibm.com/developerworks/cloud/library/cl-bluemix-arduino-iot1/index.html
      Part 2: http://www.ibm.com/developerworks/cloud/library/cl-bluemix-arduino-iot2/index.html
      Part 3: http://www.ibm.com/developerworks/cloud/library/cl-arduino-iot3-app/index.html
      Part 4: http://www.ibm.com/developerworks/cloud/library/cl-arduino-iot4-app/index.html

      posted in General Discussion
      jocke4u
      jocke4u
    • RE: FTDI <=> Arduino Pro Mini

      @gregl
      I just had to do a quick test and it seems that I have similar problem.
      Tested all 5 pro minis I have with the same result

      avrdude: stk500_recv(): programmer is not responding
      avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x01
      

      upload-fd2d47c9-ab25-476c-a7c4-19bd7f4135e9

      posted in Hardware
      jocke4u
      jocke4u
    • Strange statstics with Ethernet GW and Vera

      Hi,

      I experience some strange behavior with Vera3 and Ethernet GW.

      A little background

      In order to understand and collect some statistics of my sensor network I have hacked L_Arduino.lua in Vera3 to log values received by MySensor GW and timestamp.

      Change in L_Arduino.lua

      local function setVariable(incomingData, childId, nodeId)
          if (childId ~= nil) then
              -- Set variable on child sensor.
              local index = tonumber(incomingData[5]);
              local varType = tVarLookupNumType[index]
              local var = tVarTypes[varType]
              local value = incomingData[6]
              local timestamp = os.time()
              if (var[2] ~= nil) then 
                  log("Setting variable '".. var[3] .. "' to value '".. value.. "'")
                  setVariableIfChanged(var[2], var[3], value, childId)
          
                  -- Handle special variables battery level and tripped which also
                  -- should update other variables to os.time()
                  if (varType == "TRIPPED" and value == "1") then
                      local variable = tVeraTypes["LAST_TRIP"]
                      setVariableIfChanged(variable[2], variable[3], timestamp, childId)
                  else
                      local variable = tVeraTypes["LAST_UPDATE"]
                      setVariableIfChanged(variable[2], variable[3], timestamp, childId)
                  end
                  -- Start Jocke: adding statistics logging
                  local file = io.open("/dataMine/JJLogs/JockeMonitor_"..childId.."_"..var[3]..".log", "a")
                  file:write(timestamp.."\t"..value.."\n")
                  file:close()
                  -- End Jocke
              end
              //...snip...
          end
      end
      

      Then I can copy the data into Excel to do some very simple analysis e.g. see if no transmission was received as expected.
      The sensor used in this scenario is EnergyPulseSensor which send every 20 sec (not comparing the previously value for the test) so 20 sec between transmissions is expected (but tolerate up to 23 sec). Quite often I can see 40, 60 and in this case the transmission failed 1 or 2 times. Also I have got values in between e.g. 29 sec which can indicate that GW (or something is under heavy load)

      So to the issue...
      Yesterday I assembled a prototype for Ehernet GW to replace my current serial GW and let it run over night.
      I can now see quite many "duplicated" values i.e. time from previous is 0 but it's not consistent.
      This doesn't happen with serial GW so I suspect Ethernet GW calling setVariable(..) several times
      See Excel file
      Test5MySensors.xlsx

      Any idea? A bug?

      posted in Vera
      jocke4u
      jocke4u
    • FTDI <=> Arduino Pro Mini

      Hi,

      I have a couple of Arduino Pro Mini's and FTDI chip but have not used this programmer and to make sure I connect it correctly.

      It seems to be straight ahead but a bit puzzled about CTS and GND since Pro Mini have two connections marked GND. Shall I just leave CTS or how to connect it?

      From top:

      Pro Mini      FTDI
      --------      ------
      GND      <=>  GND
      ???      <=>  CTS
      VBUS     <=>  VCC
      RX       <=>  TX
      TX       <=>  RX
      DTR      <=>  DTR
      

      upload-01a14cf6-0b7e-44c8-b64f-d47332465c3d

      posted in Hardware
      jocke4u
      jocke4u
    • RE: Wiring a separate power supply for the radio

      Hi,
      I think this is a good thread since power supply seems to be the most tricky one in this. Shouldn't it be possible to have a "reference architecture" for power supply to eliminate 80-90% of the issues people (including me) run into?!

      I made some tests on a problematic sensor yesterday and sicne I use NRF24L01+PA+LNA (Antenna version) I added 5V external supply and AMS1117 5V-3.3V Step Down Module, with IRQ connected over 10k resistor but got a number of problems e.g. MySensors complaining "check wires". Maybe it's possible/ok (the logic detecting presence of the radio) if the radio isn't alive before Arduino starts?!

      Got tired of it and setup a new sensor...

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Reliability again

      @hek said:

      Strange. Is the sensor still "spamming" the gateway?

      Damn, I made the fix but because of a stupid reason I uploaded the old version 😞
      I have now loaded a limited software with only EnergyPulseMeter, it partly works but I get too many "fail" when sending (even though many reaches GW).
      As next step I think I need to connect an external 5V power supply and AMS1117 to feed the radio and hopefully get better reliability in transmits.
      I guess no extra capacitor is needed due to 800mA max current?

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Reliability again

      @blacey said:

      The best place to set the power level is in MyConfig.h.

      I am not sure if I agree if you have different sensors with different hardware (as I have) since changing MyConfig.h will change it globally.

      @tbully
      I have used this code:

      gw.begin(incomingMessage, AUTO, false, AUTO, RF24_PA_LOW);
      

      Since the PA parameter is the fourth one, you need to set the ones before (but go with defaults for the ones after)

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Reliability again

      @hek
      Thanks for the fix.
      I have implemented it but still the gateway hangs when sending the requested KWH value to the sensor. Doesn't it have any timeout etc?

      I have also implemented the fix + lowered PA. Still not working.

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Reliability again

      @hek
      I have amplified version on both Gateway and this sensor (NodeID 1). Both have 47 uF capacitor. I have used RF24_PA_LOW explicitly before but with 1.4 that is the default but I now see it's only for gateway but sensors uses RF24_PA_MAX as default, right? I guess that is because most sensors doesn't use amplified version.
      Will change the sensor code to start with.

      I guess the other sensors stops working because gateway fails on sending Variable1 and hangs?!

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Reliability again

      For correctness and to read the log the sensors have these Node/Child IDs

      • NodeID 1 with energy pulse meter (ChildID 1) and temperatures (ChildID 2 and 3), always sending every 20 sec
      • NodeID 2 with light (ChildID 0) and temperature (ChildID 1), send changed values every 30 sec
      • NodeID 4 with DHT22 i.e. temperature (ChildID 1) and humidity (ChildID 0), send changed values every 30 sec

      Attached log file from Vera3 where Vera3 was reloaded and gateway was stuck on "Sending: 1;1;1;0;24;331604" so Gateway was rebooted 11:47:07.468 and again stucked with the same.

      LuaUPnP.log

      posted in Troubleshooting
      jocke4u
      jocke4u
    • Reliability again

      Since I don't want to hijack @ServiceXp thread I create a new one.

      I have executed the serial gateway for some weeks now and have had the following sensors connected:

      1. Node 1 with energy pulse meter, always sending every 20 sec
      2. Node 2 with light and temperature, always send every 30 sec
      3. Node 2 with DHT22 (temp and humidity), always send every 30 sec

      All of them ignored the previous value and always send. I log all events to file with timestamp and can see if they got to Vera3 in time of not.
      This led to slow-down of previously successful measurements from (1), probably from gateway's single thread handling. Changed (2) and (3) to only send changed values and (1) got almost 100% sends successful (a few took longer time).

      So I felt it being quite OK to implement in "production" so, on (1) I added two DS18B20 and on the desk and included them without any problem. Sure the temperature logged as it should but energy meter didn't because no sensor connected. Mounted them in a enclosure and everything mounted it at almost the same location as before.

      Then nothing except for the first message arrives and it seems to lock at (from Vera):

      50      09/14/14 21:28:04.096   luup_log:97: Arduino: Requesting status for: 1;1 <0x2ea2b680>
      50      09/14/14 21:28:04.096   luup_log:97: Arduino: Request status for Variable1 <0x2ea2b680>
      50      09/14/14 21:28:04.097   luup_log:97: Arduino: Sending: 1;1;1;0;24;330127 <0x2ea2b680>
      

      So I feel this being a lot time consuming (even though fun) but still would like to see it more stable.
      Should be mentioned that ALL other sensors stopped working when doing this change.

      I like this project a lot but even for a geek it can be too much problems based on invested time.

      I will get the stuff ready for my ethernet gateway as next step...

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Migrate from Serial Gateway to Ethernet Gateway

      Great, thanks for info 🙂

      posted in Vera
      jocke4u
      jocke4u
    • Migrate from Serial Gateway to Ethernet Gateway

      Hi,

      I have ordered some new hardware to start using Ethernet Gateway instead of Serial Gateway.
      So will base the Ethernet GW on Arduino Uno instead of current Nano
      Therefore I wonder if any special actions are needed e.g. if the GW stores any values in EEPROM etc

      1. Assembly the hardware
      2. Load software
      3. Connect to LAN and boot it up
      4. Disconnect Serial GW
      5. Configure Vera3 plugin to use Ethernet GW's IP/Port
      6. Sensors will find the new GW, or??
      posted in Vera
      jocke4u
      jocke4u
    • RE: Issue with temperature units

      Thanks @hek and @Yveaux I can confirm it's working on both Dallas sensor and DHT22.
      Great support!!

      posted in Vera
      jocke4u
      jocke4u
    • RE: Issue with temperature units

      Sounds good anyway....one bug less 🙂
      I just setup a sensor with DHT22/AM2302 and get the same results here.

      posted in Vera
      jocke4u
      jocke4u
    • RE: Issue with temperature units

      @hek

      Yes for some strange reason 🙂
      However I used %s and not %d in the debug but have now used %d as below

      } else if (type == I_CONFIG) {
          // Pick up configuration from controller (currently only metric/imperial)
          // and store it in eeprom if changed
          isMetric = msg.getByte() == 'M' ;
          debug(PSTR("isMetric=%d\n"), isMetric);
          debug(PSTR("cc.isMetric=%d\n"), cc.isMetric);
          if (cc.isMetric != isMetric) {
              cc.isMetric = isMetric;
              debug(PSTR("Updating EEPROM\n"));	
              debug(PSTR("isMetric=%d\n"), isMetric);	
              debug(PSTR("cc.isMetric=%d\n"), cc.isMetric);						
              eeprom_write_byte((uint8_t*)EEPROM_CONTROLLER_CONFIG_ADDRESS, isMetric);
              //eeprom_write_block((const void*)&cc, (uint8_t*)EEPROM_CONTROLLER_CONFIG_ADDRESS, sizeof(ControllerConfig));
          }
      

      Gives the output

      sensor started, id 2
      send: 2-2-0-0 s=255,c=0,t=17,pt=0,l=3,st=ok:1.4
      send: 2-2-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
      read: 0-0-2 s=255,c=3,t=6,pt=0,l=2:M
      isMetric=0
      cc.isMetric=1
      Updating EEPROM
      isMetric=0
      cc.isMetric=0
      

      So it seems that "metric" flag is not unpacked correctly, or?

      posted in Vera
      jocke4u
      jocke4u
    • RE: Issue with temperature units

      I have the same problem with DallasSensor

      Startup says:

      sensor started, id 2
      send: 2-2-0-0 s=255,c=0,t=17,pt=0,l=3,st=ok:1.4
      send: 2-2-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
      read: 0-0-2 s=255,c=3,t=6,pt=0,l=2:M                          <<<==== Metric <<<
      send: 2-2-0-0 s=255,c=3,t=11,pt=0,l=17,st=ok:Light+Temp Sensor
      send: 2-2-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
      send: 2-2-0-0 s=0,c=0,t=16,pt=0,l=3,st=ok:1.4
      

      And I trace:

      Serial.println(gw.getConfig().isMetric);
      

      which output 0, not 1

      Switching to Imperial I get:

      sensor started, id 2
      send: 2-2-0-0 s=255,c=0,t=17,pt=0,l=3,st=ok:1.4
      send: 2-2-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
      read: 0-0-2 s=255,c=3,t=6,pt=0,l=2:I                          <<<==== Imperial <<<
      send: 2-2-0-0 s=255,c=3,t=11,pt=0,l=17,st=ok:Light+Temp Sensor
      

      and the trace says 0 as expected.

      Then I tried to trace in MySensors.cpp and added (not workin though 😉 😞

      } else if (type == I_CONFIG) {
          // Pick up configuration from controller (currently only metric/imperial)
          // and store it in eeprom if changed
          isMetric = msg.getByte() == 'M' ;
          debug(PSTR("isMetric=%s\n"), isMetric);
          debug(PSTR("cc.isMetric=%s\n"), cc.isMetric);
          if (cc.isMetric != isMetric) {
      

      But then it started to work 😄

      Removed the lines above and the problem is back....so something there...
      Don't have time right now to test....

      posted in Vera
      jocke4u
      jocke4u
    • RE: Radio problems

      DAMN 😞 😞
      I think dataMine played a prank on me and the statistic is probably not correct (not logging everything). Will hook in my MQTT monitor to extract statistics in a way I control it.
      Currently I am running 1.3b3 and will run a test sensor for a while to see how it's works and then eventually go for 1.4 again.
      Thanks for your support and I have learnt more about power and capacitors 🙂

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Radio problems

      @ServiceXp
      I have had 1.3b before but without capacitor etc.
      Maybe time to go back to 1.3b3, to see if that works better.

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Radio problems

      Hi again,
      First I would like to thank you all for the support/ideas etc and I really want to get sensors stable and reliable. Sure this EnergyMeterPulseSensor is not the most critical one and sure the sketch can be improved not to loose KWH readings/accumulations (Watts is a snapshot) when send fails. But with more critical sensors where something else is triggered.
      Anyway, since I have problem with the EnergyMeterPulseSensor sending data (not counting pulses) I need to get that working and set the "foundation" for future sensors. Sure I have some other test sensors...

      Yesterday I took the following actions.
      EnergyMeterPulseSensor

      • Reverted back to NRF24L01+ due to lower power consumtion
      • Still using 47 uF capacitor to radio power
      • Reverted back to the standard code with gw.begin(incomingMessage); (not using RF24_PA_LOW)

      Gateway

      • Still using NRF24L01+PA+LNA
      • Still using 47 uF capacitor to radio power
      • Added AMS1117 5V-3.3V Step Down Module connected to a separate USB charger feeding the radio
      • Reverted back to the standard code with gw.begin(); not using RF24_PA_LOW

      But unfortunately no success.

      So I wonder what you have as hardware reference architecture;

      • Do you have a verified and reliable solution?
      • What components do you use?
      • What working distance do you have between gateway-sensors ?

      Regards
      Joacim

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Radio problems

      Thank you for all your answers.
      I think I have a couple of "AMS1117 5V-3.3V Step Down Module" (or similar) that I can connect to a USB charger. Need to verify though.
      http://www.ebay.com/itm/261172232237 says "output: 3.3 V, 800 mA"

      Some hacks to do 🙂

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Radio problems

      @ServiceXp

      How are you powering the sensor? Is there a step-up regulator involved?

      See below. The Arduino board is Nano.

      @bjornhallberg said:

      I'd also like to know how you power your sensor node ... if it is some regulator from batteries or some wall wart?

      I am using a USB charger and have tested some different ones (Samsung's SGS2, iPhone, aftermarket) but I have to admit that those tests have not been very scientific. Now I am doing one change at time and let the device run for a couple of hours.

      The statistics I have pulled is from dataMine in Vera3 which logs this variable change and therefore I allow extra 2 sec for OK result. Most of OK tests happens on 20 sec (as the sensor sends every 20 sec) but many is 40 sec which means that the previous send failed. The statistics this morning was worse (over 10% failed) that previously posted so I am not sure whether the large capacitor helped.

      I also increased the capacitor on gateway to 47uF

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Radio problems

      @gregl said:

      -What is the universal PCB you mention?

      It is like this http://www.kjell.com/sortiment/el/elektronik/monsterkort/experimentkort/experimentkort-lankar-p89417

      Then I have soldered female header socket pins so I can replace Arduino and radio and also have screw terminals for the sensor.
      http://www.ebay.co.uk/itm/2x6pin-4x8pin-2x10pin-Single-Row-Header-Socket-Connector-Kit-for-Arduino-DIY-/151372711839?pt=UK_BOI_Industrial_Automation_Control_ET&hash=item233e84479f

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Radio problems

      @bjornhallberg

      1. Yes, I read that in the troubleshooting section http://www.mysensors.org/build/debug
      2. I read about another guy in thread http://forum.mysensors.org/topic/309/1-4b-radio-transmission-problem-not-present-in-1-3b/16 where he tested 22uF without success but 47 uF worked, so I did the same today. No success but then I restarted the gateway and it started to send/receive. Yes, I am using electrolytic capacitor. Is ceramic better?
      3. Sure the quality can be questioned sometimes but it seems to work. I have just ordered two additional NRF24L01+PA+LNA just in case 🙂
      4. It's not very good if the reception is a lot different based on radio orientation, especially if NRF24L01+PA+LNA is used (~1000m distance) in this short distance
      5. I have pretty short cables. Everything mounted on universal PCB with header pin connector and short cables. The cables are maybe not the best; used a stripped cat5e
      6. Can be something to investigate if no success in other labs

      The current setup have not yet been operated for that long time but it looks better:

      Messages received in interval (sensor sends every 20 sec so 2 sec tolerance)
      0-22 sec          181    91,4%
      23-40 sec          16    8,1%
      41-100 sec          1    0,5%
      101-100000 sec      0    0,0%
      Total messages    198    100,0%
      

      Maybe I should increase the capacitor on gateway to 47uF as well....

      posted in Troubleshooting
      jocke4u
      jocke4u
    • RE: Radio problems

      @hek No, only the sensor TSL257. Arduino and Radio currently on the firewood in the garage 🙂

      @Yveaux Sure that can be one way to sniff the traffic, but isn't a bit strange it finds its way with small NRF24L01+ but not with antenna one?!

      posted in Troubleshooting
      jocke4u
      jocke4u
    • Radio problems

      Hi,

      I have a EnergyPulseMeter in the garage with NRF24L01+ but statistics shows that quite many (~14%) send fails.
      The gateway have NRF24L01+PA+LNA (Antenna version) and connected to Vera.
      It's two inner walls and one outer (brick) wall between the sensor and gateway.

      I have also added a 4.7uF capacitor over the 3.3V and GND pins on both gateway and sensor.

      I have now tested gateway with:
      gw.begin(RF24_PA_LOW);
      which led to little improvement (12% lost messages) with NRF24L01+ on sensor which is too much to my opinion.

      So I am trying to change to NRF24L01+PA+LNA (Antenna version) on the sensor as well.
      It didn't work so I added the similar code to sensor:
      gw.begin(incomingMessage, AUTO, false, AUTO, RF24_PA_LOW);

      But still no success..

      (FYI, I tested the radio on the desk and it works and I am using 1.4b1)

      Do you have any idea what to do?

      posted in Troubleshooting
      jocke4u
      jocke4u