Skip to content

Commit c25311b

Browse files
committed
Add AssistNowOnline examples
1 parent e464c7c commit c25311b

File tree

11 files changed

+1490
-0
lines changed

11 files changed

+1490
-0
lines changed
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
/*
2+
Use ESP32 WiFi to get AssistNow Online data from u-blox Thingstream
3+
By: SparkFun Electronics / Paul Clark
4+
Date: November 24th, 2021
5+
License: MIT. See license file for more information.
6+
7+
This example shows how to obtain AssistNow Online data from u-blox Thingstream over WiFi
8+
and push it over I2C to a u-blox module.
9+
10+
You will need to have a token to be able to access Thingstream. See the AssistNow README for more details.
11+
12+
Update secrets.h with your:
13+
- WiFi credentials
14+
- AssistNow token string
15+
16+
Uncomment the "#define USE_MGA_ACKs" below to test the more robust method of using the
17+
UBX_MGA_ACK_DATA0 acknowledgements to confirm that each MGA message has been accepted.
18+
19+
Feel like supporting open source hardware?
20+
Buy a board from SparkFun!
21+
SparkFun Thing Plus - ESP32 WROOM: https://www.sparkfun.com/products/15663
22+
ZED-F9P RTK2: https://www.sparkfun.com/products/16481
23+
SparkFun GPS Breakout - ZOE-M8Q (Qwiic): https://www.sparkfun.com/products/15193
24+
25+
Hardware Connections:
26+
Plug a Qwiic cable into the GNSS and a ESP32 Thing Plus
27+
If you don't have a platform with a Qwiic connection use the SparkFun Qwiic Breadboard Jumper (https://www.sparkfun.com/products/14425)
28+
Open the serial monitor at 115200 baud to see the output
29+
*/
30+
31+
//#define USE_MGA_ACKs // Uncomment this line to use the UBX_MGA_ACK_DATA0 acknowledgements
32+
33+
#include <Wire.h>
34+
#include <HTTPClient.h>
35+
#include "secrets.h"
36+
37+
const char assistNowServer[] = "https://online-live1.services.u-blox.com";
38+
//const char assistNowServer[] = "https://online-live2.services.u-blox.com"; // Alternate server
39+
40+
const char getQuery[] = "GetOnlineData.ashx?";
41+
const char tokenPrefix[] = "token=";
42+
const char tokenSuffix[] = ";";
43+
const char getGNSS[] = "gnss=gps,glo;"; // GNSS can be: gps,qzss,glo,bds,gal
44+
const char getDataType[] = "datatype=eph,alm,aux;"; // Data type can be: eph,alm,aux,pos
45+
46+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
47+
48+
#include <SparkFun_u-blox_GNSS_v3.h> //http://librarymanager/All#SparkFun_u-blox_GNSS_v3
49+
SFE_UBLOX_GNSS myGNSS;
50+
51+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
52+
53+
void setup()
54+
{
55+
delay(1000);
56+
57+
Serial.begin(115200);
58+
Serial.println(F("AssistNow Example"));
59+
60+
while (Serial.available()) Serial.read(); // Empty the serial buffer
61+
Serial.println(F("Press any key to begin..."));
62+
while (!Serial.available()); // Wait for a keypress
63+
64+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
65+
// Start I2C. Connect to the GNSS.
66+
67+
Wire.begin(); //Start I2C
68+
69+
if (myGNSS.begin() == false) //Connect to the Ublox module using Wire port
70+
{
71+
Serial.println(F("u-blox GPS not detected at default I2C address. Please check wiring. Freezing."));
72+
while (1);
73+
}
74+
Serial.println(F("u-blox module connected"));
75+
76+
myGNSS.setI2COutput(COM_TYPE_UBX); //Turn off NMEA noise
77+
78+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
79+
// Connect to WiFi.
80+
81+
Serial.print(F("Connecting to local WiFi"));
82+
83+
WiFi.begin(ssid, password);
84+
while (WiFi.status() != WL_CONNECTED) {
85+
delay(500);
86+
Serial.print(F("."));
87+
}
88+
Serial.println();
89+
90+
Serial.println(F("WiFi connected!"));
91+
92+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
93+
// Use HTTP GET to receive the AssistNow_Online data
94+
95+
const int URL_BUFFER_SIZE = 256;
96+
char theURL[URL_BUFFER_SIZE]; // This will contain the HTTP URL
97+
int payloadSize = 0; // This will be updated with the length of the data we get from the server
98+
String payload; // This will store the data we get from the server
99+
100+
// Assemble the URL
101+
// Note the slash after the first %s (assistNowServer)
102+
snprintf(theURL, URL_BUFFER_SIZE, "%s/%s%s%s%s%s%s",
103+
assistNowServer,
104+
getQuery,
105+
tokenPrefix,
106+
myAssistNowToken,
107+
tokenSuffix,
108+
getGNSS,
109+
getDataType);
110+
111+
Serial.print(F("HTTP URL is: "));
112+
Serial.println(theURL);
113+
114+
HTTPClient http;
115+
116+
http.begin(theURL);
117+
118+
int httpCode = http.GET(); // HTTP GET
119+
120+
// httpCode will be negative on error
121+
if(httpCode > 0)
122+
{
123+
// HTTP header has been sent and Server response header has been handled
124+
Serial.printf("[HTTP] GET... code: %d\r\n", httpCode);
125+
126+
// If the GET was successful, read the data
127+
if(httpCode == HTTP_CODE_OK) // Check for code 200
128+
{
129+
payloadSize = http.getSize();
130+
Serial.printf("Server returned %d bytes\r\n", payloadSize);
131+
132+
payload = http.getString(); // Get the payload
133+
134+
// Pretty-print the payload as HEX
135+
/*
136+
int i;
137+
for(i = 0; i < payloadSize; i++)
138+
{
139+
if (payload[i] < 0x10) // Print leading zero
140+
Serial.print("0");
141+
Serial.print(payload[i], HEX);
142+
Serial.print(" ");
143+
if ((i % 16) == 15)
144+
Serial.println();
145+
}
146+
if ((i % 16) != 15)
147+
Serial.println();
148+
*/
149+
}
150+
}
151+
else
152+
{
153+
Serial.printf("[HTTP] GET... failed, error: %s\r\n", http.errorToString(httpCode).c_str());
154+
}
155+
156+
http.end();
157+
158+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
159+
// Push the AssistNow data to the module
160+
161+
if (payloadSize > 0)
162+
{
163+
// Uncomment the next line to enable the 'major' debug messages on Serial so you can see what AssistNow data is being sent
164+
//myGNSS.enableDebugging(Serial, true);
165+
166+
#ifndef USE_MGA_ACKs
167+
168+
// ***** Don't use the UBX_MGA_ACK_DATA0 messages *****
169+
170+
// Tell the module not to return UBX_MGA_ACK_DATA0 messages when we push the AssistNow data
171+
myGNSS.setAckAiding(0);
172+
173+
// Push all the AssistNow data. Don't use UBX_MGA_ACK_DATA0's. Use the default delay of 7ms between messages.
174+
myGNSS.pushAssistNowData(payload, (size_t)payloadSize);
175+
176+
#else
177+
178+
// ***** Use the UBX_MGA_ACK_DATA0 messages *****
179+
180+
// Tell the module to return UBX_MGA_ACK_DATA0 messages when we push the AssistNow data
181+
myGNSS.setAckAiding(1);
182+
183+
// Speed things up by setting setI2CpollingWait to 1ms
184+
myGNSS.setI2CpollingWait(1);
185+
186+
// Push all the AssistNow data.
187+
// We have called setAckAiding(1) to instruct the module to return MGA-ACK messages.
188+
// So, we could set the pushAssistNowData mgaAck parameter to SFE_UBLOX_MGA_ASSIST_ACK_YES.
189+
// But, just for giggles, let's use SFE_UBLOX_MGA_ASSIST_ACK_ENQUIRE just to confirm that the
190+
// MGA-ACK messages are actually enabled.
191+
// Wait for up to 100ms for each ACK to arrive! 100ms is a bit excessive... 7ms is nearer the mark.
192+
myGNSS.pushAssistNowData(payload, (size_t)payloadSize, SFE_UBLOX_MGA_ASSIST_ACK_YES, 100);
193+
194+
// Set setI2CpollingWait to 125ms to avoid pounding the I2C bus
195+
myGNSS.setI2CpollingWait(125);
196+
197+
#endif
198+
199+
}
200+
201+
Serial.println(F("Here we go!"));
202+
}
203+
204+
//=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
205+
206+
void loop()
207+
{
208+
// Print the UBX-NAV-PVT data so we can see how quickly the fixType goes to 3D
209+
210+
long latitude = myGNSS.getLatitude();
211+
Serial.print(F("Lat: "));
212+
Serial.print(latitude);
213+
214+
long longitude = myGNSS.getLongitude();
215+
Serial.print(F(" Long: "));
216+
Serial.print(longitude);
217+
Serial.print(F(" (degrees * 10^-7)"));
218+
219+
long altitude = myGNSS.getAltitude();
220+
Serial.print(F(" Alt: "));
221+
Serial.print(altitude);
222+
Serial.print(F(" (mm)"));
223+
224+
byte SIV = myGNSS.getSIV();
225+
Serial.print(F(" SIV: "));
226+
Serial.print(SIV);
227+
228+
byte fixType = myGNSS.getFixType();
229+
Serial.print(F(" Fix: "));
230+
if(fixType == 0) Serial.print(F("No fix"));
231+
else if(fixType == 1) Serial.print(F("Dead reckoning"));
232+
else if(fixType == 2) Serial.print(F("2D"));
233+
else if(fixType == 3) Serial.print(F("3D"));
234+
else if(fixType == 4) Serial.print(F("GNSS + Dead reckoning"));
235+
else if(fixType == 5) Serial.print(F("Time only"));
236+
237+
Serial.println();
238+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//Your WiFi credentials
2+
const char ssid[] = "TRex";
3+
const char password[] = "hasBigTeeth";
4+
5+
//Your AssistNow token
6+
const char myAssistNowToken[] = "58XXXXXXXXXXXXXXXXXXYQ";

0 commit comments

Comments
 (0)