Count car-starts
-
@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
@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.
-
@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.
@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 -
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 -
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 -
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..
-
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); } } -
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); } }