Snorktracker
 All Data Structures Files Functions Variables Macros Pages
Public Member Functions | Data Fields
MyOptions Class Reference

#include <Options.h>

Public Member Functions

bool load ()
 
bool save ()
 

Data Fields

String gprsAP
 GRPS access point of the sim card supplier.
 
String gprsUser
 GRPS access point User.
 
String gprsPassword
 GRPS access point Password.
 
bool connectWifiAP
 Should we connect to wifi.
 
String wifiAP
 WiFi AP name.
 
String wifiPassword
 WiFi AP password.
 
bool isDebugActive
 Is detailed debugging enabled?
 
long bme280CheckIntervalSec
 Time interval to read the temp, hum and pressure.
 
bool powerOn
 Is the GSM power from the DC-DC modul switched on?
 
bool isSmsEnabled
 Is the sms check functionality active?
 
bool isGpsEnabled
 Is the gps part of the sim808 active?
 
long gpsTimeoutSec
 Timeout for waiting for gps position.
 
long gpsCheckIntervalSec
 Time interval to check the gps position.
 
long minMovingDistance
 Minimum distance to accept as moving or not.
 
String phoneNumber
 Pone number for sms answers.
 
long smsCheckIntervalSec
 SMS check intervall.
 
bool isDeepSleepEnabled
 Should the system go into deepsleep if needed.
 
double powerSaveModeVoltage
 Minimum voltage to stay always alive.
 
long powerCheckIntervalSec
 Time interval to check the power supply.
 
long activeTimeSec
 Maximum alive time after deepsleep.
 
long deepSleepTimeSec
 Time to stay in deep sleep (without check interrupts)
 
bool isMqttEnabled
 Should the system connect to a MQTT server?
 
String mqttName
 MQTT server name.
 
String mqttId
 MQTT ID.
 
String mqttServer
 MQTT server url.
 
long mqttPort
 MQTT server port.
 
String mqttUser
 MQTT user.
 
String mqttPassword
 MQTT password.
 
long mqttSendOnMoveEverySec
 Send data interval to MQTT server on moving.
 
long mqttSendOnNonMoveEverySec
 Send data interval to MQTT server on non moving.
 

Detailed Description

Class with the complete configuration data of the programm. It can load and save the data in a ini file format to the SPIFFS as key value pairs 'key=value' line by line.

Definition at line 30 of file Options.h.

Member Function Documentation

bool MyOptions::load ( )

Load the key-value pairs from the option file into the option values.

Definition at line 108 of file Options.h.

References activeTimeSec, bme280CheckIntervalSec, connectWifiAP, deepSleepTimeSec, gprsAP, gprsPassword, gprsUser, gpsCheckIntervalSec, gpsTimeoutSec, isDebugActive, isDeepSleepEnabled, isGpsEnabled, isMqttEnabled, isSmsEnabled, minMovingDistance, mqttId, mqttName, mqttPassword, mqttPort, mqttSendOnMoveEverySec, mqttSendOnNonMoveEverySec, mqttServer, mqttUser, MyDbg(), OPTION_FILE_NAME, phoneNumber, powerCheckIntervalSec, powerOn, powerSaveModeVoltage, smsCheckIntervalSec, wifiAP, and wifiPassword.

Referenced by setup().

