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. My Project
  3. Count car-starts

Count car-starts

Scheduled Pinned Locked Moved My Project
47 Posts 5 Posters 15.7k 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 said:

    What does that mean exactly? Write to eeprom when power disappear, how is that possible without power?

    Writing is not instantaneous. It might only take a millisecond, but during that time things can happen. So when the write starts, there is enough power. But half-way through the write power is lost. That leaves the eeprom in an unknown state.

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

    @mfalkvidd
    Ok, I read it "to write as counting voltage drop" but it was "write to eeprom during voltage drop".
    It is now clear, thanks

    1 Reply Last reply
    0
    • T Offline
      T Offline
      tbowmo
      Admin
      wrote on last edited by
      #38

      @flopp

      A more exotic "hack" could be to tap into the OBD2 interface, and for example check engine RPM to see if motor is running, or not.

      See this link..
      http://mechanics.stackexchange.com/questions/24171/how-to-detect-engine-ignition-on-off-status-using-obd2

      F 1 Reply Last reply
      0
      • T tbowmo

        @flopp

        A more exotic "hack" could be to tap into the OBD2 interface, and for example check engine RPM to see if motor is running, or not.

        See this link..
        http://mechanics.stackexchange.com/questions/24171/how-to-detect-engine-ignition-on-off-status-using-obd2

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

        @tbowmo
        Something like this?
        This looks really nice, something I want to try later on
        http://youtu.be/kmZ2PUMOKB8

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

          My sketch seems to work, only problem is presentation in domoticz

          I will add a buzzer to now when it has reported to gateway

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tbowmo
            Admin
            wrote on last edited by
            #41

            @flopp

            There is an howto here http://www.instructables.com/id/Hack-an-ELM327-Cable-to-make-an-Arduino-OBD2-Scann/ looks pretty simple to get going, and read out the RPM's..

            F 1 Reply Last reply
            0
            • T tbowmo

              @flopp

              There is an howto here http://www.instructables.com/id/Hack-an-ELM327-Cable-to-make-an-Arduino-OBD2-Scann/ looks pretty simple to get going, and read out the RPM's..

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

              @tbowmo
              Nice, I will test in a few weeks

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

                I have now solve the problem with storing data in Domoticz at correct day.

                I have another node that send back the same value as it is right now, every 2 hours

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

                  Version 1.12, changes gw.wait when asking for VAR from 5 sec to 1 sec. also added support for Buzzer on D3

                  1 Reply Last reply
                  0
                  • F Offline
                    F Offline
                    flopp
                    wrote on last edited by
                    #45
                    This post is deleted!
                    1 Reply Last reply
                    0
                    • F Offline
                      F Offline
                      flopp
                      wrote on last edited by flopp
                      #46

                      Keep-alive version. I noticed when this Node didn't get any response from Controller it send back 0, which means that this day will be very many starts

                      // Made by Daniel Nilsson
                      // Tested with Domoticz 3.4967
                      // Version 1.1
                      // 2016-05-10
                      
                      //Keep-alive since Domoticz seems to not storing data if not data comes in for 3 hours(user setting)
                      
                      #include <SPI.h>
                      #include <MySensor.h>
                      
                      #define CHILD_ID 0                          // Id of the sensor child
                      #define NODE_ID 7                        // same ID as real Car Counter
                      
                      int Controller;                             // Current start counts from Controller, like Domoticz
                      
                      MySensor gw;
                      MyMessage volumeMsg(CHILD_ID,V_RAIN);
                      MyMessage lastCounterMsg(CHILD_ID,V_VAR1);
                      
                      void setup()
                      {          
                        delay(500);   // wait for radio
                        
                        //Begin
                        gw.begin(incomingMessage, NODE_ID);
                        // Register this device as Rain sensor (will not show in Domoticz until first value arrives)
                        gw.present(CHILD_ID, S_RAIN);       
                      }
                      
                      void loop()
                      { 
                        
                          //Ask for starts from Controller.
                        
                            Serial.println("Request start counts");
                            //gw.request(CHILD_ID, V_VAR1);
                            while (Controller == 0) {
                              gw.request(CHILD_ID, V_VAR1);
                              Serial.println("No response from Controller");
                              gw.wait(60000);
                              }
                            gw.wait(5000);
                            
                      if (!resend((volumeMsg.set(Controller)), 5))return;
                      gw.wait(1000);
                      gw.sleep(120*60000); //less then timeout in Controller
                      }
                      
                      // check if "st:fail" during gw.send, thanks n3ro
                      bool resend(MyMessage &msg, int repeats)
                      {
                        int repeat = 1;
                        boolean sendOK = false;
                        int repeatdelay = 2000;
                      
                        while ((sendOK == false) and (repeat < repeats)) {
                          if (gw.send(msg)) {
                            sendOK = true;
                          }
                          else {
                            sendOK = false;
                            Serial.print("Error ");
                            Serial.println(repeat);
                          }
                          repeat++; delay(repeatdelay);
                        }
                        if (sendOK == false && repeat == repeats){
                          return false;
                        }
                        return true;
                      }
                      
                      //Read if we have a incoming message.
                      void incomingMessage(const MyMessage &message) {
                        if (message.type==V_VAR1) {
                          Controller = message.getULong();
                          //pcReceived = true;
                          Serial.print("Received start counts from Controller: ");
                          Serial.println(Controller);   
                        }
                      }
                      
                      1 Reply Last reply
                      1
                      • F Offline
                        F Offline
                        flopp
                        wrote on last edited by flopp
                        #47

                        Version 1.13 changed to fixed NODE_ID

                        // Made by Daniel Nilsson
                        // Tested with Domoticz 3.5721
                        // 2016-12-10
                        
                        #include <SPI.h>
                        #include <MySensor.h>
                        
                        #define CHILD_ID 0                          // Id of the sensor child
                        #define NODE_ID 7                            // a number or AUTO to let controller assign
                        #define SKETCH_NAME "Car start counter"     // Change to a fancy name you like
                        #define SKETCH_VERSION "1.13"                // Your version
                        
                        int Controller;                             // Current start counts from Controller, like Domoticz
                        boolean pcReceived = false;                 // If we have recieved the start counts from Controller or not 
                        int starts;                                 // summary of all starts to be sent to Controller
                        int eeprom;                                 // start counts read from/to be stored in EEPROM
                        
                        
                        MySensor gw;
                        MyMessage volumeMsg(CHILD_ID,V_RAIN);
                        MyMessage lastCounterMsg(CHILD_ID,V_VAR1);
                        
                        void setup()
                        {          
                          pinMode(3,OUTPUT);
                          delay(2*45000);  // Allow time if USB/cigarette plug is powered before you turned the key
                          digitalWrite(3,HIGH);
                          delay(300);
                          digitalWrite(3,LOW);
                          delay(300);
                          digitalWrite(3,HIGH);
                          delay(300);
                          digitalWrite(3,LOW);
                          //Begin
                          gw.begin(incomingMessage, NODE_ID, false);
                          
                          // Send the Sketch Version Information to the Gateway
                          gw.sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
                        
                          // Register this device as Rain sensor (will not show in Domoticz until first value arrives)
                          gw.present(CHILD_ID, S_RAIN);       
                          Serial.println("");
                          eeprom = gw.loadState(0);                       // read EEPROM
                          Serial.print(eeprom);                           // print EEPROM
                          Serial.println(" starts have not been sent");
                          Serial.println("add 1 start");
                          Serial.print(eeprom);
                          Serial.print("+1=");
                          eeprom = eeprom + 1;
                          Serial.println(eeprom);
                          gw.saveState(0,eeprom);                         // store to EEPROM at position 0
                          Serial.println("");
                          
                          Serial.println("Startup completed");
                        }
                        
                        void loop()
                        { 
                          
                            //See if we have the start counts from Controller - and ask for it if we dont.
                            if (!pcReceived) {
                              Serial.println("Request start counts");
                              gw.request(CHILD_ID, V_VAR1);
                              gw.wait(1000);
                              return;
                            }
                        
                        Serial.println("");
                        eeprom = gw.loadState(0);                     // read EEPROM
                        Serial.print(eeprom);
                        Serial.println(" starts have not been sent");
                        Serial.print(Controller);
                        Serial.println(" starts from Controller");    
                        starts = Controller + eeprom;                 // total starts
                        Serial.print(eeprom);
                        Serial.print("+");
                        Serial.print(Controller);
                        Serial.print("=");
                        Serial.println(starts);
                        Serial.print("Send ");
                        Serial.print(starts);
                        Serial.println(" to Controller");
                        Serial.println("");
                        
                        if (!resend((volumeMsg.set(starts)), 6))return;
                        if (!resend((lastCounterMsg.set(starts)), 6)) return;
                        
                        Serial.println("");
                        Serial.println("store 0 to EEPROM");
                        gw.saveState(0,0);                            // set 0 start to EEPROM, all have been sent
                        Serial.println("sleep");                      // mission accomplished
                        digitalWrite(3,HIGH);
                          delay(900);
                          digitalWrite(3,LOW);
                          
                        while(1){}
                        
                        }
                        
                        // check if "st:fail" during gw.send, thanks n3ro
                        bool resend(MyMessage &msg, int repeats)
                        {
                          int repeat = 1;
                          boolean sendOK = false;
                          int repeatdelay = 2000;
                        
                          while ((sendOK == false) and (repeat < repeats)) {
                            if (gw.send(msg)) {
                              sendOK = true;
                            }
                            else {
                              sendOK = false;
                              Serial.print("Error ");
                              Serial.println(repeat);
                            }
                            repeat++; delay(repeatdelay);
                          }
                          if (sendOK == false && repeat == repeats){
                            return false;
                          }
                          return true;
                        }
                        
                        //Read if we have a incoming message.
                        void incomingMessage(const MyMessage &message) {
                          if (message.type==V_VAR1) {
                            Controller = message.getULong();
                            pcReceived = true;
                            Serial.print("Received start counts from Controller: ");
                            Serial.println(Controller);   
                          }
                        }
                        
                        1 Reply Last reply
                        0

                        Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                        Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                        With your input, this post could be even better 💗

                        Register Login
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        24

                        Online

                        12.0k

                        Users

                        11.2k

                        Topics

                        113.4k

                        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