-
Notifications
You must be signed in to change notification settings - Fork 0
/
theftprotection_temp.ino
123 lines (105 loc) · 2.8 KB
/
theftprotection_temp.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/**
Arduino GPS Client to retrieve the Location data from the GPS shield.
The information are processed through the TinyGPS library and send via the Akeru
**/
#include <SoftwareSerial.h>
#include <Akeru.h>
#include <TinyGPS.h>
#include <dht.h>
// Pin analog 0 for temp/humidity sensor
#define dht_dpin A0
dht DHT;
TinyGPS gps;
// Akeru uses RX=5, TX=4
SoftwareSerial ssAkeru(5,4);
SoftwareSerial ss(6,7);
void setup()
{
Serial.begin(9600);
Serial.print("Finished setup\n");
}
typedef struct {
bool theftprotection;
float lat;
float lng;
int temperature;
} Payload;
void loop()
{
bool newData = false;
unsigned long chars;
unsigned short sentences, failed;
Payload p;
ss.begin(9600);
// PARSE GPS data for one second and report some key values
for (unsigned long start = millis(); millis() - start < 1000;)
{
while (ss.available())
{
char c = ss.read();
//Serial.print(c); //uncomment to see the full NMEA datasets
if (gps.encode(c)) // Did a new valid sentence come in?
newData = true;
}
}
// end gps in order to make port listening for akeru available
ss.end();
if (newData)
{
// IF NEW GPS-DATA
float flat, flon;
unsigned long age;
gps.f_get_position(&flat, &flon, &age);
Serial.println("");
Serial.print("LAT = ");
Serial.println(flat == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flat, 6);
Serial.print("LON = ");
Serial.println(flon == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : flon, 6);
newData = false;
DHT.read11(dht_dpin);
Serial.print("Humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C ");
p.theftprotection = true;
p.lat = flat;
p.lng = flon;
p.temperature = (int)DHT.temperature;
// INIT MODEM
Akeru.begin();
// Wait 1 second for the modem to warm up
delay(1000);
if(!Akeru.isReady()) {
Serial.println("Modem not ready");
} else {
Serial.println("Modem ready");
// CHECK IF LNG/LAT != 0
if(p.lat == 0 || p.lng == 0) {
Serial.println("Unknown position");
} else {
Serial.println("Message-Size: ");
Serial.println(sizeof(p));
Akeru.send(&p, sizeof(p));
Serial.println("Message sent!");
delay(1000);
}
}
// end modem in order to make port listening for gps available
ssAkeru.end();
} else {
Serial.print("Theft-Protection: 1\n");
Serial.print("No GPS data\n");
Serial.print("LAT = 0.00000\n");
Serial.print("LON = 0.00000\n");
DHT.read11(dht_dpin);
Serial.print("Humidity = ");
Serial.print(DHT.humidity);
Serial.print("% ");
Serial.print("temperature = ");
Serial.print(DHT.temperature);
Serial.println("C\n");
delay(1000);
}
}