st=fail issue with custom energy meter sketch maybe eeprom?



  • Hello, i have recently returned to an old project i was working on 6 or more months ago, i modified a sketch to provide current only power readings from ct sensor only measuring current from sensor * typical 230v to get a power reading. It works fine except for the fact that it typically crashes after 1.5 days - 2 days.

    So that's issue 1, issue 2 is that after the crash i cant seem to reestablish comms with GW unless i erase eeprom and start again. ( i am also assigning a static node id in sketch)

    So my Sketch: (based on mysensors with open energy mteter lib)

                #include <SPI.h>
        #include <MySensor.h>  
        #include "EmonLib.h"                   // Include Emon Library
        
        #define CHILD_ID_POWER 0
        #define POWER_SENSOR_ANALOG_PIN 0
        #include "EmonLib.h"                   // Include Emon Library
        EnergyMonitor emon1;                   // Create an instance
        
        unsigned long SLEEP_TIME = 15000; // Sleep time between reads (in milliseconds)
        
        MySensor gw;
        MyMessage msg(CHILD_ID_POWER, V_WATT);
        int lastwatt;
        
        void setup()  
        { 
          emon1.current(2, 60.2);             // Current: input pin, calibration.   2 = A2
          gw.begin(NULL,27,false);
        
          // Send the sketch version information to the gateway and Controller
          gw.sendSketchInfo("Power Sensor", "1.0");
        
          // Register all sensors to gateway (they will be created as child devices)
          gw.present(CHILD_ID_POWER, S_POWER);/////???????????????
        }
        
        void loop()      
        {     
          static unsigned long lastUpdate;
          if (millis() - lastUpdate >= SLEEP_TIME)    //   If the current time - the last time we updated >= #SLEEP_TIME THEN:
        {
          double Irms = emon1.calcIrms(1480);  // Calculate Irms only
          
          int watt = (Irms*230.0); 
         // Serial.println(watt);
          //if (POWERLevel != lastPOWERPOWERLevel) {
            
              gw.send(msg.set(watt));
              
            //  lastPOWERLevel = POWERLevel;
          //}
         // gw.sleep(SLEEP_TIME);
         lastUpdate += SLEEP_TIME;    // Last update = lastupdate + SLEEP_TIME
        }
        }
    

    and my ?presentation data? after failure..
    sensor started, id 27
    send: 27-27-25-0 s=255,c=0,t=17,pt=0,l=3,st=ok:1.4
    send: 27-27-25-0 s=255,c=3,t=6,pt=1,l=1,st=fail:25
    send: 27-27-25-0 s=255,c=3,t=11,pt=0,l=12,st=ok:Power Sensor
    send: 27-27-25-0 s=255,c=3,t=12,pt=0,l=3,st=fail:1.0
    send: 27-27-25-0 s=0,c=0,t=13,pt=0,l=3,st=ok:1.4

    It seems!! as though i can restart as many times as i want until the "failure" with no issues in rebooting and reconnecting, but then something seems to happen during the failure to make in impossible to reconnect without eeprom flash..

    and then after erase i have this.
    sensor started, id 27
    send: 27-27-0-0 s=255,c=0,t=17,pt=0,l=3,st=ok:1.4
    send: 27-27-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
    send: 27-27-0-0 s=255,c=3,t=11,pt=0,l=12,st=ok:Power Sensor
    send: 27-27-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 27-27-0-0 s=0,c=0,t=13,pt=0,l=3,st=ok:1.4

    Please any ideas..??

    I'm using codebender to uplaod and several different versions of the arduino ide over the last year but i never really had the time to ask for help here before now, i just got frustrated and turned it off for a while!.. I've also used several different power supplys with all good quality and decent 1A max. I am using also several different nano's as my arduino of choice. .. please help !! 💃


  • Hero Member

    @Gambituk Take a look at this thread as some of the issues sound similar: http://forum.mysensors.org/topic/1628/st-fail-add-higher-cap. The data is being sent to ID 255, rather than ID 0. I believe this is because you have erased the EEPROM and then are hard-coding the sensor ID. Try it without hard-coding the ID first and then after it's initialized again, you should be able to hard code the ID again.

    Cheers
    Al



  • thanks for the reply @Sparkman , i had looked at that before posting but i can't seem to get my head around what i am supposed to do.... so for example i should erase.. then leave as auto so that it is assigned a value.. and then i can go back to my original static? or should i hard code the value that the controller gives me? (which isn't a major problem...)

    Also any idea's for the reason for the actual crash?

    Thanks

    Gamb


  • Hero Member

    @Gambituk said:

    thanks for the reply @Sparkman , i had looked at that before posting but i can't seem to get my head around what i am supposed to do.... so for example i should erase.. then leave as auto so that it is assigned a value.. and then i can go back to my original static? or should i hard code the value that the controller gives me? (which isn't a major problem...)

    Yes, that's correct, and you should be able to go back to your original static.

    Also any idea's for the reason for the actual crash?

    Not at this point, I thought it might be related to lastUpdate overflowing (max value for an unsigned long is 4,294,967,295), but that shouldn't happen till about 50 days or so. One thing to try is to not include the emonlib library and comment out any code referring to that to see if it's related to something in that library. I know the sketch won't be useful like that, but it might help pinpoint where the issue could be.

    Cheers
    Al



  • @Sparkman Thanks, so i've just tried resetting to auto, and i was assigned a new value of 22, so i've then set this to a static value in my sketch and re-uploaded it to the nano, so i will test like this, and report back in a day or two ( or hopefully several weeks!).. after that i will experiment with commenting out the library and continue troubleshooting in this direction.

    I did notice 1 more anomalie, in that my first reading after the presentation seems to be a value in watts of about 9000, and then after that i have normal and consistant readings from 100 - 4000 depending on whats running in the house.. so i was considering if something in my sketch logic is running wild on the first loops before the state of lastsend timer is valid... or something more.. but that's just an observation.

    Thanks again.

    Gambit



  • @Sparkman (My last ping for tonight i promise 🙂 )

    sensor started, id 22
    send: 22-22-25-0 s=255,c=0,t=17,pt=0,l=3,st=ok:1.4
    send: 22-22-25-0 s=255,c=3,t=6,pt=1,l=1,st=fail:25
    send: 22-22-25-0 s=255,c=3,t=11,pt=0,l=12,st=ok:Power Sensor
    send: 22-22-25-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 22-22-25-0 s=0,c=0,t=13,pt=0,l=3,st=ok:1.4
    send: 22-22-25-0 s=0,c=1,t=17,pt=2,l=2,st=ok:9278
    send: 22-22-25-0 s=0,c=1,t=17,pt=2,l=2,st=ok:40
    send: 22-22-25-0 s=0,c=1,t=17,pt=2,l=2,st=ok:39
    send: 22-22-25-0 s=0,c=1,t=17,pt=2,l=2,s

    Or just 4 minutes later 😞

    then deleted again the eeprom and then this
    send: 22-22-255-255 s=255,c=3,t=7,pt=0,l=0,st=fail:
    read: 25-25-22 s=255,c=3,t=8,pt=1,l=1:1
    new parent=25, d=2
    read: 0-0-22 s=255,c=3,t=8,pt=1,l=1:0
    new parent=0, d=1
    sensor started, id 22
    send: 22-22-0-0 s=255,c=0,t=17,pt=0,l=3,st=ok:1.4
    send: 22-22-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
    read: 0-0-22 s=255,c=3,t=6,pt=0,l=1:M
    send: 22-22-0-0 s=255,c=3,t=11,pt=0,l=12,st=ok:Power Sensor
    send: 22-22-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
    send: 22-22-0-0 s=0,c=0,t=13,pt=0,l=3,st=ok:1.4
    send: 22-22-0-0 s=0,c=1,t=17,pt=2,l=2,st=ok:9278

    I noticed looking above at what i've already posted that this could be an issue with nodes relaying data (or not).. it seems that at some point it decides that another node (25) will be used (it's about half way to gateway and very customised code) but this doesn't seem to be passing the message on.

    So i will also try to stop this node from offering its relaying services..

    Is there any way to insist that the node only speaks directly to the GW?
    thanks in advance


  • Hero Member

    @Gambituk I believe you can force the parent ID like this: "gw.begin(NULL,22,false,0);". The last number is the parent ID. Looks like I misread the original issue as in my mind I saw 255, not 25 😊

    Cheers
    Al



Suggested Topics

0
Online

11.2k
Users

11.1k
Topics

112.5k
Posts