Hey everyone! I hope this is something stupid but I can’t for the life of me figure out what’s wrong. I have 2 Boron’s, one installed in a vehicle (functioning as a GPS tracker) and another one I’m using for development. Admittedly, though I’ve had the one Boron in service for about a year, I haven’t consistently checked the event logs. Since working on the new Boron I just got, I noticed them both hard_faulting at random times. The new Boron is just attached to my computer via USB and has a GPS sensor attached - that’s all.
I don’t know if this is an OS issue, library issue, or something with my code (though I’ve had someone with more experience than me say my code is ok). What should I try? What’s the best way to debug this?
Here’s my code:
// Getting the library
#include "AssetTracker.h"
// Timer variables: Used to keep track of the last time we published data
unsigned long lastPublish = 0;
unsigned long delayMinutes = 2; // Minuetes set to default on boot - adjust in code below for actual
unsigned long inactiveTime = 120; // Minutes inbetween notification when inactive
int turboSwitch = 0; //Function call changes - used to activate turbomode
int inactiveCount = 0;
int acc_on_pin = D2;
//int disable_pin = D3; // Relay
// Creating an AssetTracker named 't' for us to reference
AssetTracker t = AssetTracker();
void setup() {
//Serial.begin(9600);
pinMode(acc_on_pin, INPUT_PULLDOWN); // Pulldown resister included in Boron
//digitalWrite(disable_pin, LOW); // initialise the relay to off
//pinMode(disable_pin, OUTPUT);
// Sets up all the necessary AssetTracker bits
t.begin();
// Enable the GPS module. Defaults to off to save power.
// Takes 1.5s or so because of delays.
t.gpsOn();
//Particle.function("Disable", fuel_shutoff);
Particle.function("turboMode", turboMode);
}
// Function turboMode - Record frequecy increase
int turboMode(String command) {
if (command == "On") {
turboSwitch = 1;
return 1;
}
else if (command == "Off") {
turboSwitch = 0;
return 0;
}
else {return -1;}
}
void loop() {
unsigned long now = millis();
t.updateGPS(); // You'll need to run this every loop to capture the GPS output
if (digitalRead(acc_on_pin) == HIGH) {
delayMinutes = 2;
inactiveCount = 0;
if (turboSwitch == 1){
delayMinutes = 1;
}
} else {
delayMinutes = inactiveTime;
}
// if the current time - the last time we published is greater than your set delay...
if ((now-lastPublish) >= delayMinutes*60*1000) {
lastPublish = now; // Reset time
if (t.gpsFix()) {
//String pubAccel = String::format("%d,%d", coords, accStatus);
//String datas = String::format("\"l\":%f", t.readLatLon());
//Particle.publish("V1", datas, 60, PRIVATE);
if (inactiveCount < 2){ // Don't report any new coordinates to reduce data after 2
Particle.publish("G",
String::format("%.5f",t.readLatDeg()) +
"," + String::format("%.5f",t.readLonDeg()) +
"," + String::format("%.0f",t.getSpeed()),
60, PRIVATE);
inactiveCount++;
}
}
}
}