109 {
110  bool ret = false;
111  File file = SPIFFS.open(OPTION_FILE_NAME, "r");
112 
113  if (!file) {
114  MyDbg(F("Failed to read options file"));
115  } else {
116  ret = true;
117  while (file.available() && ret) {
118  String line = file.readStringUntil('\n');
119  int idx = line.indexOf('=');
120 
121  if (idx == -1) {
122  MyDbg((String) F("Wrong option entry: ") + line);
123  ret = false;
124  } else {
125  String key = line.substring(0, idx);
126  String value = line.substring(idx + 1);
127  long lValue = atol(value.c_str());
128  double fValue = atof(value.c_str());
129 
130  value.replace("\r", "");
131  value.replace("\n", "");
132  MyDbg((String) F("Load option '") + key + F("=") + value + F("'"));
133 
134  if (key == F("isDebugActive")) {
135  isDebugActive = lValue;
136  } else if (key == F("gprsAP")) {
137  gprsAP = value;
138  } else if (key == F("gprsUser")) {
139  gprsUser = value;
140  } else if (key == F("gprsPassword")) {
141  gprsPassword = value;
142  } else if (key == F("wifiAP")) {
143  wifiAP = value;
144  } else if (key == F("connectWifiAP")) {
145  connectWifiAP = lValue;
146  } else if (key == F("wifiPassword")) {
147  wifiPassword = value;
148  } else if (key == F("powerOn")) {
149  powerOn = lValue;
150  } else if (key == F("bme280CheckIntervalSec")) {
151  bme280CheckIntervalSec = lValue;
152  } else if (key == F("isSmsEnabled")) {
153  isSmsEnabled = lValue;
154  } else if (key == F("isGpsEnabled")) {
155  isGpsEnabled = lValue;
156  } else if (key == F("gpsTimeoutSec")) {
157  gpsTimeoutSec = lValue;
158  } else if (key == F("gpsCheckIntervalSec")) {
159  gpsCheckIntervalSec = lValue;
160  } else if (key == F("minMovingDistance")) {
161  minMovingDistance = lValue;
162  } else if (key == F("phoneNumber")) {
163  phoneNumber = value;
164  } else if (key == F("smsCheckIntervalSec")) {
165  smsCheckIntervalSec = lValue;
166  } else if (key == F("isDeepSleepEnabled")) {
167  isDeepSleepEnabled = lValue;
168  } else if (key == F("powerSaveModeVoltage")) {
169  powerSaveModeVoltage = fValue;
170  } else if (key == F("powerCheckIntervalSec")) {
171  powerCheckIntervalSec = lValue;
172  } else if (key == F("activeTimeSec")) {
173  activeTimeSec = lValue;
174  } else if (key == F("deepSleepTimeSec")) {
175  deepSleepTimeSec = lValue;
176  } else if (key == F("isMqttEnabled")) {
177  isMqttEnabled = lValue;
178  } else if (key == F("mqttName")) {
179  mqttName = value;
180  } else if (key == F("mqttId")) {
181  mqttId = value;
182  } else if (key == F("mqttServer")) {
183  mqttServer = value;
184  } else if (key == F("mqttPort")) {
185  mqttPort = lValue;
186  } else if (key == F("mqttUser")) {
187  mqttUser = value;
188  } else if (key == F("mqttPassword")) {
189  mqttPassword = value;
190  } else if (key == F("mqttSendOnMoveEverySec")) {
191  mqttSendOnMoveEverySec = lValue;
192  } else if (key == F("mqttSendOnNonMoveEverySec")) {
193  mqttSendOnNonMoveEverySec = lValue;
194  } else {
195  MyDbg((String) F("Wrong option entry: ") + line);
196  ret = false;
197  }
198  }
199  }
200  file.close();
201  }
202  if (ret) {
203  MyDbg(F("Settings loaded"));
204  }
205  return ret;
206 }
long deepSleepTimeSec
Time to stay in deep sleep (without check interrupts)
Definition: Options.h:53
String phoneNumber
Pone number for sms answers.
Definition: Options.h:47
bool isGpsEnabled
Is the gps part of the sim808 active?
Definition: Options.h:43
double powerSaveModeVoltage
Minimum voltage to stay always alive.
Definition: Options.h:50
long smsCheckIntervalSec
SMS check intervall.
Definition: Options.h:48
bool connectWifiAP
Should we connect to wifi.
Definition: Options.h:36
String mqttUser
MQTT user.
Definition: Options.h:59
String wifiAP
WiFi AP name.
Definition: Options.h:37
long gpsCheckIntervalSec
Time interval to check the gps position.
Definition: Options.h:45
void MyDbg(String info, bool fromWebServer=false, bool newline=true)
Definition: Utils.h:94
bool powerOn
Is the GSM power from the DC-DC modul switched on?
Definition: Options.h:41
String mqttId
MQTT ID.
Definition: Options.h:56
long gpsTimeoutSec
Timeout for waiting for gps position.
Definition: Options.h:44
String mqttPassword
MQTT password.
Definition: Options.h:60
long powerCheckIntervalSec
Time interval to check the power supply.
Definition: Options.h:51
String wifiPassword
WiFi AP password.
Definition: Options.h:38
String gprsUser
GRPS access point User.
Definition: Options.h:34
String mqttServer
MQTT server url.
Definition: Options.h:57
bool isDebugActive
Is detailed debugging enabled?
Definition: Options.h:39
long mqttPort
MQTT server port.
Definition: Options.h:58
long activeTimeSec
Maximum alive time after deepsleep.
Definition: Options.h:52
long bme280CheckIntervalSec
Time interval to read the temp, hum and pressure.
Definition: Options.h:40
String gprsPassword
GRPS access point Password.
Definition: Options.h:35
bool isSmsEnabled
Is the sms check functionality active?
Definition: Options.h:42
String gprsAP
GRPS access point of the sim card supplier.
Definition: Options.h:33
String mqttName
MQTT server name.
Definition: Options.h:55
bool isMqttEnabled
Should the system connect to a MQTT server?
Definition: Options.h:54
#define OPTION_FILE_NAME
Option file name.
Definition: Options.h:23
long mqttSendOnNonMoveEverySec
Send data interval to MQTT server on non moving.
Definition: Options.h:62
bool isDeepSleepEnabled
Should the system go into deepsleep if needed.
Definition: Options.h:49
long mqttSendOnMoveEverySec
Send data interval to MQTT server on moving.
Definition: Options.h:61
long minMovingDistance
Minimum distance to accept as moving or not.
Definition: Options.h:46
bool MyOptions::save ( )

