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 12.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

    Sorry, I forgot to change void resend to bool resend. I have updated my previous post.

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

    @mfalkvidd
    But if I put ! inside ( it works

    if (!resend((volumeMsg.set(starts)), 5))return;
    
    1 Reply Last reply
    0
    • mfalkviddM Offline
      mfalkviddM Offline
      mfalkvidd
      Mod
      wrote on last edited by
      #28

      Yes, sorry about that. I edited my previous post to have ! inside ().

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

          This post is deleted!

          Z Offline
          Z Offline
          Zeph
          Hero Member
          wrote on last edited by Zeph
          #30

          OK, let me see if I understand your overall flow.

          You have your node connected to switched 12V power in the car. When you turn on the car, the uC gets power, when you turn off the car it loses power. When the car is cranking, the voltage drops enough that it tends to reset again (or else the cranking position on your key switch actually cuts off auxiliary power used by the uC).

          So if you are at home and in range, loop() is called by the Arduino runtime just once; at the end of loop() the uC goes into an infinite busy loop rather than return, staying there until power is lost again. If you are away from home or the packets are lost for other reasons, resend() will cause a return from loop(), so that loop() will be called again by the Arduino runtime, so it will just keep trying until either power is lost, or it makes contact with your wireless network again.

          Meanwhile every time it starts, the first byte of eeprom is incremented in setup(), and then loop() tries to fetch VAR1, and send VAR1+eeprom(0) back. If it succeeds, then the first byte of eeprom is zeroed.

          Right?

          That sounds reasonable. My immediate concern would be inconsistent operation during cranking, if the input voltage went just low enough to make the uC unstable. If your car's wiring cuts the power entirely, not a problem. Likewise there appears to be time for the uC to boot, and fully update eeprom, before losing power during cranking. (It's best not to be writing eeprom as voltage drops). It appears that those are not problems for your system tho.

          F mfalkviddM 2 Replies Last reply
          0
          • F flopp

            @tbowmo
            Yes, but I dont want to jeopardize my cars :)
            12v can be handle by the Arduino Pro min on RAW pin

            Z Offline
            Z Offline
            Zeph
            Hero Member
            wrote on last edited by Zeph
            #31

            @flopp said:

            12v can be handle by the Arduino Pro min on RAW pin

            Cars go well above 14V during operation (as well as having noise glitches on top of that). If the regulator is only good up to 12v, operation could be marginal. Hence the suggestion from @tbowmo of a couple of diodes in the power feed, to drop a bit of the voltage as seen by the regulator.

            F 1 Reply Last reply
            0
            • Z Zeph

              OK, let me see if I understand your overall flow.

              You have your node connected to switched 12V power in the car. When you turn on the car, the uC gets power, when you turn off the car it loses power. When the car is cranking, the voltage drops enough that it tends to reset again (or else the cranking position on your key switch actually cuts off auxiliary power used by the uC).

              So if you are at home and in range, loop() is called by the Arduino runtime just once; at the end of loop() the uC goes into an infinite busy loop rather than return, staying there until power is lost again. If you are away from home or the packets are lost for other reasons, resend() will cause a return from loop(), so that loop() will be called again by the Arduino runtime, so it will just keep trying until either power is lost, or it makes contact with your wireless network again.

              Meanwhile every time it starts, the first byte of eeprom is incremented in setup(), and then loop() tries to fetch VAR1, and send VAR1+eeprom(0) back. If it succeeds, then the first byte of eeprom is zeroed.

              Right?

              That sounds reasonable. My immediate concern would be inconsistent operation during cranking, if the input voltage went just low enough to make the uC unstable. If your car's wiring cuts the power entirely, not a problem. Likewise there appears to be time for the uC to boot, and fully update eeprom, before losing power during cranking. (It's best not to be writing eeprom as voltage drops). It appears that those are not problems for your system tho.

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

              @Zeph
              Fully correct :) thanks for summarizing.

              Car A have a built in USB where I, today, take power. I have to test if the voltage will go low so the uC will not get correct power but not 0 volt(restart), I don't know what will happen then. This was your question?
              Car B have cigarette plug(12v output) so I use a converter to 5V, I think these converters can handle low input and still have 5V on output.

              I will test it for a while and count starts in my head(good luck)

              Next idea is to have a buzzer to beep when it has successfully sent data to Controller, just as information and if it beeps when I am away from home I have a mistake in the sketch

              1 Reply Last reply
              0
              • Z Zeph

                @flopp said:

                12v can be handle by the Arduino Pro min on RAW pin

                Cars go well above 14V during operation (as well as having noise glitches on top of that). If the regulator is only good up to 12v, operation could be marginal. Hence the suggestion from @tbowmo of a couple of diodes in the power feed, to drop a bit of the voltage as seen by the regulator.

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

                @Zeph
                you are right about 14V.

                Best should be to hide uC and connect to power(which only have power after crank)

                1 Reply Last reply
                0
                • Z Zeph

                  OK, let me see if I understand your overall flow.

                  You have your node connected to switched 12V power in the car. When you turn on the car, the uC gets power, when you turn off the car it loses power. When the car is cranking, the voltage drops enough that it tends to reset again (or else the cranking position on your key switch actually cuts off auxiliary power used by the uC).

                  So if you are at home and in range, loop() is called by the Arduino runtime just once; at the end of loop() the uC goes into an infinite busy loop rather than return, staying there until power is lost again. If you are away from home or the packets are lost for other reasons, resend() will cause a return from loop(), so that loop() will be called again by the Arduino runtime, so it will just keep trying until either power is lost, or it makes contact with your wireless network again.

                  Meanwhile every time it starts, the first byte of eeprom is incremented in setup(), and then loop() tries to fetch VAR1, and send VAR1+eeprom(0) back. If it succeeds, then the first byte of eeprom is zeroed.

                  Right?

                  That sounds reasonable. My immediate concern would be inconsistent operation during cranking, if the input voltage went just low enough to make the uC unstable. If your car's wiring cuts the power entirely, not a problem. Likewise there appears to be time for the uC to boot, and fully update eeprom, before losing power during cranking. (It's best not to be writing eeprom as voltage drops). It appears that those are not problems for your system tho.

                  mfalkviddM Offline
                  mfalkviddM Offline
                  mfalkvidd
                  Mod
                  wrote on last edited by mfalkvidd
                  #34

                  @Zeph said:

                  It's best not to be writing eeprom as voltage drops

                  This is correct. However, shouldn't the BOD take care of that problem? Might be a good idea to set the BOD to 4.3V i stead of the default 2.7 though?

                  F 1 Reply Last reply
                  0
                  • mfalkviddM mfalkvidd

                    @Zeph said:

                    It's best not to be writing eeprom as voltage drops

                    This is correct. However, shouldn't the BOD take care of that problem? Might be a good idea to set the BOD to 4.3V i stead of the default 2.7 though?

                    F Offline
                    F Offline
                    flopp
                    wrote on last edited by mfalkvidd
                    #35

                    @mfalkvidd said:

                    @Zeph said:

                    It's best not to be writing eeprom as voltage drops

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

                    This is correct. However, shouldn't the BOD take care of that problem? Might be a good idea to set the BOD to 4.3V instead of the default 2.7 though?

                    Perfect, then it will die sooner I guess

                    mfalkviddM 1 Reply Last reply
                    0
                    • F flopp

                      @mfalkvidd said:

                      @Zeph said:

                      It's best not to be writing eeprom as voltage drops

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

                      This is correct. However, shouldn't the BOD take care of that problem? Might be a good idea to set the BOD to 4.3V instead of the default 2.7 though?

                      Perfect, then it will die sooner I guess

                      mfalkviddM Offline
                      mfalkviddM Offline
                      mfalkvidd
                      Mod
                      wrote on last edited by mfalkvidd
                      #36

                      @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 1 Reply Last reply
                      0
                      • 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
                        • tbowmoT Offline
                          tbowmoT 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
                          • tbowmoT 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
                              • tbowmoT Offline
                                tbowmoT 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
                                • tbowmoT 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
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          12

                                          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