Skip to content

Added a couple of options #73

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions OpenTracker/OpenTracker.ino
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ int SEND_DATA = 1;
long time_start, time_stop, time_diff; //count execution time to trigger interval
int interval_count = 0; //current interval count (increased on each data collection and reset after sending)
int sms_check_count = 0; //counter for SMS check (increased on each cycle and reset after check)
int engine_off_send_count = 0; //counter for sending data when the ignition is off

char data_current[DATA_LIMIT+1]; //data collected in one go, max 2500 chars
int data_index = 0; //current data index (where last data record stopped)
Expand Down Expand Up @@ -207,7 +208,7 @@ void loop() {
// force sending last data
interval_count = config.interval_send;
collect_data(IGNT_STAT);
send_data();
send_data(0);
}
engineRunning = 1;
// save power when engine is off
Expand Down Expand Up @@ -242,15 +243,17 @@ void loop() {
//start counting time
time_start = millis();

if(ALWAYS_ON || IGNT_STAT == 0) {
if(ALWAYS_ON || IGNT_STAT == 0 || (ENGINE_OFF_INTERVAL_COUNT >0 && ++engine_off_send_count >= ENGINE_OFF_INTERVAL_COUNT)) {
engine_off_send_count = 0;

if(IGNT_STAT == 0) {
debug_print(F("Ignition is ON!"));
// Insert here only code that should be processed when Ignition is ON
}

//collecting GPS data
collect_data(IGNT_STAT);
send_data();
send_data(IGNT_STAT);

#if SMS_CHECK_INTERVAL_ENGINE_RUNNING > 0
// perform SMS check
Expand Down Expand Up @@ -288,8 +291,10 @@ void loop() {
}
#endif
}

status_led();

if (ENABLE_STATUS_LED) {
status_led();
}

debug_check_input();

Expand Down
27 changes: 22 additions & 5 deletions OpenTracker/data.ino
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,25 @@ void collect_all_data(int ignitionState) {
data_field_restart();

// append battery level to data packet
if(DATA_INCLUDE_BATTERY_LEVEL) {
data_field_separator(',');
if(DATA_INCLUDE_BATTERY_LEVEL || BATTERY_LOW_KILL_POWER > 0) {
float sensorValue = analog_input_voltage(AIN_S_INLEVEL, HIGH);
char batteryLevel[10];
dtostrf(sensorValue,2,2,batteryLevel);
data_append_string(batteryLevel);

if (DATA_INCLUDE_BATTERY_LEVEL) {
data_field_separator(',');
data_append_string(batteryLevel);
}

if (BATTERY_LOW_KILL_POWER > 0 && sensorValue < BATTERY_LOW_KILL_POWER) {
if (strlen(BATTERY_LOW_SMS_NUMBER) >0) {
char buf[100];
snprintf((char *)&buf, sizeof(buf), "voltage dropped below %s - powering off", batteryLevel);
sms_send_msg(buf, BATTERY_LOW_SMS_NUMBER);
}

power_cutoff = 1;
}
}

// ignition state
Expand Down Expand Up @@ -297,7 +310,7 @@ void collect_all_data_raw(int ignitionState) {
/**
* This function send collected data using HTTP or TCP
*/
void send_data() {
void send_data(int force) {
debug_print(F("send_data() started"));

debug_print(F("Current:"));
Expand All @@ -306,7 +319,11 @@ void send_data() {
interval_count++;
debug_print(F("Data accumulated:"));
debug_print(interval_count);


if (force) {
interval_count = config.interval_send;
}

// send accumulated data
if (interval_count >= config.interval_send) {
// if data send disabled, use storage
Expand Down
4 changes: 3 additions & 1 deletion OpenTracker/sms.ino
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,10 @@ void sms_cmd_run(char *cmd, char *phone) {
if(strcmp(cmd, "locate") == 0) {
debug_print(F("sms_cmd_run(): Locate command detected"));

if(LOCATE_COMMAND_FORMAT_IOS) {
if(LOCATE_COMMAND_FORMAT_IOS == 1) {
snprintf(msg,sizeof(msg),"comgooglemaps://?center=%s,%s",lat_current,lon_current);
} else if(LOCATE_COMMAND_FORMAT_IOS == 2) {
snprintf(msg,sizeof(msg),"maps:ll=%s,%s&q=car",lat_current,lon_current);
} else {
snprintf(msg,sizeof(msg),"https://maps.google.com/maps/place/%s,%s",lat_current,lon_current);
}
Expand Down
7 changes: 6 additions & 1 deletion OpenTracker/tracker.h.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//default settings (can be overwritten and stored in EEPRom)
#define INTERVAL 5000 //how often to collect data (milli sec, 600000 - 10 mins)
#define INTERVAL_SEND 4 //how many times to collect data before sending (times), sending interval interval*interval_send (4 default)
#define ENGINE_OFF_INTERVAL_COUNT 3600 //how often to send data when the ignition is off
#define POWERSAVE 1 //enable power saving mode with engine off (turn off modem data session, slow down CPU)
#define KEY "cSQ88qShwC3" //key for connection, will be sent with every data transmission - max 12 chars
#define DATA_LIMIT 2500 //current data limit, data collected before sending to remote server can not exceed this
Expand All @@ -19,7 +20,7 @@
#define SMS_CHECK_INTERVAL_COUNT 6 // 0=disable SMS check with engine off, 1-N=check every N cycles of interval time
#define SMS_CHECK_INTERVAL_ENGINE_RUNNING 2 // 0=disable SMS check with engine running, 1-N=check every N cycles of interval time

#define LOCATE_COMMAND_FORMAT_IOS 0 // 1=google maps links will be sent as comgooglemaps://, 0=use format https://maps.google...
#define LOCATE_COMMAND_FORMAT_IOS 0 // 0=use format https://maps.google... 1=google maps links will be sent as comgooglemaps://, 2=apple maps format

#define GSM_USE_QUECLOCATOR_TIMEOUT 10 // 0=don't use QuecLocator, 1-300=timeout for server reply
#define GSM_USE_NTP_SERVER "pool.ntp.org" // use Network Time Protocol server for modem clock update (undefine to disable)
Expand Down Expand Up @@ -102,3 +103,7 @@
#define KNOWN_APN_SCAN_MODE 1 // 0=check GPRS context only, 2=attempt only server connection, 1=use both in sequence
#define KNOWN_APN_SCAN_USE_RESET 0 // 1=reset modem to change APN, 0=change APN without reset

#define ENABLE_STATUS_LED 1

#define BATTERY_LOW_KILL_POWER 0 // shutdown if the battery falls below this voltage, 0 = disabled
#define BATTERY_LOW_SMS_NUMBER "" // send SMS to this number before shutting down (blank = disabled)