Save all the options as key-value pair to the option file.

Definition at line 209 of file Options.h.

References activeTimeSec, bme280CheckIntervalSec, connectWifiAP, deepSleepTimeSec, gprsAP, gprsPassword, gprsUser, gpsCheckIntervalSec, gpsTimeoutSec, isDebugActive, isDeepSleepEnabled, isGpsEnabled, isMqttEnabled, isSmsEnabled, minMovingDistance, mqttId, mqttName, mqttPassword, mqttPort, mqttSendOnMoveEverySec, mqttSendOnNonMoveEverySec, mqttServer, mqttUser, MyDbg(), OPTION_FILE_NAME, phoneNumber, powerCheckIntervalSec, powerOn, powerSaveModeVoltage, smsCheckIntervalSec, wifiAP, and wifiPassword.

Referenced by MySmsCmd::cmdOff(), MySmsCmd::cmdOn(), MySmsCmd::cmdPsm(), MyWebServer::handleLoadMainInfo(), and MyWebServer::handleSaveSettings().

210 {
211  File file = SPIFFS.open(OPTION_FILE_NAME, "w+");
212 
213  if (!file) {
214  MyDbg("Failed to write options file");
215  } else {
216  file.println((String) F("isDebugActive=") + String(isDebugActive));
217  file.println((String) F("gprsAP=") + gprsAP);
218  file.println((String) F("gprsUser=") + gprsUser);
219  file.println((String) F("gprsPassword=") + gprsPassword);
220  file.println((String) F("connectWifiAP=") + String(connectWifiAP));
221  file.println((String) F("wifiAP=") + wifiAP);
222  file.println((String) F("wifiPassword=") + wifiPassword);
223  file.println((String) F("powerOn=") + String(powerOn));
224  file.println((String) F("bme280CheckIntervalSec=") + String(bme280CheckIntervalSec));
225  file.println((String) F("isSmsEnabled=") + String(isSmsEnabled));
226  file.println((String) F("isGpsEnabled=") + String(isGpsEnabled));
227  file.println((String) F("gpsTimeoutSec=") + String(gpsTimeoutSec));
228  file.println((String) F("gpsCheckIntervalSec=") + String(gpsCheckIntervalSec));
229  file.println((String) F("minMovingDistance=") + String(minMovingDistance));
230  file.println((String) F("phoneNumber=") + phoneNumber);
231  file.println((String) F("smsCheckIntervalSec=") + String(smsCheckIntervalSec));
232  file.println((String) F("isDeepSleepEnabled=") + String(isDeepSleepEnabled));
233  file.println((String) F("powerSaveModeVoltage=") + String(powerSaveModeVoltage, 2));
234  file.println((String) F("powerCheckIntervalSec=") + String(powerCheckIntervalSec));
235  file.println((String) F("activeTimeSec=") + String(activeTimeSec));
236  file.println((String) F("deepSleepTimeSec=") + String(deepSleepTimeSec));
237  file.println((String) F("isMqttEnabled=") + String(isMqttEnabled));
238  file.println((String) F("mqttName=") + mqttName);
239  file.println((String) F("mqttId=") + mqttId);
240  file.println((String) F("mqttServer=") + mqttServer);
241  file.println((String) F("mqttPort=") + String(mqttPort));
242  file.println((String) F("mqttUser=") + mqttUser);
243  file.println((String) F("mqttPassword=") + mqttPassword);
244  file.println((String) F("mqttSendOnMoveEverySec=") + String(mqttSendOnMoveEverySec));
245  file.println((String) F("mqttSendOnNonMoveEverySec=") + String(mqttSendOnNonMoveEverySec));
246  file.close();
247  MyDbg(F("Settings saved"));
248  return true;
249  }
250  return false;
251 }
long deepSleepTimeSec
Time to stay in deep sleep (without check interrupts)
Definition: Options.h:53
String phoneNumber
Pone number for sms answers.
Definition: Options.h:47
bool isGpsEnabled
Is the gps part of the sim808 active?
Definition: Options.h:43
double powerSaveModeVoltage
Minimum voltage to stay always alive.
Definition: Options.h:50
long smsCheckIntervalSec
SMS check intervall.
Definition: Options.h:48
bool connectWifiAP
Should we connect to wifi.
Definition: Options.h:36
String mqttUser
MQTT user.
Definition: Options.h:59
String wifiAP
WiFi AP name.
Definition: Options.h:37
long gpsCheckIntervalSec
Time interval to check the gps position.
Definition: Options.h:45
void MyDbg(String info, bool fromWebServer=false, bool newline=true)
Definition: Utils.h:94
bool powerOn
Is the GSM power from the DC-DC modul switched on?
Definition: Options.h:41
String mqttId
MQTT ID.
Definition: Options.h:56
long gpsTimeoutSec
Timeout for waiting for gps position.
Definition: Options.h:44
String mqttPassword
MQTT password.
Definition: Options.h:60
long powerCheckIntervalSec
Time interval to check the power supply.
Definition: Options.h:51
String wifiPassword
WiFi AP password.
Definition: Options.h:38
String gprsUser
GRPS access point User.
Definition: Options.h:34
String mqttServer
MQTT server url.
Definition: Options.h:57
bool isDebugActive
Is detailed debugging enabled?
Definition: Options.h:39
long mqttPort
MQTT server port.
Definition: Options.h:58
long activeTimeSec
Maximum alive time after deepsleep.
Definition: Options.h:52
long bme280CheckIntervalSec
Time interval to read the temp, hum and pressure.
Definition: Options.h:40
String gprsPassword
GRPS access point Password.
Definition: Options.h:35
bool isSmsEnabled
Is the sms check functionality active?
Definition: Options.h:42
String gprsAP
GRPS access point of the sim card supplier.
Definition: Options.h:33
String mqttName
MQTT server name.
Definition: Options.h:55
bool isMqttEnabled
Should the system connect to a MQTT server?
Definition: Options.h:54
#define OPTION_FILE_NAME
Option file name.
Definition: Options.h:23
long mqttSendOnNonMoveEverySec
Send data interval to MQTT server on non moving.
Definition: Options.h:62
bool isDeepSleepEnabled
Should the system go into deepsleep if needed.
Definition: Options.h:49
long mqttSendOnMoveEverySec
Send data interval to MQTT server on moving.
Definition: Options.h:61
long minMovingDistance
Minimum distance to accept as moving or not.
Definition: Options.h:46

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