Snorktracker
 All Data Structures Files Functions Variables Macros Pages
Public Member Functions | Protected Member Functions | Protected Attributes
MySmsCmd Class Reference

#include <SmsCmd.h>

Public Member Functions

 MySmsCmd (MyGsmGps &gsmGps, MyOptions &options, MyData &data)
 
bool begin ()
 
void handleClient ()
 

Protected Member Functions

void checkSms ()
 
String getGoogleMapGpsUrl ()
 
void sendSms (const String &message)
 
void sendOk (const SmsData &sms)
 
bool readValues (String &value, const String message)
 
bool readValues (long &value, const String message)
 
bool readValues (long &value, long &value2, const String message)
 
void cmdOn (const SmsData &sms)
 
void cmdOff (const SmsData &sms)
 
void cmdStatus (const SmsData &sms)
 
void cmdPsm (const SmsData &sms)
 
void cmdGps (const SmsData &sms)
 
void cmdSms (const SmsData &sms)
 
void cmdMqtt (const SmsData &sms)
 
void cmdPhone (const SmsData &sms)
 
void cmdDefault (const SmsData &sms)
 

Protected Attributes

MyGsmGpsmyGsmGps
 Reference to the gsm/gps instance.
 
MyOptionsmyOptions
 Reference to the options.
 
MyDatamyData
 Reference to the data.
 

Detailed Description

SMS Controller class to manage receiving SMS commands.

Definition at line 26 of file SmsCmd.h.

Constructor & Destructor Documentation

MySmsCmd::MySmsCmd ( MyGsmGps gsmGps,
MyOptions options,
MyData data 
)

Constructor

Definition at line 65 of file SmsCmd.h.

66  : myGsmGps(gsmGps)
67  , myOptions(options)
68  , myData(data)
69 {
70 }
MyOptions & myOptions
Reference to the options.
Definition: SmsCmd.h:30
MyData & myData
Reference to the data.
Definition: SmsCmd.h:31
MyGsmGps & myGsmGps
Reference to the gsm/gps instance.
Definition: SmsCmd.h:29

Member Function Documentation

bool MySmsCmd::begin ( )

Log only the start of the sms controller

Definition at line 73 of file SmsCmd.h.

References MyDbg().

Referenced by setup().

74 {
75  MyDbg(F("MySmsCmd::begin"));
76  return true;
77 }
void MyDbg(String info, bool fromWebServer=false, bool newline=true)
Definition: Utils.h:94
void MySmsCmd::checkSms ( )
protected

Checks for new sms and parse the commands from the message

Definition at line 102 of file SmsCmd.h.

References cmdDefault(), cmdGps(), cmdMqtt(), cmdOff(), cmdOn(), cmdPhone(), cmdPsm(), cmdSms(), cmdStatus(), MyGsmGps::deleteSMS(), MyGsmGps::getSMS(), SmsData::index, MyData::isGsmActive, SmsData::message, myData, MyDbg(), myGsmGps, and SmsData::phoneNumber.

Referenced by handleClient().

