AssetTrackerRK
Public Member Functions | Static Public Member Functions
AssetTracker Class Reference

Compatible replacement for the official Particle AssetTracker/Electron library. More...

#include <AssetTrackerRK.h>

Inheritance diagram for AssetTracker:
LegacyAdapter

Public Member Functions

 AssetTracker ()
 Construct an AssetTracker object. Normally this is a global variable.
 
virtual ~AssetTracker ()
 Destructor.
 
void begin (void)
 Initialize the LIS3DH accelerometer. Optional.
 
void updateGPS (void)
 Updates the GPS. Must be called from loop() as often as possible, typically every loop. More...
 
void startThreadedMode ()
 Enable GPS threaded mode. More...
 
void gpsOn (void)
 Turns the GPS on. More...
 
void gpsOff (void)
 Turns the GPS off.
 
int readX (void)
 Read the accelerometer X value (signed)
 
int readY (void)
 Read the accelerometer Y value (signed)
 
int readZ (void)
 Read the accelerometer Z value (signed)
 
int readXYZmagnitude (void)
 Read the magnitude of the acceleration vector (positive value) More...
 
void sendCommand (const uint8_t *cmd, size_t len)
 Sends a u-blox GPS command. More...
 
bool antennaInternal ()
 Select the internal antenna. More...
 
bool antennaExternal ()
 Select the external antenna. More...
 
char * preNMEA (void)
 Not supported. The data is not available from TinyGPS++. More...
 
bool setupLowPowerWakeMode (uint8_t movementThreshold=16)
 Calls the LIS3DH setupLowPowerWakeMode. More...
 
uint8_t clearAccelInterrupt ()
 Clears the accelerometer interrupt if latching interrupts are enabled.
 
bool calibrateFilter (unsigned long stationaryTime, unsigned long maxWaitTime=0)
 Calibrate the filter used to cancel out gravity. More...
 
AssetTrackerwithSerialPort (USARTSerial &port)
 Override the default serial port used to connect to the GPS. Default is Serial1.
 
AssetTrackerwithI2C (TwoWire &wire=Wire, uint8_t addr=0x42)
 Use I2C (DDC) instead of serial. More...
 
LIS3DHSPI * getLIS3DHSPI ()
 Gets the LIS3DH accelerometer object so you can access its methods directly.
 
TinyGPSPlusgetTinyGPSPlus ()
 Gets the TinyGPS++ object so you can access its methods directly.
 
void setExternalDecoder (std::function< bool(char)> fn)
 Sets the external decoder function. More...
 
void lock ()
 Lock the mutex. Used to prevent multiple threads from writing to the GPS at the same time.
 
void unlock ()
 Lock the mutex. Used to prevent multiple threads from writing to the GPS at the same time.
 
- Public Member Functions inherited from LegacyAdapter
 LegacyAdapter (TinyGPSPlus &gpsData)
 Constructs the LegacyAdapter object. More...
 
virtual ~LegacyAdapter ()
 Destructor.
 
float convertToDegreesMinutes (double deg) const
 Converts a degree value (as a double) into the weird GPS DDMM.MMMMM format (degrees * 100 + minutes). More...
 
float readLat (void) const
 Return the latitude in a GPS-style value DDMM.MMMMM format (degrees * 100 + minutes). More...
 
float readLon (void) const
 Return the longitude in a GPS-style value DDMM.MMMMM format (degrees * 100 + minutes). More...
 
float readLatDeg (void) const
 Returns the latitude in degrees as a float. May be positive or negative. More...
 
float readLonDeg (void) const
 Returns the longitude in degrees as a float. May be positive or negative. More...
 
float getSpeed () const
 Gets the speed in knots. More...
 
float getAngle () const
 Get the course angle in degrees 0 <= deg < 360.
 
uint8_t getHour () const
 Get the current hour (in UTC)
 
uint8_t getMinute () const
 Get the current minute (in UTC)
 
uint8_t getSeconds () const
 Get the current second (in UTC)
 
uint16_t getMilliseconds () const
 Get the current millisecond (in UTC) More...
 
uint8_t getYear () const
 Get the current year (in UTC) More...
 
uint8_t getMonth () const
 Get the current month (1-12) (at UTC)
 
uint8_t getDay () const
 Get the current day of month (1-31) (at UTC)
 
uint32_t getGpsTimestamp () const
 Returns the number of milliseconds since the last GPS reading.
 
uint8_t getFixQuality () const
 Returns true (1) if there is a GPS fix or false (0) if not.
 
float readHDOP (void) const
 Gets the HDOP value. More...
 
float getGpsAccuracy () const
 Gets the GPS accuracy.
 
float getAltitude () const
 Get the altitude in meters.
 
float getGeoIdHeight () const
 Get the GeoID separation in meters. More...
 
