|
| 1 | +/* |
| 2 | + Monitor AssistNow Autonomous data collection |
| 3 | + By: SparkFun Electronics / Paul Clark |
| 4 | + Date: November 29th, 2021 |
| 5 | + License: MIT. See license file for more information but you can |
| 6 | + basically do whatever you want with this code. |
| 7 | +
|
| 8 | + This example shows how to enable and monitor AssistNow Autonomous data collection by the module. |
| 9 | + A callback is used to monitor AssistNow Autonomous data availability for each satellite. |
| 10 | + A second callback is used to print the AOPSTATUS status. |
| 11 | +
|
| 12 | + If your GNSS board has battery-backup for the RAM - and all SparkFun boards do! - then you can: |
| 13 | + wait until the module has AssistNow Autonomous data for a few satellites; |
| 14 | + power-cycle the board; |
| 15 | + watch how fast it gets its first fix! |
| 16 | +
|
| 17 | + Note: this example will only work on boards which have plenty of RAM available. |
| 18 | + The UBX-NAV-SAT information occupies several kBytes. |
| 19 | +
|
| 20 | + Feel like supporting open source hardware? |
| 21 | + Buy a board from SparkFun! |
| 22 | + SparkFun Thing Plus - ESP32 WROOM: https://www.sparkfun.com/products/15663 |
| 23 | + ZED-F9P RTK2: https://www.sparkfun.com/products/16481 |
| 24 | + SparkFun GPS Breakout - ZOE-M8Q (Qwiic): https://www.sparkfun.com/products/15193 |
| 25 | +
|
| 26 | + Hardware Connections: |
| 27 | + Plug a Qwiic cable into the GNSS and a ESP32 Thing Plus |
| 28 | + If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425) |
| 29 | + Open the serial monitor at 115200 baud to see the output |
| 30 | +*/ |
| 31 | + |
| 32 | +#include <SparkFun_u-blox_GNSS_Arduino_Library.h> //http://librarymanager/All#SparkFun_u-blox_GNSS |
| 33 | +SFE_UBLOX_GNSS myGNSS; |
| 34 | + |
| 35 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 36 | + |
| 37 | +// Callback: printSATdata will be called when new NAV SAT data arrives |
| 38 | +// See u-blox_structs.h for the full definition of UBX_NAV_SAT_data_t |
| 39 | +// _____ You can use any name you like for the callback. Use the same name when you call setAutoNAVSATcallback |
| 40 | +// / _____ This _must_ be UBX_NAV_SAT_data_t |
| 41 | +// | / _____ You can use any name you like for the struct |
| 42 | +// | | / |
| 43 | +// | | | |
| 44 | +void printSATdata(UBX_NAV_SAT_data_t ubxDataStruct) |
| 45 | +{ |
| 46 | + //Serial.println(); |
| 47 | + |
| 48 | + Serial.print(F("UBX-NAV-SAT contains data for ")); |
| 49 | + Serial.print(ubxDataStruct.header.numSvs); |
| 50 | + if (ubxDataStruct.header.numSvs == 1) |
| 51 | + Serial.println(F(" SV")); |
| 52 | + else |
| 53 | + Serial.println(F(" SVs")); |
| 54 | + |
| 55 | + uint16_t numAopAvail = 0; // Count how many SVs have AssistNow Autonomous data available |
| 56 | + |
| 57 | + for (uint16_t block = 0; block < ubxDataStruct.header.numSvs; block++) // For each SV |
| 58 | + { |
| 59 | + if (ubxDataStruct.blocks[block].flags.bits.aopAvail == 1) // If the aopAvail bit is set |
| 60 | + numAopAvail++; // Increment the number of SVs |
| 61 | + } |
| 62 | + |
| 63 | + Serial.print(F("AssistNow Autonomous data is available for ")); |
| 64 | + Serial.print(numAopAvail); |
| 65 | + if (numAopAvail == 1) |
| 66 | + Serial.println(F(" SV")); |
| 67 | + else |
| 68 | + Serial.println(F(" SVs")); |
| 69 | +} |
| 70 | + |
| 71 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 72 | + |
| 73 | +// Callback: printAOPstatus will be called when new NAV AOPSTATUS data arrives |
| 74 | +// See u-blox_structs.h for the full definition of UBX_NAV_AOPSTATUS_data_t |
| 75 | +// _____ You can use any name you like for the callback. Use the same name when you call setAutoNAVAOPSTATUScallback |
| 76 | +// / _____ This _must_ be UBX_NAV_AOPSTATUS_data_t |
| 77 | +// | / _____ You can use any name you like for the struct |
| 78 | +// | | / |
| 79 | +// | | | |
| 80 | +void printAOPstatus(UBX_NAV_AOPSTATUS_data_t ubxDataStruct) |
| 81 | +{ |
| 82 | + //Serial.println(); |
| 83 | + |
| 84 | + Serial.print(F("AOPSTATUS status is ")); |
| 85 | + Serial.println(ubxDataStruct.status); |
| 86 | +} |
| 87 | + |
| 88 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 89 | + |
| 90 | +// Callback: printPVTdata will be called when new NAV PVT data arrives |
| 91 | +// See u-blox_structs.h for the full definition of UBX_NAV_PVT_data_t |
| 92 | +// _____ You can use any name you like for the callback. Use the same name when you call setAutoPVTcallback |
| 93 | +// / _____ This _must_ be UBX_NAV_PVT_data_t |
| 94 | +// | / _____ You can use any name you like for the struct |
| 95 | +// | | / |
| 96 | +// | | | |
| 97 | +void printPVTdata(UBX_NAV_PVT_data_t ubxDataStruct) |
| 98 | +{ |
| 99 | + // Print the UBX-NAV-PVT data so we can see how quickly the fixType goes to 3D |
| 100 | + |
| 101 | + Serial.println(); |
| 102 | + |
| 103 | + long latitude = ubxDataStruct.lat; // Print the latitude |
| 104 | + Serial.print(F("Lat: ")); |
| 105 | + Serial.print(latitude); |
| 106 | + |
| 107 | + long longitude = ubxDataStruct.lon; // Print the longitude |
| 108 | + Serial.print(F(" Long: ")); |
| 109 | + Serial.print(longitude); |
| 110 | + Serial.print(F(" (degrees * 10^-7)")); |
| 111 | + |
| 112 | + long altitude = ubxDataStruct.hMSL; // Print the height above mean sea level |
| 113 | + Serial.print(F(" Alt: ")); |
| 114 | + Serial.print(altitude); |
| 115 | + Serial.print(F(" (mm)")); |
| 116 | + |
| 117 | + byte fixType = ubxDataStruct.fixType; // Print the fix type |
| 118 | + Serial.print(F(" Fix: ")); |
| 119 | + if(fixType == 0) Serial.print(F("No fix")); |
| 120 | + else if(fixType == 1) Serial.print(F("Dead reckoning")); |
| 121 | + else if(fixType == 2) Serial.print(F("2D")); |
| 122 | + else if(fixType == 3) Serial.print(F("3D")); |
| 123 | + else if(fixType == 4) Serial.print(F("GNSS + Dead reckoning")); |
| 124 | + else if(fixType == 5) Serial.print(F("Time only")); |
| 125 | + |
| 126 | + Serial.println(); |
| 127 | +} |
| 128 | + |
| 129 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 130 | + |
| 131 | +void setup() |
| 132 | +{ |
| 133 | + delay(1000); |
| 134 | + |
| 135 | + Serial.begin(115200); |
| 136 | + Serial.println(F("AssistNow Example")); |
| 137 | + |
| 138 | + //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 139 | + // Start I2C. Connect to the GNSS. |
| 140 | + |
| 141 | + Wire.begin(); //Start I2C |
| 142 | + |
| 143 | + //myGNSS.enableDebugging(Serial, true); // Uncomment this line to see the 'major' debug messages on Serial |
| 144 | + |
| 145 | + if (myGNSS.begin() == false) //Connect to the Ublox module using Wire port |
| 146 | + { |
| 147 | + Serial.println(F("u-blox GPS not detected at default I2C address. Please check wiring. Freezing.")); |
| 148 | + while (1); |
| 149 | + } |
| 150 | + Serial.println(F("u-blox module connected")); |
| 151 | + |
| 152 | + myGNSS.setI2COutput(COM_TYPE_UBX); //Turn off NMEA noise |
| 153 | + myGNSS.saveConfigSelective(VAL_CFG_SUBSEC_IOPORT); //Save (only) the communications port settings to flash and BBR |
| 154 | + |
| 155 | + //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 156 | + // Enable AssistNow Autonomous data collection. |
| 157 | + |
| 158 | + if (myGNSS.setAopCfg(1) == true) |
| 159 | + { |
| 160 | + Serial.println(F("aopCfg enabled")); |
| 161 | + } |
| 162 | + else |
| 163 | + { |
| 164 | + Serial.println(F("Could not enable aopCfg. Please check wiring. Freezing.")); |
| 165 | + while (1); |
| 166 | + } |
| 167 | + |
| 168 | + //=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 169 | + // Enable automatic UBX-NAV-SAT and UBX-NAV-AOPSTATUS messages and set up the callbacks |
| 170 | + |
| 171 | + myGNSS.setNavigationFrequency(1); //Produce one solution per second |
| 172 | + |
| 173 | + myGNSS.setAutoNAVSATcallback(&printSATdata); // Enable automatic NAV SAT messages with callback to printSATdata |
| 174 | + myGNSS.setAutoAOPSTATUScallback(&printAOPstatus); // Enable automatic NAV AOPSTATUS messages with callback to printAOPstatus |
| 175 | + myGNSS.setAutoPVTcallback(&printPVTdata); // Enable automatic NAV PVT messages with callback to printPVTdata |
| 176 | +} |
| 177 | + |
| 178 | +//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= |
| 179 | + |
| 180 | +void loop() |
| 181 | +{ |
| 182 | + myGNSS.checkUblox(); // Check for the arrival of new data and process it. |
| 183 | + myGNSS.checkCallbacks(); // Check if any callbacks are waiting to be processed. |
| 184 | + |
| 185 | + Serial.print("."); |
| 186 | + delay(50); |
| 187 | +} |
0 commit comments