103 {
104  if (!myData.isGsmActive) {
105  return;
106  }
107 
108  SmsData sms;
109 
110  MyDbg(F("checkSMS"));
111  while (myGsmGps.getSMS(sms)) {
112  String messageLower = sms.message;
113 
114  messageLower.toLowerCase();
115  myGsmGps.deleteSMS(sms.index);
116 
117  MyDbg((String) F("SMS: ") + sms.message + F(" [") + sms.phoneNumber + F("]"));
118  if (messageLower.indexOf(F("on")) == 0) {
119  cmdOn(sms);
120  } else if (messageLower.indexOf(F("off")) == 0) {
121  cmdOff(sms);
122  } else if (messageLower.indexOf(F("status")) == 0) {
123  cmdStatus(sms);
124  } else if (messageLower.indexOf(F("psm")) == 0) {
125  cmdPsm(sms);
126  } else if (messageLower.indexOf(F("gps")) == 0) {
127  cmdGps(sms);
128  } else if (messageLower.indexOf(F("sms")) == 0) {
129  cmdSms(sms);
130  } else if (messageLower.indexOf(F("mqtt")) == 0) {
131  cmdMqtt(sms);
132  } else if (messageLower.indexOf(F("phone")) == 0) {
133  cmdPhone(sms);
134  } else {
135  cmdDefault(sms);
136  }
137  }
138 }
String phoneNumber
Sms sender number.
Definition: Sim808.h:37
void MyDbg(String info, bool fromWebServer=false, bool newline=true)
Definition: Utils.h:94
void cmdSms(const SmsData &sms)
Definition: SmsCmd.h:272
String message
Sms content.
Definition: Sim808.h:40
void cmdPhone(const SmsData &sms)
Definition: SmsCmd.h:292
bool deleteSMS(long index)
Definition: GsmGps.h:292
MyData & myData
Reference to the data.
Definition: SmsCmd.h:31
void cmdOff(const SmsData &sms)
Definition: SmsCmd.h:204
MyGsmGps & myGsmGps
Reference to the gsm/gps instance.
Definition: SmsCmd.h:29
long index
Sms index on sim card.
Definition: Sim808.h:35
void cmdGps(const SmsData &sms)
Definition: SmsCmd.h:258
void cmdPsm(const SmsData &sms)
Definition: SmsCmd.h:237
void cmdMqtt(const SmsData &sms)
Definition: SmsCmd.h:282
void cmdStatus(const SmsData &sms)
Definition: SmsCmd.h:212
void cmdOn(const SmsData &sms)
Definition: SmsCmd.h:195
bool isGsmActive
Is the sim808 modul connected to a gsm network?
Definition: Data.h:68
Definition: Sim808.h:32
bool getSMS(SmsData &sms)
Definition: GsmGps.h:268
void cmdDefault(const SmsData &sms)
Definition: SmsCmd.h:302
void MySmsCmd::cmdDefault ( const SmsData sms)
protected

Default sms response if something is wrong

Definition at line 302 of file SmsCmd.h.

References sendSms().

Referenced by checkSms(), cmdGps(), cmdMqtt(), cmdPhone(), cmdPsm(), and cmdSms().

303 {
304  String info;
305 
306  info += F("wrong command\n");
307  info += F("on\n");
308  info += F("off\n");
309  info += F("status\n");
310  info += F("psm[:off] - power saving mode\n");
311  info += F("gps[:15] - check every (sec)\n");
312  info += F("sms[:15] - check every (sec)\n");
313  info += F("mqtt[30:60] - (moving:standing (sec)\n");
314  info += F("phone:1234\n");
315  sendSms(info);
316 }
void sendSms(const String &message)
Definition: SmsCmd.h:141
void MySmsCmd::cmdGps ( const SmsData sms)
protected

Command: send the gps position as an google map URL.

Definition at line 258 of file SmsCmd.h.

References cmdDefault(), getGoogleMapGpsUrl(), MyOptions::gpsCheckIntervalSec, SmsData::message, myOptions, readValues(), sendOk(), and sendSms().

Referenced by checkSms().

259 {
260  if (sms.message.indexOf(F(":")) == -1) {
262  } else {
264  sendOk(sms);
265  } else {
266  cmdDefault(sms);
267  }
268  }
269 }
MyOptions & myOptions
Reference to the options.
Definition: SmsCmd.h:30
long gpsCheckIntervalSec
Time interval to check the gps position.
Definition: Options.h:45
String message
Sms content.
Definition: Sim808.h:40
String getGoogleMapGpsUrl()
Definition: SmsCmd.h:88
void sendSms(const String &message)
Definition: SmsCmd.h:141
bool readValues(String &value, const String message)
Definition: SmsCmd.h:153
void sendOk(const SmsData &sms)
Definition: SmsCmd.h:147
void cmdDefault(const SmsData &sms)
Definition: SmsCmd.h:302
void MySmsCmd::cmdMqtt ( const SmsData sms)
protected

Command: Set the mqtt sending time checking time values.

Definition at line 282 of file SmsCmd.h.

References cmdDefault(), SmsData::message, MyOptions::mqttSendOnMoveEverySec, MyOptions::mqttSendOnNonMoveEverySec, myOptions, readValues(), and sendOk().

Referenced by checkSms().