uint8_t getSatellites () const
 Gets the number of satellites found.
 
bool gpsFix (void) const
 Returns true if there is a GPS fix. More...
 
String readLatLon (void) const
 Returns a string version of latitude and longitude. More...
 

Static Public Member Functions

static AssetTrackergetInstance ()
 Get the singleton instance of this class.
 

Additional Inherited Members

- Static Public Attributes inherited from LegacyAdapter
static const unsigned long MAX_GPS_AGE_MS = 10000
 GPS location must be newer than this to be considered valid.
 

Detailed Description

Compatible replacement for the official Particle AssetTracker/Electron library.

This is an almost drop-in replacement based on my LIS3DH driver and TinyGPS++.

If I were creating a new project, I'd write directly to the LIS3DH and TinyGPS++ interfaces instead of using this wrapper, but it's up to you.

Note that many of the backward compatibility methods are in the LegacyAdapter class so make sure you check there as well.

Member Function Documentation

◆ antennaExternal()

bool AssetTracker::antennaExternal ( )

Select the external antenna.

On the AssetTracker v2 only (or other u-blox GPS), sets the antenna to external. Internal is the default and is reset every time the GPS is powered up.

On the AssetTracker v1 (or other PA6H GPS), the antenna is auto-switching and this call is ignored.

◆ antennaInternal()

bool AssetTracker::antennaInternal ( )

Select the internal antenna.

On the AssetTracker v2 only (or other u-blox GPS), sets the antenna to internal. Internal is the default and is reset every time the GPS is powered up.

On the AssetTracker v1 (or other PA6H GPS), the antenna is auto-switching and this call is ignored.

◆ calibrateFilter()

bool AssetTracker::calibrateFilter ( unsigned long  stationaryTime,
unsigned long  maxWaitTime = 0 
)

Calibrate the filter used to cancel out gravity.

Parameters
stationaryTimeAmount of time (in milliseconds) the device needs to be stationary
maxWaitTimeAmount of time to wait (in milliseconds). 0 = wait forever
Returns
true if the filter is calibrated or false if still moving and the wait time was exceeded

In order to cancel out the effects of gravity on the accelerometer, we need to wait until it's not moving. Then we assume the steady state gravity is the baseline. This is necessary to support having the GPS positioned in any direction other than completely flat (all gravity in the Z direction).

◆ gpsOn()

void AssetTracker::gpsOn ( void  )

Turns the GPS on.

By default, it's off on reset. Call gpsOn() to turn it on.

◆ preNMEA()

char * AssetTracker::preNMEA ( void  )

Not supported. The data is not available from TinyGPS++.

An empty string is always returned.

◆ readXYZmagnitude()

int AssetTracker::readXYZmagnitude ( void  )

Read the magnitude of the acceleration vector (positive value)

sqrt((sample.x*sample.x)+(sample.y*sample.y)+(sample.z*sample.z));

◆ sendCommand()

void AssetTracker::sendCommand ( const uint8_t *  cmd,
size_t  len 
)

Sends a u-blox GPS command.

Parameters
cmdThe pointer to a uint8_t array of bytes to send
lenThe length of the command.

◆ setExternalDecoder()

void AssetTracker::setExternalDecoder ( std::function< bool(char)>  fn)
inline

Sets the external decoder function.

Parameters
fnfunction set. Replaces any existing function. Set to 0 to remove.

This is used by the UbloxGPS module to hook into the GPS decoding loop. You probably won't have to use this directly. Other brands of GPS that decode things that TinyGPS++ can't might also use this to hook in.

◆ setupLowPowerWakeMode()

bool AssetTracker::setupLowPowerWakeMode ( uint8_t  movementThreshold = 16)

Calls the LIS3DH setupLowPowerWakeMode.

You should call this instead of begin().

◆ startThreadedMode()

void AssetTracker::startThreadedMode ( )

Enable GPS threaded mode.

In threaded mode, the serial port is read from a separate thread so you'll be less likely to lose data if loop() is blocked for any reason

◆ updateGPS()

void AssetTracker::updateGPS ( void  )

Updates the GPS. Must be called from loop() as often as possible, typically every loop.

Only call this when not using threaded mode.

◆ withI2C()

AssetTracker & AssetTracker::withI2C ( TwoWire &  wire = Wire,
uint8_t  addr = 0x42 
)

Use I2C (DDC) instead of serial.

Parameters
wireThe I2C interface to use. This is optional, and if not set, Wire (the standard I2C interface) is used. On some devices (Electron, Argon, and Xenon), there is an optional Wire1.
addrThe I2C address to use. This is optional, and the default is 0x42. The address can be reprogrammed in software on the u-blox GPS, but 0x42 is the default.

The documentation for this class was generated from the following files: