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

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. Troubleshooting
  3. Energy Meter - not sending at expected

Energy Meter - not sending at expected

Scheduled Pinned Locked Moved Troubleshooting
18 Posts 4 Posters 4.8k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mfalkviddM mfalkvidd

    @flopp could you post serial output from the node, including the startup phase after a reset?

    F Offline
    F Offline
    flopp
    wrote on last edited by flopp
    #3

    @mfalkvidd

    1.5.1

    send: 17-17-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.1
    send: 17-17-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
    read: 0-0-17 s=255,c=3,t=6,pt=0,l=1,sg=0:M
    sensor started, id=17, parent=0, distance=1
    send: 17-17-0-0 s=255,c=3,t=11,pt=0,l=12,sg=0,st=ok:Energy Meter
    send: 17-17-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
    send: 17-17-0-0 s=1,c=0,t=13,pt=0,l=0,sg=0,st=ok:
    send: 17-17-0-0 s=1,c=2,t=24,pt=0,l=0,sg=0,st=ok:
    read: 0-0-17 s=1,c=2,t=24,pt=0,l=10,sg=0:1845100810
    Received last pulse count from gw:1845100810
    send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:64
    Watt:64
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:1845100814
    send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:184510.0800
    send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:63
    Watt:63
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:1845100817
    send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:64
    Watt:64
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:1845100821
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:1845100824
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:1845100828
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:1845100831
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:1845100835
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:1845100839
    send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:63
    Watt:63
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:1845100842
    send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:64
    Watt:64
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:1845100846
    read: 0-0-17 s=1,c=2,t=24,pt=0,l=10,sg=0:1845100810
    Received last pulse count from gw:1845100810
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=fail:1845100813
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=fail:1845100817
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=fail:1845100820
    read: 0-0-17 s=1,c=2,t=24,pt=0,l=10,sg=0:1845100810
    Received last pulse count from gw:1845100810
    send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=fail:1845100813
    

    looks strange, why does ask for VAR1 again

    Domoticz Log

    2016-09-07 06:57:04.773 MySensors: Node: 17, Sketch Name: Energy Meter
    2016-09-07 06:57:04.845 MySensors: Node: 17, Sketch Version: 1.0
    2016-09-07 06:57:25.013 (MySensors USB) General/kWh (PannaMeter)
    2016-09-07 06:57:25.142 (MySensors USB) General/kWh (PannaMeter)
    2016-09-07 06:57:45.013 (MySensors USB) General/kWh (PannaMeter)
    2016-09-07 06:58:05.012 (MySensors USB) General/kWh (PannaMeter)
    2016-09-07 06:58:35.651 (MySensors USB) Temp (KökTbx_T)
    2016-09-07 06:58:35.712 (MySensors USB) Temp (UppTbx_T)
    2016-09-07 06:58:35.756 (MySensors USB) Temp (KökUt_T)
    2016-09-07 06:58:35.797 (MySensors USB) Temp (ToaUt_T)
    2016-09-07 06:58:35.838 (MySensors USB) Temp (EfterPump_T)
    2016-09-07 06:58:35.878 (MySensors USB) Temp (HallTbx_T)
    2016-09-07 06:58:35.918 (MySensors USB) Temp (UppUt_T)
    2016-09-07 06:58:35.958 (MySensors USB) Temp (ToaTbx_T)
    2016-09-07 06:58:35.997 (MySensors USB) Temp (Kök_T)
    2016-09-07 06:58:36.036 (MySensors USB) Temp (PannaKomp_T)
    2016-09-07 06:58:36.075 (MySensors USB) Temp (HallUt_T)
    2016-09-07 06:58:36.115 (MySensors USB) Temp (Tvätt_T)
    2016-09-07 06:58:36.154 (MySensors USB) Temp (T12_T)
    2016-09-07 06:58:36.193 (MySensors USB) Temp (VMellan_T)
    2016-09-07 06:58:36.233 (MySensors USB) Temp (Hallen_T)
    2016-09-07 06:58:36.272 (MySensors USB) Temp (PannaEl_T)
    2016-09-07 06:58:36.311 (MySensors USB) Temp (ToaNere_T)
    2016-09-07 06:58:36.350 (MySensors USB) Temp (VarmVatten_T)
    2016-09-07 06:58:40.106 (MySensors USB) Temp (KylUppe_T)
    2016-09-07 06:58:41.190 (MySensors USB) Temp (KylMitten_T)
    2016-09-07 06:58:41.230 (MySensors USB) Temp (KylNere_T)
    2016-09-07 06:58:41.269 (MySensors USB) Temp (FrysUppe_T)
    2016-09-07 06:58:41.309 (MySensors USB) Temp (KylBakom_T)
    2016-09-07 06:58:41.387 (MySensors USB) Temp (Allrum_T)
    2016-09-07 06:58:41.465 (MySensors USB) Temp (SovrumOW_T)
    2016-09-07 07:00:02.496 Starting automatic database backup procedure...
    2016-09-07 07:00:18.899 Ending automatic database backup procedure...
    2016-09-07 07:00:05.013 (MySensors USB) General/kWh (PannaMeter)
    2016-09-07 07:00:25.014 (MySensors USB) General/kWh (PannaMeter)
    2016-09-07 07:01:01.239 (MySensors USB) General/Voltage (VinglasSkapet_V)
    2016-09-07 07:01:01.353 (MySensors USB) Temp + Humidity (VinglasSkapet_T)
    2016-09-07 07:01:01.428 (MySensors USB) Temp + Humidity (VinglasSkapet_T)
    2016-09-07 07:01:06.073 (MySensors USB) Rain (Hyundai)
    2016-09-07 07:01:08.160 (MySensors USB) Rain (Hyundai)
    2016-09-07 07:01:16.177 (MySensors USB) General/kWh (MeterHuset)
    2016-09-07 07:01:16.242 (MySensors USB) General/kWh (MeterHuset)
    2016-09-07 07:01:59.706 (MySensors USB) General/Voltage (BadrumNere_V)
    2016-09-07 07:01:59.828 (MySensors USB) Temp (Temp)
    2016-09-07 07:01:59.908 (MySensors USB) Humidity (Hum)
    2016-09-07 07:02:05.016 (MySensors USB) Temp (AppleTV_T)
    2016-09-07 07:02:05.115 (MySensors USB) Temp (PS3_T)
    2016-09-07 07:02:05.229 (MySensors USB) Temp (Stereo_T)
    

    Yes I a lot of temp senors :)

    1 Reply Last reply
    0
    • F Offline
      F Offline
      flopp
      wrote on last edited by
      #4

      after I changed pulseCount to be 100000 it looks better

      serial output

      send: 17-17-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.1
      send: 17-17-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0
      read: 0-0-17 s=255,c=3,t=6,pt=0,l=1,sg=0:M
      sensor started, id=17, parent=0, distance=1
      send: 17-17-0-0 s=255,c=3,t=11,pt=0,l=12,sg=0,st=ok:Energy Meter
      send: 17-17-0-0 s=255,c=3,t=12,pt=0,l=3,sg=0,st=ok:1.0
      send: 17-17-0-0 s=1,c=0,t=13,pt=0,l=0,sg=0,st=ok:
      send: 17-17-0-0 s=1,c=2,t=24,pt=0,l=0,sg=0,st=ok:
      read: 0-0-17 s=1,c=2,t=24,pt=0,l=6,sg=0:100000
      Received last pulse count from gw:100000
      send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:62
      Watt:62
      send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100004
      send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0004
      send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100007
      send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0007
      send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:63
      Watt:63
      send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100010
      send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0010
      send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:62
      Watt:62
      send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100014
      send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0014
      send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100017
      send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0017
      send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100021
      send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0021
      send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:63
      Watt:63
      send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100024
      send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0024
      send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100028
      send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0028
      send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:62
      Watt:62
      send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100031
      send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0031
      
      

      DZ log

      2016-09-07 08:30:15.154 MySensors Node 17 Sketch Name Energy Meter
      2016-09-07 08:30:15.223 MySensors Node 17 Sketch Version 1.0
      2016-09-07 08:30:35.397 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:30:35.526 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:30:55.461 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:31:15.398 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:31:15.524 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:31:16.867 (MySensors USB) General/kWh (MeterHuset)
      2016-09-07 08:31:16.924 (MySensors USB) General/kWh (MeterHuset)
      2016-09-07 08:31:35.398 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:31:35.529 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:31:55.462 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:32:15.459 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:32:35.397 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:32:35.527 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:32:55.463 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:33:15.397 (MySensors USB) General/kWh (PannaMeter)
      2016-09-07 08:33:15.530 (MySensors USB) General/kWh (PannaMeter)
      
      1 Reply Last reply
      0
      • F Offline
        F Offline
        flopp
        wrote on last edited by
        #5

        after a while I got this

        send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100116
        send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0116
        send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:62
        Watt:62
        send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100119
        send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0119
        read: 51-51-51 s=1,c=2,t=24,pt=0,l=6,sg=0:100063
        ver mismatch
        read: 0-0-0 s=1,c=2,t=24,pt=0,l=0,sg=0:
        ver mismatch
        send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:63
        Watt:63
        send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100123
        send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0123
        

        what is 51-51-51 and that is also wrong VAR value

        sundberg84S 1 Reply Last reply
        0
        • F flopp

          after a while I got this

          send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100116
          send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0116
          send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:62
          Watt:62
          send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100119
          send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0119
          read: 51-51-51 s=1,c=2,t=24,pt=0,l=6,sg=0:100063
          ver mismatch
          read: 0-0-0 s=1,c=2,t=24,pt=0,l=0,sg=0:
          ver mismatch
          send: 17-17-0-0 s=1,c=1,t=17,pt=5,l=4,sg=0,st=ok:63
          Watt:63
          send: 17-17-0-0 s=1,c=1,t=24,pt=5,l=4,sg=0,st=ok:100123
          send: 17-17-0-0 s=1,c=1,t=18,pt=7,l=5,sg=0,st=ok:10.0123
          

          what is 51-51-51 and that is also wrong VAR value

          sundberg84S Offline
          sundberg84S Offline
          sundberg84
          Hardware Contributor
          wrote on last edited by sundberg84
          #6

          @flopp pulseCount/V_VAR1 and Domoticz is something else... I have not got my finger around it but what I know is that some values in the energi meter is calculacted from V_VAR1 / day. When i tested my rain sensor (tip_bucket) i pretty much have to do 1 test each day to be sure. Also there is the possibility to edit the database but as i said, im not sure.

          If you had a pulsecount of 1000 and set it to 0 it would show -1000 in watts i think or something... but only calculated the pulse from that day.
          Sorry, not bringing anything good to the table, just remember it was a bit hard to get my head around.

          Controller: Proxmox VM - Home Assistant
          MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
          MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
          RFLink GW - Arduino Mega + RFLink Shield, 433mhz

          F 1 Reply Last reply
          0
          • F Offline
            F Offline
            flopp
            wrote on last edited by flopp
            #7

            a few thing that can be my error.

            1. I had one beginner mistake, no cap on NRF thats why it was getting Failed a few times, this happened after 0-10 minutes and during my first setup it was 5 minutes to send.
              New NRF and Cap seems to solve one issue. Sorry
            2. I noticed if the Watt is sent it will update Domoticz. If VAR is sent it will not update Domoticz. If kwh is sent it will update Domoticz.
            3. skectch is checking if kwh was same as old, the check is only handling 2 decimals(what is can see in SerialPrint) so I needed a lot of watts to change second decimal. 1845110734 is my VAR but the IF code is only seeing 184511.07

            summary

            Bad NRF, it was working a few minutes. Biggest error
            My watt was same, heating system and right now it doesn't heat = dont send
            My kwh was increasing slowly = don't send

            I think I will remove the check if value is old and send it every 5 minutes even if watt, kwh, pulsecount is same as old

            1 Reply Last reply
            0
            • sundberg84S sundberg84

              @flopp pulseCount/V_VAR1 and Domoticz is something else... I have not got my finger around it but what I know is that some values in the energi meter is calculacted from V_VAR1 / day. When i tested my rain sensor (tip_bucket) i pretty much have to do 1 test each day to be sure. Also there is the possibility to edit the database but as i said, im not sure.

              If you had a pulsecount of 1000 and set it to 0 it would show -1000 in watts i think or something... but only calculated the pulse from that day.
              Sorry, not bringing anything good to the table, just remember it was a bit hard to get my head around.

              F Offline
              F Offline
              flopp
              wrote on last edited by
              #8

              @sundberg84
              i also had a lot of problem with my Rain data in Domoticz.
              read more here https://www.domoticz.com/forum/viewtopic.php?f=28&t=11088

              if your Sensor timeout is 2 hours you need to send rain VAR within 2 hours otherwise your graph will look strange.

              Yes, if you change the VAR during the day to a lower value you will get minus value. Took me a few days to understand how Domoticz DB file was working.

              Keep up the good work :punch:

              1 Reply Last reply
              2
              • F Offline
                F Offline
                flopp
                wrote on last edited by flopp
                #9

                It was working for a few hours then not sending any data, even with my new sketch. I changed to Arduino UNO and since then it has been working perfect. So it was my NRF(maybe) and my Nano that was not working correctly.

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  flopp
                  wrote on last edited by flopp
                  #10

                  But I found something weird about the division

                  0_1473320473986_IMG_2818.JPG

                  Why doesn't it send the exact value?

                  My pulseCount is 1845124894 and it is sent to Controller correct, then it will use below function
                  My PULSE_FACTOR is 10000

                  double kwh = ((double)pulseCount/((double)PULSE_FACTOR));
                  

                  and send the divided value to Controller, but it doesn't send correct value, it is missing the two last numbers "94" it is absolutely not a big problem but why send 4 decimals when the two last it always 0(zero)

                  Look at last row, 1845125113 = 184512.5200?

                  Is this because double values is rounding up? But 5113 should be 5100.

                  YveauxY 1 Reply Last reply
                  0
                  • F flopp

                    But I found something weird about the division

                    0_1473320473986_IMG_2818.JPG

                    Why doesn't it send the exact value?

                    My pulseCount is 1845124894 and it is sent to Controller correct, then it will use below function
                    My PULSE_FACTOR is 10000

                    double kwh = ((double)pulseCount/((double)PULSE_FACTOR));
                    

                    and send the divided value to Controller, but it doesn't send correct value, it is missing the two last numbers "94" it is absolutely not a big problem but why send 4 decimals when the two last it always 0(zero)

                    Look at last row, 1845125113 = 184512.5200?

                    Is this because double values is rounding up? But 5113 should be 5100.

                    YveauxY Offline
                    YveauxY Offline
                    Yveaux
                    Mod
                    wrote on last edited by
                    #11

                    @flopp could be because 'double' is actually float on Arduino, and therefore precision is limited. Have to do so maths though to know for sure.

                    http://yveaux.blogspot.nl

                    F 1 Reply Last reply
                    0
                    • YveauxY Yveaux

                      @flopp could be because 'double' is actually float on Arduino, and therefore precision is limited. Have to do so maths though to know for sure.

                      F Offline
                      F Offline
                      flopp
                      wrote on last edited by
                      #12

                      @Yveaux
                      OK thanks

                      1 Reply Last reply
                      0
                      • F Offline
                        F Offline
                        flopp
                        wrote on last edited by
                        #13

                        still working with UNO.

                        this is the sketch i am running

                        #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 10000       // 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 15000          // 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 = 5*60000; // 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");
                          //1.1 no check for old value, always send
                          
                          // Register this device as power sensor
                          gw.present(CHILD_ID, S_POWER);
                        
                          // Fetch last known pulse count value from gw
                          gw.request(CHILD_ID, V_VAR1);
                          
                          attachInterrupt(INTERRUPT, onPulse, RISING);
                          lastSend=millis();
                        }
                        
                        
                        void loop()     
                        { 
                          gw.process();
                          unsigned long now = millis();
                          // Only send values at a maximum frequency or woken up from sleep
                          bool sendTime = now - lastSend > SEND_FREQUENCY;
                          if (pcReceived && (SLEEP_MODE || sendTime)) {
                            
                            // New watt value has been calculated  
                               
                            // Check that we dont get unresonable large watt value. 
                            // could hapen when long wraps or false interrupt triggered
                            if (watt<((unsigned long)MAX_WATT)) {
                            
                              gw.send(wattMsg.set(watt));  // Send watt value to gw 
                            }  
                            Serial.print("Watt:");
                            Serial.println(watt);
                            oldWatt = watt;
                             
                            // Pulse cout has changed
                            
                            if (pulseCount != oldPulseCount) {
                            
                              gw.send(pcMsg.set(pulseCount));  // Send pulse count value to gw 
                              double kwh = ((double)pulseCount/((double)PULSE_FACTOR));     
                              oldPulseCount = pulseCount;
                                 
                              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++;
                        }
                        
                        1 Reply Last reply
                        0
                        • F Offline
                          F Offline
                          flopp
                          wrote on last edited by
                          #14

                          There must be something wrong with my code. Since 1 February my Arduino is 3 kWh before the real energy value for my house.
                          My second Arduino is measuring kWh on my heating system and that one is running correct.
                          For my house I use Nano(clone) for heating system I use UNO(original)
                          Can the hardware be the bad guy here?
                          It should be same code in both Arduino but tomorrow I will use an UNO(org) for my house and wait 1 week.

                          YveauxY 1 Reply Last reply
                          0
                          • F flopp

                            There must be something wrong with my code. Since 1 February my Arduino is 3 kWh before the real energy value for my house.
                            My second Arduino is measuring kWh on my heating system and that one is running correct.
                            For my house I use Nano(clone) for heating system I use UNO(original)
                            Can the hardware be the bad guy here?
                            It should be same code in both Arduino but tomorrow I will use an UNO(org) for my house and wait 1 week.

                            YveauxY Offline
                            YveauxY Offline
                            Yveaux
                            Mod
                            wrote on last edited by
                            #15

                            @flopp how do you count the pulses from your meter? Could that be the issue?

                            http://yveaux.blogspot.nl

                            F 1 Reply Last reply
                            0
                            • YveauxY Yveaux

                              @flopp how do you count the pulses from your meter? Could that be the issue?

                              F Offline
                              F Offline
                              flopp
                              wrote on last edited by
                              #16

                              @Yveaux
                              I don't know the name but I think it is a photo resistor, which I have connected to a LM393 then Arduino counts the interrupts.
                              Same hardware for both House and Heating.
                              Same sketch.

                              1 Reply Last reply
                              0
                              • F Offline
                                F Offline
                                flopp
                                wrote on last edited by flopp
                                #17

                                I changed to a UNO now my Watt is showing the same value!!
                                EDIT: this was because the WATT was above 15000 and then it didn't send any data to Controller. I had values up to 110000.
                                It must be something with the Watt calculation. Anyone seen this before?
                                0_1486495276398_elhuset.png

                                1 Reply Last reply
                                0
                                • F Offline
                                  F Offline
                                  flopp
                                  wrote on last edited by
                                  #18

                                  I think I found it.

                                  if (interval<10000L) { // Sometimes we get interrupt on RISING
                                        return;
                                      }
                                  

                                  It seems to be that my interrupt is to quick. above code is default if I change to

                                  if (interval<35000L) { // Sometimes we get interrupt on RISING
                                        return;
                                      }
                                  

                                  it will calculate Watt as I think it should be.
                                  I will let it run for a week and see if kWh is OK now.

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


                                  15

                                  Online

                                  11.7k

                                  Users

                                  11.2k

                                  Topics

                                  113.1k

                                  Posts


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

                                  • Don't have an account? Register

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