37 String m =
":" + String(millis()) +
"[" +
message;
38 Serial.println(m.c_str());
43 String m =
message +
":" + String(millis()) +
"]";
44 Serial.println(m.c_str());
56 if (lastCheckSec == 0 || (currentSec - lastCheckSec > intervalSec)) {
67 if (lastCheckSec == 0 || (currentSec - lastCheckSec > intervalSec)) {
68 lastCheckSec = currentSec;
74 #define POLY 0xedb88320
77 long crc32(
long crc,
unsigned char *buf,
size_t len)
82 for (
int k = 0; k < 8; k++)
83 crc = crc & 1 ? (crc >> 1) ^
POLY : crc >> 1;
89 void myDebugInfo(String info,
bool isWebServer,
bool newline);
94 void MyDbg(String info,
bool fromWebServer =
false,
bool newline =
true)
108 while (millis() - m < millisDelay) {
125 }
else if (rssi >= -50) {
128 quality = 2 * (rssi + 100);
130 return String(quality);
139 data.replace(F(
"%"), F(
"%25"));
140 data.replace(F(
"&"), F(
"%26"));
141 data.replace(F(
"<"), F(
"%3C"));
142 data.replace(F(
">"), F(
"%3E"));
144 for (
int i = 0; i < data.length(); i++) {
145 bool validChar = (data[i] == 0x09 || data[i] == 0x0A || data[i] == 0x0D || (data[i] >= 0x20 && data[i] <= 0xFF));
158 data.replace(F(
"&"), F(
"&"));
159 data.replace(F(
"<"), F(
"<"));
160 data.replace(F(
">"), F(
">"));
161 data.replace(F(
"\""), F(
"""));
168 String
Trim(
const String &data,
const String &chars)
172 for (
int i = 0; i < ret.length(); i++) {
173 if (chars.indexOf(ret[i]) != -1) {
180 for (
int i = data.length() - 1; i >= 0; i--) {
181 if (chars.indexOf(ret[i]) != -1) {
195 int days = secs / 60 / 60 / 24;
196 int hours = (secs / 60 / 60) % 24;
197 int minutes = (secs / 60) % 60;
198 int seconds = secs % 60;
202 sprintf(buff,
"%02d:%02d:%02d", hours, minutes, seconds);
204 sprintf(buff,
"%d %02d:%02d:%02d", days, hours, minutes, seconds);
214 interval =
Trim(interval, F(
" "));
215 first = interval.indexOf(F(
":"));
219 String minutesString;
220 String secondsString;
226 int second = interval.indexOf(F(
":"), first + 1);
229 int space = interval.indexOf(F(
" "));
231 if (space != -1 && space < first) {
232 daysString = interval.substring(0, space);
233 hoursString = interval.substring(space + 1, first);
235 hoursString = interval.substring(0, first);
237 minutesString = interval.substring(first + 1, second);
238 secondsString = interval.substring(second + 1);
240 days = atol(daysString.c_str());
241 hours = atol(hoursString.c_str());
242 minutes = atol(minutesString.c_str());
243 seconds = atol(secondsString.c_str());
246 hours >= 0 && hours <= 23 &&
247 minutes >= 0 && minutes <= 59 &&
248 seconds >= 0 && seconds <= 59) {
250 secs += days * 24 * 60 * 60;
251 secs += hours * 60 * 60;
252 secs += minutes * 60;
266 MyDbg(F(
"StartOTA"));
268 ArduinoOTA.setHostname(
"SnorkTracker");
270 ArduinoOTA.setPort(8266);
272 ArduinoOTA.onStart([]() {
273 MyDbg(F(
"OTA Start"));
275 ArduinoOTA.onEnd([]() {
276 MyDbg(F(
"\nOTA End"));
278 ArduinoOTA.onProgress([](
unsigned int progress,
unsigned int total) {
279 MyDbg(
"OTA Progress: " + String(progress / (total / 100)));
281 ArduinoOTA.onError([](ota_error_t error) {
282 MyDbg(
"OTA Error[%u]: " + error);
283 if (error == OTA_AUTH_ERROR)
MyDbg(F(
"OTA Auth Failed"));
284 else if (error == OTA_BEGIN_ERROR)
MyDbg(F(
"OTA Begin Failed"));
285 else if (error == OTA_CONNECT_ERROR)
MyDbg(F(
"OTA Connect Failed"));
286 else if (error == OTA_RECEIVE_ERROR)
MyDbg(F(
"OTA Receive Failed"));
287 else if (error == OTA_END_ERROR)
MyDbg(F(
"OTA End Failed"));
String formatInterval(long secs)
bool scanInterval(String interval, long &secs)
String TextToXml(String data)
void myDebugInfo(String info, bool isWebServer, bool newline)
long crc32(long crc, unsigned char *buf, size_t len)
String TextToUrl(String data)
void MyDbg(String info, bool fromWebServer=false, bool newline=true)
String WifiGetRssiAsQuality(int rssi)
void MyDelay(long millisDelay)
long secondsSincePowerOn()
#define POLY
CRC-32 (Ethernet, ZIP, etc.) polynomial in reversed bit order.
String message
Mesage on contructor and destructor.
bool secondsElapsed(long &lastCheckSec, const long &intervalSec)
bool secondsElapsedAndUpdate(long &lastCheckSec, const long &intervalSec)
String Trim(const String &data, const String &chars)