283 {
285  sendOk(sms);
286  } else {
287  cmdDefault(sms);
288  }
289 }
MyOptions & myOptions
Reference to the options.
Definition: SmsCmd.h:30
String message
Sms content.
Definition: Sim808.h:40
bool readValues(String &value, const String message)
Definition: SmsCmd.h:153
void sendOk(const SmsData &sms)
Definition: SmsCmd.h:147
long mqttSendOnNonMoveEverySec
Send data interval to MQTT server on non moving.
Definition: Options.h:62
long mqttSendOnMoveEverySec
Send data interval to MQTT server on moving.
Definition: Options.h:61
void cmdDefault(const SmsData &sms)
Definition: SmsCmd.h:302
void MySmsCmd::cmdOff ( const SmsData sms)
protected

Command: switch off the modules

Definition at line 204 of file SmsCmd.h.

References myOptions, MyOptions::powerOn, MyOptions::save(), and sendOk().

Referenced by checkSms().

205 {
206  myOptions.powerOn = false;
207  myOptions.save();
208  sendOk(sms);
209 }
MyOptions & myOptions
Reference to the options.
Definition: SmsCmd.h:30
bool powerOn
Is the GSM power from the DC-DC modul switched on?
Definition: Options.h:41
bool save()
Definition: Options.h:209
void sendOk(const SmsData &sms)
Definition: SmsCmd.h:147
void MySmsCmd::cmdOn ( const SmsData sms)
protected

Command: switch on the modules

Definition at line 195 of file SmsCmd.h.

References MyOptions::isGpsEnabled, myOptions, MyOptions::powerOn, MyOptions::save(), and sendOk().

Referenced by checkSms().

196 {
197  myOptions.powerOn = true;
198  myOptions.isGpsEnabled = true;
199  myOptions.save();
200  sendOk(sms);
201 }
MyOptions & myOptions
Reference to the options.
Definition: SmsCmd.h:30
bool isGpsEnabled
Is the gps part of the sim808 active?
Definition: Options.h:43
bool powerOn
Is the GSM power from the DC-DC modul switched on?
Definition: Options.h:41
bool save()
Definition: Options.h:209
void sendOk(const SmsData &sms)
Definition: SmsCmd.h:147
void MySmsCmd::cmdPhone ( const SmsData sms)
protected

Command: Set the receiving phone number.

Definition at line 292 of file SmsCmd.h.

References cmdDefault(), SmsData::message, myOptions, MyOptions::phoneNumber, readValues(), and sendOk().

Referenced by checkSms().

293 {
295  sendOk(sms);
296  } else {
297  cmdDefault(sms);
298  }
299 }
MyOptions & myOptions
Reference to the options.
Definition: SmsCmd.h:30
String phoneNumber
Pone number for sms answers.
Definition: Options.h:47
String message
Sms content.
Definition: Sim808.h:40
bool readValues(String &value, const String message)
Definition: SmsCmd.h:153
void sendOk(const SmsData &sms)
Definition: SmsCmd.h:147
void cmdDefault(const SmsData &sms)
Definition: SmsCmd.h:302
void MySmsCmd::cmdPsm ( const SmsData sms)
protected

Command: switch the power saving mode on or off.

Definition at line 237 of file SmsCmd.h.

References cmdDefault(), MyOptions::isDeepSleepEnabled, SmsData::message, MyDbg(), myOptions, readValues(), MyOptions::save(), and sendOk().

Referenced by checkSms().

238 {
239  if (sms.message.indexOf(F(":")) == -1) {
241  myOptions.save();
242  sendOk(sms);
243  } else {
244  String off;
245 
246  if (readValues(off, sms.message) && off == F("off")) {
248  myOptions.save();
249  sendOk(sms);
250  } else {
251  MyDbg((String) F("psm:[") + off + F("]"));
252  cmdDefault(sms);
253  }
254  }
255 }
MyOptions & myOptions
Reference to the options.
Definition: SmsCmd.h:30
void MyDbg(String info, bool fromWebServer=false, bool newline=true)
Definition: Utils.h:94
String message
Sms content.
Definition: Sim808.h:40
bool save()
Definition: Options.h:209
bool readValues(String &value, const String message)
Definition: SmsCmd.h:153
void sendOk(const SmsData &sms)
Definition: SmsCmd.h:147
bool isDeepSleepEnabled
Should the system go into deepsleep if needed.
Definition: Options.h:49
void cmdDefault(const SmsData &sms)
Definition: SmsCmd.h:302
void MySmsCmd::cmdSms ( const SmsData sms)
protected

Command: Set the sms checking time.

