I am attempting to use the Asset Tracker shield and library to report the location of an object. Whenever I enable the GPS, the Accelerometer stops working, without the GPS enabled the Accelerometer works fine.
I have searched the forum and can find similar posts but around using the wake on movement function, I am not using that, I simply want to collect GPS and Accelerometer readings at the same time.
Below is the code I am using, it publishes:
Event: A - 0,0,0
If I remove the line t.gpsOn() it publishes accelerometers readings.
Thanks
// This #include statement was automatically added by the Particle IDE.
#include <AssetTracker.h>
long lastPublish = 0;
int delaySecondsActive = 15;
int delaySecondsNotActive = 30; //3600;
// Creating an AssetTracker named 't' for us to reference
AssetTracker t = AssetTracker();
// 9000 is VERY sensitive, 12000 will still detect small bumps
int accelThreshold = 11000;
// A FuelGauge named 'fuel' for checking on the battery state
FuelGauge fuel;
double mainBatteryVoltage;
double auxBatteryVoltage;
bool isolatorStatus;
String gpsLocation = "";
long gpsTime = 0;
void setup() {
// 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();
// These three functions are useful for remote diagnostics. Read more below.
Particle.function("b", batteryStatus);
Particle.function("f", hasGPSFix);
Particle.function("t", accelThresholder);
Particle.variable("l", gpsLocation);
}
// loop() runs continuously
void loop() {
// You'll need to run this every loop to capture the GPS output
//t.updateGPS();
int publishDelaySeconds = 0;
if(t.readXYZmagnitude() > accelThreshold){
publishDelaySeconds = delaySecondsActive;
}else{
publishDelaySeconds = delaySecondsNotActive;
}
if(lastPublish == 0 || millis()-lastPublish > publishDelaySeconds*1000){
//Let's publush
lastPublish = millis();
if(t.gpsFix()) {
gpsLocation = t.readLatLon();
gpsTime = millis();
}
mainBatteryVoltage = getMainBatteryVoltage();
auxBatteryVoltage = getMainBatteryVoltage();
isolatorStatus = getIsolatorStatus();
Particle.publish("vs", statusData(), 60, PRIVATE);
String pubAccel = String::format("%d,%d,%d",t.readX(),t.readY(),t.readZ());
Particle.publish("A", pubAccel, 60, PRIVATE);
Particle.publish("D", String::format("%d",publishDelaySeconds), 60, PRIVATE);
}
}
String statusData() {
//Start JSON
String data = String("{ ");
//GPS Location
data.concat("\"1\": \"");
data.concat(gpsLocation);
data.concat("\"");
//Main Battery
data.concat(", \"2\": \"");
data.concat(String::format("%.1f",mainBatteryVoltage));
data.concat("\"");
//Aux Battery
data.concat(", \"3\": \"");
data.concat(String::format("%.1f",auxBatteryVoltage));
data.concat("\"");
//GPS Time
data.concat(", \"4\": \"");
data.concat(String::format("%d",millis()-gpsTime));
data.concat("\"");
//Finish JSON
data.concat("}");
return data;
}
double getMainBatteryVoltage() {
return 12.5;
}
double getAuxBatteryVoltage() {
return 13.4;
}
bool getIsolatorStatus() {
return true;
}
int hasGPSFix(String command) {
if(t.gpsFix()) {
return 1;
}else {
return 0;
}
}
// Remotely change the trigger threshold!
int accelThresholder(String command){
accelThreshold = atoi(command);
return 1;
}
// Lets you remotely check the battery status by calling the function "batt"
// Triggers a publish with the info (so subscribe or watch the dashboard)
// and also returns a '1' if there's >10% battery left and a '0' if below
int batteryStatus(String command){
// Publish the battery voltage and percentage of battery remaining
// if you want to be really efficient, just report one of these
// the String::format("%f.2") part gives us a string to publish,
// but with only 2 decimal points to save space
Particle.publish("B",
"v:" + String::format("%.2f",fuel.getVCell()) +
",c:" + String::format("%.2f",fuel.getSoC()),
60, PRIVATE
);
// if there's more than 10% of the battery left, then return 1
if(fuel.getSoC()>10){ return 1;}
// if you're running out of battery, return 0
else { return 0;}
}