[SOLVED] Asset shield: How to get altitude?


#1

How do I get altitude?

I’m using the t.readLatLon() and that provides latitude and longitude only. I opened the Assetshield library and dont see a function that will provide altitude too?


#2

Just pushed changes to the library (v0.0.7) that supports altitude. Please test and let us know.
t.getAltitude() will return a float value.


#3

Wow you guys need a medal for your user support. Seriously.


#4

Just tried the code, but getting an error:

/src/1_gps_features.cpp:81:21: error: 'class AssetTracker' has no member named 'getAltitude'

Do I need to re-include the asset tracker?


#5

For updating the library you need to remove it and include it again, if you hadn’t tried that yet.


#6

Yup, works now, thanks!


#7

Can you share the line of code you are using to publish the altitude?


#8

Here, but I never got to actually publishing it. The GPS on the asset shield is not very accurate and I’ve been trying to get an external GPS to work on it.

// This #include statement was automatically added by the Particle IDE.
#include <AssetTracker.h>

// This #include statement was automatically added by the Particle IDE.

/* -----------------------------------------------------------
This example shows a lot of different features. As configured here
it'll check for a good GPS fix every 10 minutes and publish that data
if there is one. If not, it'll save you data by staying quiet. It also
registers 3 Particle.functions for changing whether it publishes,
reading the battery level, and manually requesting a GPS reading.
---------------------------------------------------------------*/

// Getting the library

// Set whether you want the device to publish data to the internet by default here.
// 1 will Particle.publish AND Serial.print, 0 will just Serial.print
// Extremely useful for saving data while developing close enough to have a cable plugged in.
// You can also change this remotely using the Particle.function "tmode" defined in setup()
int transmittingData = 1;
int angle = 1;
Servo myservo;
int pos = 0;
float lat, lon, alt;

// Used to keep track of the last time we published data
long lastPublish = 0;

// How many minutes between publishes? 10+ recommended for long-time continuous publishing!
int delayMinutes = 1;

// Creating an AssetTracker named 't' for us to reference
AssetTracker t = AssetTracker();

// A FuelGauge named 'fuel' for checking on the battery state
FuelGauge fuel;

// setup() and loop() are both required. setup() runs once when the device starts
// and is used for registering functions and variables and initializing things
void setup() {
    // Sets up all the necessary AssetTracker bits
    myservo.attach(D0);
    t.begin();
    
    // Enable the GPS module. Defaults to off to save power. 
    // Takes 1.5s or so because of delays.
    //t.gpsOn();
    
    // Opens up a Serial port so you can listen over USB
    Serial1.begin(9600);
    
    // These three functions are useful for remote diagnostics. Read more below.
    Particle.function("sa", servoToAngle);
    Particle.function("tmode", transmitMode);
    Particle.function("batt", batteryStatus);
    Particle.function("gps", gpsPublish);
    
}

// loop() runs continuously
void loop() {
    // You'll need to run this every loop to capture the GPS output

    t.updateGPS();

    // if the current time - the last time we published is greater than your set delay...
    if(millis()-lastPublish > delayMinutes*60*1000){
        // Remember when we published
        lastPublish = millis();
        
        //String pubAccel = String::format("%d,%d,%d",t.readX(),t.readY(),t.readZ());
        //Serial.println(pubAccel);
        //Particle.publish("A", pubAccel, 60, PRIVATE);
        
        // Dumps the full NMEA sentence to serial in case you're curious
        Serial.println(t.preNMEA());
        
        // GPS requires a "fix" on the satellites to give good data,
        // so we should only publish data if there's a fix
        if(t.gpsFix()){
            lat = t.readLat();
            lon = t.readLon();
            alt = t.getAltitude();
            // Only publish if we're in transmittingData mode 1;
            if(transmittingData){
                // Short publish names save data!
                Particle.publish("G", t.readLatLon(), 60, PRIVATE);
                Serial.println("lat=");
                Serial.println(lat);
                Serial.println("lon=");
                Serial.println(lon);
                Serial.println("alt=");
                Serial.println(alt);
            }
            // but always report the data over serial for local development
            Serial.println(t.readLatLon());
            
        }
    }
}

// Allows you to remotely change whether a device is publishing to the cloud
// or is only reporting data over Serial. Saves data when using only Serial!
// Change the default at the top of the code.
int transmitMode(String command){
    transmittingData = atoi(command);
    return 1;
}

int servoToAngle(String command){
    angle = command.toInt();
    //myservo.attach(D0);
    myservo.write(angle);
    //myservo.detach();
    //analogWrite(D1, angle);
    return angle;
}

String latLonAlt = "";

// Actively ask for a GPS reading if you're impatient. Only publishes if there's
// a GPS fix, otherwise returns '0'
int gpsPublish(String command){
    if(t.gpsFix()){ 
        //latLonAlt = t.readLatLon() + " " + t.getAltitude();
        latLonAlt = t.readLatLon();
        Particle.publish("G", latLonAlt, 60, PRIVATE);
                Serial.println("lat=");
                Serial.println(lat);
                Serial.println("lon=");
                Serial.println(lon);
                Serial.println("alt=");
                Serial.println(alt);
        
        
        // uncomment next line if you want a manual publish to reset delay counter
        // lastPublish = millis();
        return 1;
    }
    else { return 0; }
}

// 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;}
}

#9

There are two different lines of code to make the external antenna work. one will work and other wont depending on the library used from what I understand. try these two

t.antennaExternal();

or

gps.antennaExternal();

It should be called right after gpsOn().


#10

ahhh just noticed you may not have been talking about an antenna, but rather a different gps module altogether. ill keep it up just in case you were


#11

Wait, when you say antenna what do you mean?
This?
https://www.aliexpress.com/item/MMCX-interface-driving-recorder-GPS-antenna-external-GPS-active-antenna-module-1-meter-long-rear-view/32756021781.html?spm=2114.search0303.3.2.lMSnGX


#12

https://www.amazon.com/gp/aw/d/B01M8QCZ9T/ref=mp_s_a_1_3?ie=UTF8&qid=1505254295&sr=8-3&pi=AC_SX236_SY340_FMwebp_QL65&keywords=gps+wangdd22&dpPl=1&dpID=413T3qwQMTL&ref=plSrch

I use the above and have good results with both versions of the shields… WAY better than the original module with no antenna. The code I pasted above is only required for the v1 asset tracker. The new asset tracker shield detects the external antenna automatically.


#13

Amazon wont ship to my country, so I have to resort to AliExpress.

But this is great stuff, i’ll order one right away, it’s been 2 weeks banging my head with this external GPS.


#14

OK… Wow… I am likely literally the most unqualified person on the entire internet to give advice in this forum, however after lots of very frustrating hours trying to get mine to work, this worked for me and I have 3 asset trackers in some of my heavy equipment working just fine.

If you cant get them shipped to your country, let me know. I can ship them to you from my house if you like. Send me a private message if you need help.


#15

That’s very kind of you!

There’s not much difference in my mind between the Chinese ones and what I can get on Amazon in terms of this particular device, so I’ll just save you the trouble. Thank you very much for the offer though, not many people would volunteer to do that :slight_smile:

Did you manage to get altitude?


#16

Digging through my drawers I found one! It was attached to a GPRS shield I had bought and forgotten about!

I may need an adapter to fit it in, but seems i’m all set!