Definition at line 272 of file SmsCmd.h.

References cmdDefault(), SmsData::message, myOptions, readValues(), sendOk(), and MyOptions::smsCheckIntervalSec.

Referenced by checkSms().

273 {
275  sendOk(sms);
276  } else {
277  cmdDefault(sms);
278  }
279 }
MyOptions & myOptions
Reference to the options.
Definition: SmsCmd.h:30
long smsCheckIntervalSec
SMS check intervall.
Definition: Options.h:48
String message
Sms content.
Definition: Sim808.h:40
bool readValues(String &value, const String message)
Definition: SmsCmd.h:153
void sendOk(const SmsData &sms)
Definition: SmsCmd.h:147
void cmdDefault(const SmsData &sms)
Definition: SmsCmd.h:302
void MySmsCmd::cmdStatus ( const SmsData sms)
protected

Command: send status information via sms

Definition at line 212 of file SmsCmd.h.

References MyGps::altitudeString(), MyGps::fixStatus, getGoogleMapGpsUrl(), MyData::humidity, MyOptions::isGpsEnabled, MyGps::kmphString(), MyData::RtcData::lastGps, myData, myOptions, MyData::pressure, MyData::rtcData, MyGps::satellitesString(), sendSms(), MyData::status, MyData::temperature, and MyData::voltage.

Referenced by checkSms().

213 {
214  String status;
215 
216  status += (String) F("Status: ") + myData.status + '\n';
217  status += (String) F("Voltage: ") + String(myData.voltage, 2) + F(" V\n");
218  status += (String) F("Temperature: ") + String(myData.temperature) + F(" C\n");
219  status += (String) F("Humidity: ") + String(myData.humidity) + F(" %\n");
220  status += (String) F("Pressure: ") + String(myData.pressure) + F(" hPa\n");
222  if (myOptions.isGpsEnabled) {
223  status += F("No Gps positions.");
224  } else {
225  status += F("Gps not enabled.");
226  }
227  } else {
228  status += (String) F("Altitude: ") + myData.rtcData.lastGps.altitudeString() + F(" m\n");
229  status += (String) F("Speed: ") + myData.rtcData.lastGps.kmphString() + F(" kmph\n");
230  status += (String) F("Satellites: ") + myData.rtcData.lastGps.satellitesString() + '\n';
231  status += getGoogleMapGpsUrl();
232  }
233  sendSms(status);
234 }
MyOptions & myOptions
Reference to the options.
Definition: SmsCmd.h:30
bool isGpsEnabled
Is the gps part of the sim808 active?
Definition: Options.h:43
String status
Status information.
Definition: Data.h:63
class MyData::RtcData rtcData
Data to store in the RTC memory.
double temperature
Current BME280 temperature.
Definition: Data.h:75
MyGps lastGps
Last known gps location without timeout.
Definition: Data.h:35
String altitudeString()
Definition: Gps.h:552
String satellitesString()
Definition: Gps.h:564
double pressure
Current BME280 pressure.
Definition: Data.h:77
MyData & myData
Reference to the data.
Definition: SmsCmd.h:31
String kmphString()
Definition: Gps.h:558
String getGoogleMapGpsUrl()
Definition: SmsCmd.h:88
double voltage
Current supply voltage.
Definition: Data.h:74
void sendSms(const String &message)
Definition: SmsCmd.h:141
bool fixStatus
Are the gps is valid received?
Definition: Gps.h:133
double humidity
Current BME280 humidity.
Definition: Data.h:76
String MySmsCmd::getGoogleMapGpsUrl ( )
protected

Returns the gps position as an google map url.

Definition at line 88 of file SmsCmd.h.

References MyGps::fixStatus, MyOptions::isGpsEnabled, MyData::RtcData::lastGps, MyGps::latitudeString(), MyGps::longitudeString(), myData, myOptions, and MyData::rtcData.

Referenced by cmdGps(), and cmdStatus().

