ESP_IOT v2.5
IOT ESP Coding
REFAcTOR.c
Go to the documentation of this file.
1#define REFACTOR_MSG
2#ifdef REFACTOR_MSG
3 //!TODO: duplicate and depreciate these and replace with set:buzz,val:on
4 else if (strcasecmp(setCmdString,"buzz")==0)
5 {
6 if (flag)
7 {
8 SerialDebug.println("BUZZON via BLE");
10 }
11 else if (strcasecmp(cmd,"buzzoff")==0)
12 {
13 SerialDebug.println("BUZZOFF via BLE");
15 }
16 }
17
18
19 //BLECLient
20 else if (strcasecmp(setCmdString,"bleclient")==0)
21 {
22 if (flag)
23 {
24 if (deviceNameSpecified)
25 {
26 SerialDebug.println("PREFERENCE_MAIN_BLE_CLIENT_VALUE ON via BLE");
28 //!for now just reboot which will use this perference
30 }
31 }
32 else
33 {
34 if (deviceNameSpecified)
35 {
36 SerialDebug.println("PREFERENCE_MAIN_BLE_CLIENT_VALUE OFF via BLE");
38 //!for now just reboot which will use this perference
40 }
41 }
42 }
43 // bleserver
44 else if (strcasecmp(setCmdString,"bleserver")==0)
45 {
46 if (flag)
47 {
48 if (deviceNameSpecified)
49 {
50 SerialDebug.println("PREFERENCE_MAIN_BLE_SERVER_VALUE ON via BLE");
52 //!for now just reboot which will use this perference
54 }
55 }
56 else
57 {
58 if (deviceNameSpecified)
59 {
60 SerialDebug.println("PREFERENCE_MAIN_BLE_SERVER_VALUE OFF via BLE");
62 //!for now just reboot which will use this perference
64 }
65 }
66 }
67
68 else if (strcasecmp(setCmdString,"tilt")==0)
69 {
70 if (flag)
71 {
72 SerialDebug.println("PREFERENCE_SENSOR_TILT_VALUE ON via BLE");
74 }
75 else
76 {
77 SerialDebug.println("PREFERENCE_SENSOR_TILT_VALUE OFF via BLE");
79 }
80 }
81
82.....
83 else if (strcasecmp(setCmdString,"zoomSm")==0)
84 {
85 //!zoom == the NON semantic marker version.. so min menu is true
86 if (flag)
87 {
88
89 //hide semantic marker.. (but only if in the max menus)
90 //NOTE: this only hides the Semantic Marker - if on a page that has one..
91 SerialDebug.println("PREFERENCE_SEMANTIC_MARKER_ZOOMED_VALUE ON via BLE");
93
94 //!zoom only if in the max menu set..
96 {
97 //stay on this page, but change the marker..
99 }
100
101 }
102 else
103 {
104 //show semantic marker..
105 //NOTE: this only shows the Semantic Marker - if on a page that has one..
106 SerialDebug.println("PREFERENCE_SEMANTIC_MARKER_ZOOMED_VALUE OFF via BLE");
109
110 //!zoom only if in the max menu set..
112 {
113 //change to the status..
115 //!send message to ourself to process the current mode..
117 }
118 else
119 {
120 //stay on this page, but change the zoom..
122 }
123 }
124 } // zoomSM
125 #endif // REFACTOR
126
127 }
128 //! {'guest':'guest password'}
129 else if (guestCmd) //depreciated..
130 {
131 _mqttGuestPasswordString = const_cast<char*>(guestCmd);
132 SerialDebug.printf("guestCmd = '%s'\n", _mqttGuestPasswordString);
133 }
134 // {'sm':'name/cat/uuid'}
135 else if (semanticMarkerCmd)
136 {
137 //char semanticMarkerString[200];
138 char* baseString = (char*)"https://SemanticMarker.org/bot/";
139 sprintf(_semanticMarkerString,"%s/%s", baseString, semanticMarkerCmd);
140
141 //! use the name/cat/uuid ..
143
144 }
145 //!5.12.22
146 else if (setCmd && valCmd)
147 {
148 //! options: hightemp, feedcount, timeout
149 char* setCmdString = const_cast<char*>(setCmd);
150 char* valCmdString = const_cast<char*>(valCmd);
151 SerialTemp.print("Set: ");
152 SerialTemp.print(setCmdString);
153 SerialTemp.print(", Val: ");
154 SerialTemp.println(valCmdString);
155
156 // if boolean
157 boolean flag = false;
158 if (isTrueString(valCmdString))
159 flag = true;
160
161 //!try 5.12.22 {'set':'item'},{'val':'value'}
162 //! eg. set:hightemp, val:80)
163 //! TODO: confirm valid integer values...
164 if (strcasecmp(setCmdString,"hightemp")==0)
165 {
166 //!set the high temp value..
168 }
169 else if (strcasecmp(setCmdString,"screentimeout")==0)
170 {
171 //set the screen timeout
173 }
174 else if (strcasecmp(setCmdString,"stepperangle")==0)
175 {
176 //!set the stepperangle.
178 }
179 else if (strcasecmp(setCmdString,"noclick")==0)
180 {
181 //!set the timeout from no click to poweroff
183 }
184 else if (strcasecmp(setCmdString,"gateway")==0)
185 {
186 boolean flag = false;
187 if (isTrueString(valCmdString))
188 flag = true;
189
190 //! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
192 }
193 //!add stepper type
194 else if (strcasecmp(setCmdString,"stepper")==0)
195 {
196 int feederType = STEPPER_IS_UNO;
197 if (strcasecmp(valCmdString,"mini")==0)
198 feederType = STEPPER_IS_MINI;
199 else if (strcasecmp(valCmdString,"tumbler")==0)
200 feederType = STEPPER_IS_TUMBLER;
201 //! called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean)
203 }
204 //!add stepper type
205 else if (strcasecmp(setCmdString,"otafile")==0)
206 {
207 //perform the OTA via a file specified .. be careful..
209 }
210 //!set the location
211 else if (strcasecmp(setCmdString,"location")==0)
212 {
213 //perform the OTA via a file specified .. be careful..
214 _jsonLocationString = createCopy(valCmdString);
216 }
217 //! rename device
218 else if (strcasecmp(setCmdString,"device")==0)
219 {
220 //define the device
221 _deviceNameString = createCopy(valCmdString);
223
224 //!since renaming, lets set a STATUS out..
225 //! request a STATUS be sent.
226 processBarkletMessage("#STATUS", topic);
227 }
228 //! paireddev the paired device
229 else if (strcasecmp(setCmdString,"pairdev")==0)
230 {
231 //!saves the pair device name TODO: the feed device should use the pair as well.. (DONE..)
233 }
234
235 else if (strcasecmp(setCmdString,"screencolor")==0)
236 {
237 //!set the screen color 0..n
238 int screenColor = atoi(valCmdString);
239 setScreenColor_displayModule(screenColor);
240
241 //stay on this page, but change the marker..
243 }
244 //! sets the gen3only flag
245 else if (strcasecmp(setCmdString,"gen3only")==0)
246 {
247 boolean flag = isTrueString(valCmdString);
248
249 //! sets the gen3only flag
251 //!for now just reboot which will use this perference
253 }
254 //! sets the gen3only flag
255 else if (strcasecmp(setCmdString,"bleusepaireddevicename")==0)
256 {
257 boolean flag = isTrueString(valCmdString);
258
259 //! sets the bleusepaireddevicename flag
261
262 }
263 //! sets the gen3only flag
264 else if (strcasecmp(setCmdString,"bleusedevicename")==0)
265 {
266 boolean flag = isTrueString(valCmdString);
267
268 //! sets the bleusedevicename flag
270
271 //!for now just reboot which will use this perference and re-create the service name..
273 else if (strcasecmp(setCmdString,"minMenu")==0)
274 {
275 SerialDebug.println("PREFERENCE_IS_MINIMAL_MENU_SETTING via BLE");
276 boolean flag = isTrueString(valCmdString);
277 if (flag)
278 {
281 }
282 else
283 {
284 int max = minMenuModesMax_mainModule();
285 //set to start of after min..
287 }
288 //!send message to ourself to process the current mode..
290 }
291 else if (strcasecmp(setCmdString,"addwifi")==0)
292 {
293 //has to support "Cisco:"
294 //parse the valCmdString: ssid:password
295 char str[100];
296 strcpy(str,valCmdString);
297 char *token;
298 char *rest = str;
299 char* ssid = strtok_r(rest,":", &rest);
300 char* password = strtok_r(rest,":", &rest);
301 SerialDebug.printf("addwifi %s, %s\n", ssid?ssid:"null", password?password:"");
302 //now save as a credential
303 // main_addWIFICredentials(addSSID, addPassword);
304 //!send message to ourself to process the current mode..
305 // invokeCurrentSMModePage(topic);
306
307 //NOTE: there can be empty passwords..
308 char credentials[100];
309 //!store the JSON version of these credentials..
310 sprintf(credentials, "{'ssid':'%s','ssidPassword':'%s'}", ssid?ssid:"NULL", password?password:"");
311 // This works by just sending the credentials to ourself .. and process correctly.
312 SerialMin.println(credentials);
314
315 //The problem with invoking the current SMModePage is if we are on the swap WIFI page, then it will swap .. which might not be desired..
316 }
317 else if (strcasecmp(setCmdString,"docfollow")==0)
318 {
319 SerialDebug.printf("PREFERENCE_USE_DOC_FOLLOW_SETTING %s\n", valCmdString);
320 boolean flag = isTrueString(valCmdString);
322
323 }
324 }
325 //!5.24.22 send:<request> .. Note these are for cmd without an argument..
326 else if (sendCmd)
327 {
328 //!NOTE: This will be calling ourself
329
330 char* sendCmdString = const_cast<char*>(sendCmd);
331 if (strcasecmp(sendCmdString,"temp")==0)
332 {
333 SerialTemp.println("sendCmd == temp");
334 //! request a TEMP be sent.
335 processBarkletMessage("#TEMP", topic);
336 }
337 else if (strcasecmp(sendCmdString,"status")==0)
338 {
339 SerialTemp.println("sendCmd == status");
340 //! request a STATUS be sent.
341 processBarkletMessage("#STATUS", topic);
342 }
343 else if (strcasecmp(sendCmdString,"capture")==0)
344 {
345 SerialTemp.println("sendCmd == capture");
346 //! request a CAPTURE be sent.
347 processBarkletMessage("#CAPTURE", topic);
348 }
349 else if (strcasecmp(sendCmdString,"volume")==0)
350 {
351 SerialTemp.println("sendCmd == volume (not implemented)");
352 //! request a VOLUME be sent.
353 processBarkletMessage("#VOLUME", topic);
354 }
355 else
356 {
357 SerialTemp.print("Unknown send request: ");
358 SerialTemp.println(sendCmdString);
359 }
360
361 }
362
363 //!this return is important!!!
364 return true;
365 } //!end process commands..
366
367 //end NEW
368 //!TRY without 1.30.22 (RAMS win) and it works..
369 //!if can talk BLE, then reboot.. 2.2.22
370
371 //NOTE: here is where different reasons for the info could be provided in the data>
372 // eg. dataKind (wifi, mqtt, etc...)boot
373 /**
374 {
375 "ssid" : "SunnyWhiteriver",
376 "ssidPassword" : "sunny2021",
377 "mqtt_topic": "usersP/bark/test",
378 "mqtt_user" : "test",
379 "deviceName" : "HowieFeeder",
380 "mqtt_password" : "password..",
381 "mqtt_guestPassword" : "password",
382 "uuid" : "scott",
383 "mqtt_port" : "1883",
384 "mqtt_server" : "idogwatch.com",
385 "mqtt_status" : "Success",
386 "location": "whatever to reply with, GPS, state, city, etc.."
387 }
388
389 //todo pass the guest password too
390 */
391 //TODO: parse the string...
392 //!! Store wifi config. ␖å␖˜␖å␖¨wifi␖é␖␖ç␖®␖ä␖¡␖æ␖¯
393 //! @see https://arduinojson.org
394
395 {
396 const char* a1 = myObject["ssid"];
397 if (a1 && strlen(a1)>0)
398 {
399 _ssidString = const_cast<char*>(a1);
401 }
402 else
404
405 SerialTemp.println(a1);
406 SerialTemp.println(_ssidString);
407 }
408
409 {
410 const char* a2 = myObject["ssidPassword"];
411 if (a2 && strlen(a2)>0)
412 {
413 _ssidPasswordString = const_cast<char*>(a2);
415 }
416 else
418 }
419
420 {
421 //!5.25.22 (50 years since Grateful Dead London Show
422
423 //! To support just setting the ssid and password, a JSON
424 //! of {ssid:s,ssidPassword:p} is supported, so don't null out if mqtt aren't provided..
425 //! this should work (since the SSID is what's checked to go to the AP mode)
426
427 //!the MQTT host/port/user/password (topic is created in this code...)
428 const char* a3 = myObject["mqtt_server"];
429 if (a3)
430 {
431 _mqttServerString = const_cast<char*>(a3);
433 }
434 // else
435 // _mqttServerString = NULL;
436 }
437 {
438 const char* a4 = myObject["mqtt_port"];
439 if (a4)
440 {
441 _mqttPortString = const_cast<char*>(a4);
443 }
444 // else
445 // _mqttPortString = NULL;
446 //
447 }
448 {
449 const char* a5 = myObject["mqtt_password"];
450 if (a5)
451 {
452 _mqttPasswordString = const_cast<char*>(a5);
454 }
455 // else
456 // _mqttPasswordString = NULL;
457 }
458
459 {
460 const char* a6 = myObject["mqtt_user"];
461 if (a6)
462 {
463 _mqttUserString = const_cast<char*>(a6);
465 }
466 // else
467 // _mqttUserString = NULL;
468 }
469 {
470 const char* a7 = myObject["deviceName"];
471 if (a7 && strlen(a7)>0)
472 {
473 _deviceNameString = const_cast<char*>(a7);
475 }
476 // else
477 // _deviceNameString = NULL;
478 }
479 {
480 const char* a8 = myObject["uuid"];
481 if (a8)
482 {
483 _uuidString = const_cast<char*>(a8);
485 }
486 // else
487 // _uuidString = NULL;
488 }
489 {
490 const char* a9 = myObject["mqtt_topic"];
491 if (a9)
492 {
493 _mqttTopicString = const_cast<char*>(a9);
495 }
496 // else
497 // _mqttTopicString = NULL;
498
499 }
500 {
501 const char* a10 = myObject["mqtt_guestPassword"];
502 if (a10)
503 {
504 _mqttGuestPasswordString = const_cast<char*>(a10);
506 }
507 // else
508 // _mqttGuestPasswordString = NULL;
509 }
510
511 {
512 const char* a11 = myObject["location"];
513 if (a11 && strlen(a11)>0)
514 {
515 _jsonLocationString = const_cast<char*>(a11);
517 }
518 // else
519 // _mqttGuestPasswordString = NULL;
520 }
521
522 //!reset the MQTT attempts
524
525 boolean saveJSONPreferences = true;
526 //!setup the WIFI if the ssid string (at least) is specified
528 {
529 SerialDebug.println("Setting WIFI from JSON parameters");
530 //setupWIFI(_ssidString, _ssidPasswordString);
531
532 //!new: go out and let the process work...
533 //!set the state, then the 'loop' will call setupWIF(...)
536
537 }
538 else
539 {
540 SerialDebug.println(" ***** ERROR .. no ssidString *** ");
541 //!call the callback specified from the caller (eg. NimBLE_PetTutor_Server .. or others)
543
544 saveJSONPreferences = false;
545 }
546
547
548 //!don't save the preferences, since it didn't have enough information..
550 {
551 SerialDebug.println("**** Not saving JSON in preferences ***");
552 return true;
553 }
554
555 //!NOTE: this writes over entire values, since it's a string vs an JSON object
557
558 //!new 4.8.22 .. trying to kick out of AP mode if the credentials are good..
560
561 //!putting here .. time might have gone too fast..
564
565
566 return true;
567}
568
569//!restart the WIFI and then MQTT connection
571{
572 //let it know MQTT isn't running either
573 _MQTTRunning = false;
574
575 SerialTemp.println("restartWIFI_MQTTState");
576 //putting here .. time might have gone too fast..
579
580}
581
582//!just update the EPROM, and send that to the WIFI_AP module as well
584{
585 DynamicJsonDocument myObject(1024);
586
587 //!basically if only the ssid/pass are sent, that is all that's written to EPROM
588 //!even if the other information is available.. So recreate the JSON instead..
589 //!seems c++ you cannot re-use output as it just appends to it.. unreal
590 String output2;
591 myObject["ssid"] = _ssidString;
592 myObject["ssidPassword"] = _ssidPasswordString;
593 myObject["mqtt_server"] = _mqttServerString;
594 myObject["mqtt_port"] = _mqttPortString;
595 myObject["mqtt_password"] = _mqttPasswordString;
596 myObject["mqtt_guestPassword"] = _mqttGuestPasswordString;
597
598 myObject["mqtt_user"] = _mqttUserString;
599 myObject["mqtt_topic"] = _mqttTopicString;
600 myObject["deviceName"] = _deviceNameString;
601 myObject["uuid"] = _uuidString;
602 myObject["jsonHeader"] = _jsonHeaderString;
603 myObject["jsonVersion"] = _jsonVersionString;
604 myObject["location"] = _jsonLocationString;
605
606
607 //!JSON
608 serializeJson(myObject, output2);
609
610 //!open the preferences
612 SerialDebug.print("MQTTNetworking.Writing EPROM JSON = '");
613 SerialDebug.print(output2);
614 SerialDebug.println("'");
615
616 //!save in EPROM
618 //! Close the Preferences
620
621 //! sets the MQTT user/password. It's up to the code to decide who needs to know (currently saves in the WIFI_APModule
623
624 //!NEW: 2.21.22
625 //!TRY: reading back..
626 _preferencesMQTTNetworking.begin(ESP_EPROM_NAME, false); //false=read/write..
628 SerialDebug.print("Reading.2 EPROM JSON = ");
629 SerialDebug.println(_fullJSONString? _fullJSONString:"NULL");
630
631 //!check ... _fullMessage
632 //! Close the Preferences
634
635 SerialDebug.println("Write to MQTTNetworking.eprom done!");
636}
637
638#endif //USE_MQTT_NETWORKING
639
void redrawSemanticMarker_displayModule(boolean startNew)
redraws the Semantic Marker image..
void setScreenColor_displayModule(int screenColor)
cache for getting the screen color 0..n. Will reset the cache as well
void showSemanticMarker_displayModule(String semanticMarkerAddress, String title)
displays the Semantic Marker (a super QR code) on the M5 screen (title = to display)
#define START_NEW
Definition: DisplayModule.h:53
void processBarkletMessage(String message, String topic)
process an MQTT message looking for keywords (barklet language)
char * _jsonVersionString
char * _mqttPortString
char * _deviceNameString
boolean isTrueString(String valCmdString)
whether the string is TRUE, ON, 1
char * _mqttTopicString
char * _jsonLocationString
#define ESP_EPROM_NAME
Ambers 22nd birthday.. 2.20.22.
boolean _MQTTRunning
char * _jsonHeaderString
@ preSetupWIFI
char * _mqttPasswordString
char * _mqttUserString
void invokeCurrentSMModePage(char *topic)
send message to ourself to change to current specifed SM Mode
boolean processJSONMessageMQTT(char *ascii, char *topic)
process the JSON message (looking for FEED, etc). Note: topic can be nil, or if not,...
char * _uuidString
char * _mqttServerString
char _semanticMarkerString[MAX_MESSAGE]
Preferences _preferencesMQTTNetworking
3.3.22 Using the new JSON library which is supposed to catch syntax errors without blowing up
char * _mqttGuestPasswordString
#define _preferencesJSONName
Points to strings read from JSON (limited to 15 char key name)
String _fullJSONString
storage for the full JSON message string to send around..
#define MQTT_CALLBACK_SOLID_LIGHT
#define CALLBACKS_MQTT
Definition: MainModule.cpp:221
void main_updateMQTTInfo(char *ssid, char *ssid_password, char *username, char *password, char *guestPassword, char *deviceName, char *host, char *port, char *locationString)
sets the WIFI and MQTT user/password. It's up to the code (below, maybe in future a register approach...
Definition: MainModule.cpp:741
int minMenuModesMax_mainModule()
returns the current max of the MIN menu modes (using the setting of min or expanded) to determine
void main_dispatchAsyncCommandWithString(int asyncCallCommand, char *parameter)
Definition: MainModule.cpp:807
boolean isEmptyString(char *stringA)
informs if null or empty string
void rebootDevice_mainModule()
Definition: MainModule.cpp:616
int getCurrentSMMode_mainModule()
returns the current SM Mode
void setCurrentSMMode_mainModule(int whichSMMode)
sets the current screen mode .. which can be used by Button and Display processing
void main_dispatchAsyncCommand(int asyncCallCommand)
checks if any async commands are in 'dispatch' mode, and if so, invokes them, and sets their flag to ...
Definition: MainModule.cpp:789
char * createCopy(char *stringA)
#define SM_status
//status
Definition: MainModule.h:295
#define ASYNC_CALL_BUZZ_ON
sends a 'B' to the BLE end of the code (assuming a feeder is connected).
Definition: MainModule.h:149
#define ASYNC_CALL_OTA_FILE_UPDATE_PARAMETER
these are the async with a string parameter
Definition: MainModule.h:181
#define TOPIC_TO_SEND
Definition: MainModule.h:41
#define ASYNC_CALL_BUZZ_OFF
sends a 'b' to the BLE end of the code (assuming a feeder is connected).
Definition: MainModule.h:151
void savePreferenceInt_mainModule(int preferenceID, int val)
sets an int preference
void savePreferenceBoolean_mainModule(int preferenceID, boolean flag)
save a boolean preference
void savePreferenceIntFromString_mainModule(int preferenceID, char *val)
sets an int, but only if a valid integer, and no signs. If bad, then a 0 is stored
void savePreference_mainModule(int preferenceID, String preferenceValue)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
#define PREFERENCE_STEPPER_KIND_VALUE
uses STEPPER type
#define PREFERENCE_SENSOR_TILT_VALUE
Sensor preferences.
#define PREFERENCE_BLE_SERVER_USE_DEVICE_NAME_SETTING
if set, the BLE Server (like PTFeeder) will tack on the device name (or none if not defined).
#define PREFERENCE_ONLY_GEN3_CONNECT_SETTING
if true, only BLEClient connect to GEN3 feeders..
#define PREFERENCE_NO_BUTTON_CLICK_POWEROFF_SETTING
#define PREFERENCE_SEMANTIC_MARKER_ZOOMED_VALUE
Display preferences (SemanticMarker etc) - boolean.
#define PREFERENCE_MAIN_BLE_SERVER_VALUE
#define PREFERENCE_PAIRED_DEVICE_SETTING
the paired device for guest device feeding (6.6.22)
#define STEPPER_IS_TUMBLER
#define PREFERENCE_BLE_USE_DISCOVERED_PAIRED_DEVICE_SETTING
#define PREFERENCE_USE_DOC_FOLLOW_SETTING
for
#define STEPPER_IS_UNO
#define PREFERENCE_DISPLAY_SCREEN_TIMEOUT_VALUE
sets the timeout value
#define PREFERENCE_IS_MINIMAL_MENU_SETTING
sets the max temp for a poweroff
#define STEPPER_IS_MINI
#define PREFERENCE_HIGH_TEMP_POWEROFF_VALUE
sets the max temp for a poweroff
#define PREFERENCE_STEPPER_ANGLE_FLOAT_SETTING
#define PREFERENCE_MAIN_GATEWAY_VALUE
#define PREFERENCE_MAIN_BLE_CLIENT_VALUE
_WIFI_MQTTState
putting here .. time might have gone too fast..
Definition: REFAcTOR.c:562
_globalMQTTAttempts
reset the MQTT attempts
Definition: REFAcTOR.c:523
callCallbackMain(CALLBACKS_MQTT, MQTT_CALLBACK_SOLID_LIGHT,(char *)"solidLight")
call the callback specified from the caller (eg. NimBLE_PetTutor_Server .. or others)
updatePreferencesInEPROM()
NOTE: this writes over entire values, since it's a string vs an JSON object.
Definition: REFAcTOR.c:583
boolean saveJSONPreferences
Definition: REFAcTOR.c:525
else _ssidString
Definition: REFAcTOR.c:403
main_credentialsUpdated()
new 4.8.22 .. trying to kick out of AP mode if the credentials are good..
Definition: MainModule.cpp:392
else _ssidPasswordString
Definition: REFAcTOR.c:417
startDelay_WIFI_MQTTState()
init the delay, this uses the array of delays so we can change easier..
void restartWIFI_MQTTState()
restart the WIFI and then MQTT connection
Definition: REFAcTOR.c:570