-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGetTime.ino
41 lines (34 loc) · 1.18 KB
/
GetTime.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/**
* This example demonstrates how to get the current time using the ArduinoCellular library.
* It derives the time from GPS connection.
*
* Instructions:
* 1. Move the Arduino Pro 4G Module to an outdoor location with a clear view of the sky.
* 2. Provide sufficient power to the Arduino Pro 4G Module. Ideally, use a 5V power supply
* 3. Upload the sketch to the connected Arduino board.
* 4. Open the serial monitor to view the output.
*
* Initial author: Cristian Dragomir
*/
#include "ArduinoCellular.h"
ArduinoCellular cellular = ArduinoCellular();
void setup(){
Serial.begin(115200);
while (!Serial);
cellular.begin();
if(!cellular.enableGPS()){
Serial.println("Failed to enable GPS");
while(true); // Stop the program
}
delay(2000); // Give the modem some time to initialize
}
void loop(){
Geolocation location = cellular.getGPSLocation(10000);
if(location.latitude == 0.0 && location.longitude == 0.0){
Serial.println("Failed to get GPS location");
} else {
Time time = cellular.getGPSTime();
Serial.print("Current time (ISO8601): "); Serial.println(time.getISO8601());
}
delay(10000);
}