20
20
*
21
21
* REVISION HISTORY
22
22
* Version 1.0 - Henrik Ekblad
23
- *
23
+ *
24
24
* DESCRIPTION
25
- * Example sketch showing how to interface with a GPS sensor.
25
+ * Example sketch showing how to interface with a GPS sensor.
26
26
* A GPS is also an excellent atomic time source.
27
27
* http://www.mysensors.org/build/gps
28
- */
28
+ */
29
29
30
30
// Enable debug prints to serial monitor
31
- #define MY_DEBUG
31
+ #define MY_DEBUG
32
32
33
33
// Enable and select radio type attached
34
34
#define MY_RADIO_NRF24
35
35
// #define MY_RADIO_RFM69
36
36
37
37
// GPS position send interval (in millisectonds)
38
- #define GPS_SEND_INTERVAL 10000
38
+ #define GPS_SEND_INTERVAL 10000
39
39
40
40
// The child id used for the gps sensor
41
41
#define CHILD_ID_GPS 1
@@ -47,7 +47,7 @@ static const int GPS_PIN = A0;
47
47
static const uint32_t GPSBaud = 9600 ;
48
48
49
49
// Offset hours adjustment from gps time (UTC)
50
- const int offset = 1 ;
50
+ const int offset = 1 ;
51
51
52
52
#include < SPI.h>
53
53
#include < TimeLib.h>
@@ -61,15 +61,15 @@ TinyGPSPlus gps;
61
61
MyMessage msg (CHILD_ID_GPS, V_POSITION);
62
62
63
63
// The serial connection to the GPS device
64
- // A5 pin can be left unconnected
65
- SoftwareSerial ss (GPS_PIN, A5);
64
+ // A5 pin can be left unconnected
65
+ SoftwareSerial ss (GPS_PIN, A5);
66
66
67
67
// Last time GPS position was sent to controller
68
68
unsigned long lastGPSSent = 0 ;
69
69
70
- // Some buffers
70
+ // Some buffers
71
71
char latBuf[11 ];
72
- char lngBuf[11 ];
72
+ char lngBuf[11 ];
73
73
char altBuf[6 ];
74
74
char payload[30 ];
75
75
char sz[64 ];
@@ -81,7 +81,7 @@ void setup() {
81
81
}
82
82
83
83
84
- void present () {
84
+ void presentation () {
85
85
// Send the sketch version information to the gateway and Controller
86
86
sendSketchInfo (" GPS Sensor" , " 1.0" );
87
87
@@ -96,10 +96,10 @@ void loop()
96
96
// Evaluate if it is time to send a new position
97
97
bool timeToSend = currentTime - lastGPSSent > GPS_SEND_INTERVAL;
98
98
99
- // Read gps data
100
- while (ss.available ())
99
+ // Read gps data
100
+ while (ss.available ())
101
101
gps.encode (ss.read ());
102
-
102
+
103
103
if (timeToSend) {
104
104
// Sync gps time with Arduino
105
105
updateTime ();
@@ -121,7 +121,7 @@ void loop()
121
121
sprintf (sz, " %02d/%02d/%02d %02d:%02d:%02d" , month (), day (), year (), hour (), minute (), second ());
122
122
Serial.println (sz);
123
123
124
-
124
+
125
125
} else {
126
126
if (millis () > 5000 && gps.charsProcessed () < 10 )
127
127
Serial.println (F (" No GPS data received: check wiring" ));
@@ -141,8 +141,6 @@ void updateTime()
141
141
setTime (t.hour (), t.minute (), t.second (), d.day (), d.month (), d.year ());
142
142
adjustTime (offset * SECS_PER_HOUR);
143
143
return ;
144
- }
144
+ }
145
145
Serial.println (F (" Unable to adjust time from GPS" ));
146
146
}
147
-
148
-
0 commit comments