MySensors Library & Examples  2.3.2
TinyGsmClientSIM808.h
1 
9 #ifndef TinyGsmClientSIM808_h
10 #define TinyGsmClientSIM808_h
11 
12 #include "TinyGsmClientSIM800.h"
13 
15 {
16 
17 public:
18 
19  explicit TinyGsmSim808(Stream& stream)
20  : TinyGsmSim800(stream)
21  {}
22 
23  /*
24  * GPS location functions
25  */
26 
27  // enable GPS
28  bool enableGPS()
29  {
30  uint16_t state;
31 
32  sendAT(GF("+CGNSPWR=1"));
33  if (waitResponse() != 1) {
34  return false;
35  }
36 
37  return true;
38  }
39 
40  bool disableGPS()
41  {
42  uint16_t state;
43 
44  sendAT(GF("+CGNSPWR=0"));
45  if (waitResponse() != 1) {
46  return false;
47  }
48 
49  return true;
50  }
51 
52  // get the RAW GPS output
53  // works only with ans SIM808 V2
54  String getGPSraw()
55  {
56  sendAT(GF("+CGNSINF"));
57  if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) {
58  return "";
59  }
60  String res = stream.readStringUntil('\n');
61  waitResponse();
62  res.trim();
63  return res;
64  }
65 
66  // get GPS informations
67  // works only with ans SIM808 V2
68  bool getGPS(float *lat, float *lon, float *speed=0, int *alt=0, int *vsat=0, int *usat=0)
69  {
70  //String buffer = "";
71  char chr_buffer[12];
72  bool fix = false;
73 
74  sendAT(GF("+CGNSINF"));
75  if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) {
76  return false;
77  }
78 
79  stream.readStringUntil(','); // mode
80  if ( stream.readStringUntil(',').toInt() == 1 ) {
81  fix = true;
82  }
83  stream.readStringUntil(','); //utctime
84  *lat = stream.readStringUntil(',').toFloat(); //lat
85  *lon = stream.readStringUntil(',').toFloat(); //lon
86  if (alt != NULL) {
87  *alt = stream.readStringUntil(',').toFloat(); //lon
88  }
89  if (speed != NULL) {
90  *speed = stream.readStringUntil(',').toFloat(); //speed
91  }
92  stream.readStringUntil(',');
93  stream.readStringUntil(',');
94  stream.readStringUntil(',');
95  stream.readStringUntil(',');
96  stream.readStringUntil(',');
97  stream.readStringUntil(',');
98  stream.readStringUntil(',');
99  if (vsat != NULL) {
100  *vsat = stream.readStringUntil(',').toInt(); //viewed satelites
101  }
102  if (usat != NULL) {
103  *usat = stream.readStringUntil(',').toInt(); //used satelites
104  }
105  stream.readStringUntil('\n');
106 
107  waitResponse();
108 
109  return fix;
110  }
111 
112  // get GPS time
113  // works only with SIM808 V2
114  bool getGPSTime(int *year, int *month, int *day, int *hour, int *minute, int *second)
115  {
116  bool fix = false;
117  char chr_buffer[12];
118  sendAT(GF("+CGNSINF"));
119  if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) {
120  return false;
121  }
122 
123  for (int i = 0; i < 3; i++) {
124  String buffer = stream.readStringUntil(',');
125  buffer.toCharArray(chr_buffer, sizeof(chr_buffer));
126  switch (i) {
127  case 0:
128  //mode
129  break;
130  case 1:
131  //fixstatus
132  if ( buffer.toInt() == 1 ) {
133  fix = buffer.toInt();
134  }
135  break;
136  case 2:
137  *year = buffer.substring(0,4).toInt();
138  *month = buffer.substring(4,6).toInt();
139  *day = buffer.substring(6,8).toInt();
140  *hour = buffer.substring(8,10).toInt();
141  *minute = buffer.substring(10,12).toInt();
142  *second = buffer.substring(12,14).toInt();
143  break;
144 
145  default:
146  // if nothing else matches, do the default
147  // default is optional
148  break;
149  }
150  }
151  String res = stream.readStringUntil('\n');
152  waitResponse();
153 
154  if (fix) {
155  return true;
156  } else {
157  return false;
158  }
159  }
160 
161 };
162 
163 #endif
TinyGsmSim800
Definition: TinyGsmClientSIM800.h:43
TinyGsmSim808
Definition: TinyGsmClientSIM808.h:14