89 {
91  return (String) F("https://maps.google.com/maps?q=") + myData.rtcData.lastGps.latitudeString() + F(",") + myData.rtcData.lastGps.longitudeString();
92  } else {
93  if (myOptions.isGpsEnabled) {
94  return F("No Gps position.\n");
95  } else {
96  return F("Gps not enabled.\n");
97  }
98  }
99 }
MyOptions & myOptions
Reference to the options.
Definition: SmsCmd.h:30
bool isGpsEnabled
Is the gps part of the sim808 active?
Definition: Options.h:43
class MyData::RtcData rtcData
Data to store in the RTC memory.
MyGps lastGps
Last known gps location without timeout.
Definition: Data.h:35
MyData & myData
Reference to the data.
Definition: SmsCmd.h:31
String longitudeString()
Definition: Gps.h:540
String latitudeString()
Definition: Gps.h:546
bool fixStatus
Are the gps is valid received?
Definition: Gps.h:133
void MySmsCmd::handleClient ( )

Check the sms if the time from the options is elapsed.

Definition at line 80 of file SmsCmd.h.

References checkSms(), MyData::RtcData::lastSmsCheckSec, myData, myOptions, MyData::rtcData, secondsElapsedAndUpdate(), and MyOptions::smsCheckIntervalSec.

Referenced by loop().

81 {
83  checkSms();
84  }
85 }
MyOptions & myOptions
Reference to the options.
Definition: SmsCmd.h:30
long smsCheckIntervalSec
SMS check intervall.
Definition: Options.h:48
class MyData::RtcData rtcData
Data to store in the RTC memory.
MyData & myData
Reference to the data.
Definition: SmsCmd.h:31
bool secondsElapsedAndUpdate(long &lastCheckSec, const long &intervalSec)
Definition: Utils.h:63
long lastSmsCheckSec
Timestamp of the last sms check.
Definition: Data.h:46
void checkSms()
Definition: SmsCmd.h:102
bool MySmsCmd::readValues ( String &  value,
const String  message 
)
protected

Parse a sub string parameter from a sms message (xxx:sub)

Definition at line 153 of file SmsCmd.h.

Referenced by cmdGps(), cmdMqtt(), cmdPhone(), cmdPsm(), and cmdSms().

154 {
155  int idx = message.indexOf(':');
156 
157  if (idx != -1) {
158  value = message.substring(idx + 1);
159  value.toLowerCase();
160  return true;
161  }
162  return false;
163 }
bool MySmsCmd::readValues ( long &  value,
const String  message 
)
protected

Parse a sub long parameter from a sms message (xxx:sub)

Definition at line 166 of file SmsCmd.h.

167 {
168  int idx = message.indexOf(':');
169 
170  if (idx != -1) {
171  value = atoi(message.substring(idx + 1).c_str());
172  return true;
173  }
174  return false;
175 }
bool MySmsCmd::readValues ( long &  value1,
long &  value2,
const String  message 
)
protected

Parse two sub long parameter from a sms message (xxx:sub1:sub2)

Definition at line 178 of file SmsCmd.h.

179 {
180  int first = message.indexOf(':');
181 
182  if (first != -1) {
183  int second = message.indexOf(':', first + 1);
184 
185  if (second != -1) {
186  value1 = atoi(message.substring(first + 1, second).c_str());
187  value2 = atoi(message.substring(second + 1).c_str());
188  return true;
189  }
190  }
191  return false;
192 }
void MySmsCmd::sendOk ( const SmsData sms)
protected

Send an OK sms

Definition at line 147 of file SmsCmd.h.

References SmsData::message, and sendSms().

Referenced by cmdGps(), cmdMqtt(), cmdOff(), cmdOn(), cmdPhone(), cmdPsm(), and cmdSms().

148 {
149  sendSms(sms.message + F(" -> OK"));
150 }
String message
Sms content.
Definition: Sim808.h:40
void sendSms(const String &message)
Definition: SmsCmd.h:141
void MySmsCmd::sendSms ( const String &  message)
protected

Helper function to send one sms

Definition at line 141 of file SmsCmd.h.

References myGsmGps, myOptions, MyOptions::phoneNumber, and MyGsmGps::sendSMS().

Referenced by cmdDefault(), cmdGps(), cmdStatus(), and sendOk().

142 {
144 }
MyOptions & myOptions
Reference to the options.
Definition: SmsCmd.h:30
String phoneNumber
Pone number for sms answers.
Definition: Options.h:47
bool sendSMS(String phoneNumber, String message)
Definition: GsmGps.h:280
MyGsmGps & myGsmGps
Reference to the gsm/gps instance.
Definition: SmsCmd.h:29

The documentation for this class was generated from the following file: