2#include "../../Defines.h"
35#define MESSAGE_STORAGE_MAX 400
74 SerialMin.println(
"setup_mainModule");
96 SerialMin.println(
"FIRST TIME TURNING off the BLE_SERVER for the M5");
108#if defined(ESP_M5_CAMERA) || defined(ESP_32)
118#if defined(ESP_M5_CAMERA) || defined(ESP_32)
170 SerialTemp.println(
"incrementFeedCount_mainModule");
176#ifdef USE_MQTT_NETWORKING
198 if (substring.length() == 0 )
200 bool found = strstr(&message[0], &substring[0]);
201 SerialLots.printf(
"containsSubstring-%d - %s in: %s\n", found, &substring[0], &message[0]);
205#ifdef USE_MQTT_NETWORKING
206#include "../MQTTModule/MQTTNetworking.h"
208#ifdef USE_BLE_SERVER_NETWORKING
209#include "../BLEServerModule/BLEServerNetworking.h"
211#ifdef USE_BLE_CLIENT_NETWORKING
212#include "../BLEClientModule/BLEClientNetworking.h"
214#ifdef USE_BUTTON_MODULE
215#include "../ButtonModule/ButtonModule.h"
221#define CALLBACKS_MQTT 0
222#define CALLBACKS_BUTTON_MODULE 1
223#define CALLBACKS_BLE_CLIENT 2
224#define CALLBACKS_BLE_SERVER 3
230void callCallbackMain(
int callbacksModuleId,
int callbackType,
char *message);
235#define CALLBACKS_MAX_MQTT MQTT_MAX_CALLBACKS
236#define CALLBACKS_MAX_BUTTON_MODULE MAX_CALLBACKS_BM
237#define CALLBACKS_MAX_BLE_CLIENT BLE_CLIENT_MAX_CALLBACKS
238#define CALLBACKS_MAX_BLE_SERVER BLE_SERVER_MAX_CALLBACKS
244 SerialLots.printf(
"No callback defined .. %s\n", message);
268 SerialLots.printf(
"creatingCallbacks %d size: %d\n", max,
sizeof(
callbackSignature *));
270 for (
int i=0; i< max; i++)
274 return callbackArray;
292#ifdef USE_MQTT_NETWORKING
295#ifdef USE_BLE_SERVER_NETWORKING
298#ifdef USE_BLE_CLIENT_NETWORKING
301#ifdef USE_BUTTON_MODULE
322 if (callbackType < 0 || callbackType >= max)
324 SerialError.println(
"#### Error outside callback range");
339 if (callbackType < 0 || callbackType >= max)
341 SerialError.println(
"#### Error outside callback range");
344 void (*callbackFunction)(
char *) =
_allCallbacks[callbacksModuleId][callbackType];
345 (*callbackFunction)(message);
349#ifdef USE_MQTT_NETWORKING
354 SerialTemp.print(
"feedMessageCallback_main: ");
355 SerialTemp.println(message);
356 char * rxValue = (
char*)
"c";
371#ifdef USE_BLE_CLIENT_NETWORKING
373 SerialTemp.print(
"Paired Device: ");
376 SerialTemp.printf(
"Gateway: Feeding over the BLE CLIENT network .. if connected: %d\n",
isConnectedBLEClient());
382 SerialLots.println(
"after send feed via ble");
395 SerialDebug.println(
" *** main_credentialsUpdated .. setDoneWIFI_APModuleFlag **");
396#ifdef USE_WIFI_AP_MODULE
406 SerialCall.print(
"onWriteBLEServerCallback: ");
407 SerialCall.println(message);
413 SerialCall.print(
"onStatusMessageBLEServerCallback");
414 SerialCall.print(message);
423 SerialDebug.print(
"onWriteBLEServerCallback_main: ");
424 SerialDebug.println(message);
428 if (strlen(message) == 1)
431 if (strcmp(message,
"#MSG_START")==0)
439 if (strcmp(message,
"#MSG_END")==0)
461 message = (
char*)
"s";
465 message = (
char*)
"B";
469 message = (
char*)
"b";
474#ifdef USE_MQTT_NETWORKING
482#ifdef USE_BLE_SERVER_NETWORKING
490 SerialDebug.printf(
"Perform BLE Command '%s'\n", message);
492 char cmd = message[0];
500#ifdef USE_BLE_SERVER_NETWORKING
505 SerialDebug.println(
"*********");
514#define TRY_ASYNC_BLE_PROCESSING
515#ifdef TRY_ASYNC_BLE_PROCESSING
530#ifdef USE_CAMERA_MODULE
531 takePicture_CameraModule();
538#ifdef USE_BUTTON_MODULE
574 boolean isValid = pairedDevice && strlen(pairedDevice)>0 && strcmp(pairedDevice,
"NONE")!= 0;
578 isValid = pairedDeviceAddress && strlen(pairedDeviceAddress)>0 && strcmp(pairedDeviceAddress,
"NONE")!= 0;
579 SerialDebug.printf(
"isValidDeviceAddress(%s,%d)\n", pairedDeviceAddress, isValid);
581 SerialDebug.printf(
"isValidPairedDevice_mainModule(%s,%d)\n", pairedDevice, isValid);
591 if (pairedDevice && strlen(pairedDevice)>0 && strcmp(pairedDevice,
"NONE")!= 0)
593 SerialLots.printf(
"getPairedDeviceOrAddress_mainModule(%s)\n", pairedDevice);
597 if (pairedDeviceAddress && strlen(pairedDeviceAddress)>0 && strcmp(pairedDeviceAddress,
"NONE")!= 0)
599 SerialLots.printf(
"getPairedDeviceOrAddress_mainModule(%s)\n", pairedDeviceAddress);
600 return pairedDeviceAddress;
627 SerialTemp.println(
" **** POWEROFF ***");
640 SerialDebug.println(
"CLEANING EPROM PREFERENCES");
645#ifdef USE_MQTT_NETWORKING
649#ifdef USE_WIFI_AP_MODULE
654 SerialDebug.println(
"REBOOTING...");
680 if (strcmp(credential,
"NONE")==0)
684 SerialTemp.print(
"main_nextJSONWIFICredential:");
685 SerialTemp.println(credential);
690 SerialTemp.print(
"main_nextJSONWIFICredential:");
700 SerialMin.print(
"main_saveWIFICredentials");
709 if (strcmp(credential,
"NONE")==0)
728 SerialMin.println(
"main_cleanSavedWIFICredentials");
741void main_updateMQTTInfo(
char *ssid,
char *ssid_password,
char *username,
char *password,
char *guestPassword,
char *deviceName,
char * host,
char * port,
char *locationString)
743 SerialMin.printf(
"main_updateMQTTInfo(%s,%s,%s,%s,%s, %s)\n", ssid?ssid:
"NULL", ssid_password?ssid_password:
"NULL", username?username:
"NULL", password?password:
"NULL", guestPassword?guestPassword:
"NULL", locationString?locationString:
"NULL");
751#ifdef USE_WIFI_AP_MODULE
795 SerialError.printf(
"ERROR: async call out of range: %d\n", asyncCallCommand);
800 SerialLots.printf(
"main_dispatchAsyncCommand: %d\n", asyncCallCommand);
815 SerialError.printf(
"ERROR: async call out of range: %d\n", asyncCallCommand);
820 SerialTemp.print(
"main_dispatchAsyncCommandWithString:");
821 SerialTemp.print(asyncCallCommand);
822 SerialTemp.print(
": ");
840 SerialTemp.print(
"ASYNC_CALL_BLE_CLIENT_PARAMETER: ");
842#ifdef USE_BLE_CLIENT_NETWORKING
851 SerialTemp.print(
"ASYNC_CALL_OTA_FILE_UPDATE_PARAMETER: ");
853#ifdef USE_MQTT_NETWORKING
859 char httpAddress[100];
872 hostname[i] = (char)0;
874 strcpy(httpAddress,a);
879 SerialTemp.print(
"will performOTAUpdate: ");
880 SerialTemp.print(hostname);
881 SerialTemp.print(
" with httpAddress: ");
882 SerialTemp.println(httpAddress);
891 SerialDebug.print(
"ASYNC_JSON_MESSAGE_PARAMETER: ");
914 SerialLots.println(
"ASYNC_CALL_OTA_UPDATE");
915#ifdef USE_MQTT_NETWORKING
920 SerialTemp.println(
"ASYNC_CALL_CLEAN_CREDENTIALS");
921#ifdef USE_WIFI_AP_MODULE
927 SerialTemp.println(
"ASYNC_CALL_CLEAN_EPROM");
931 SerialLots.println(
"ASYNC_CALL_FEED_COMMAND");
933#ifdef USE_MQTT_NETWORKING
940#define TRY_WIFI_FIRST
944 SerialTemp.println(
"ASYNC_SEND_MQTT_FEED_MESSAGE");
946 SerialCall.println(
"async_send_feed.0");
949#ifdef USE_MQTT_NETWORKING
957 boolean isPaired = paired && strlen(paired)>0;
959 SerialTemp.printf(
"Paired = %s\n", paired?paired:(
char*)
"none");
968 strcat(pubString,
",'cmd':'feed'}");
978#ifdef USE_BLE_CLIENT_NETWORKING
983#ifdef USE_MQTT_NETWORKING_NOT_NOW
984 SerialCall.println(
"async_send_feed.1");
986 SerialTemp.println(
" *** NO BLE connected so send wifi ASYNC_SEND_MQTT_FEED_MESSAGE");
991 SerialCall.println(
"async_send_feed.2");
998#ifdef USE_MQTT_NETWORKING
1015 case ASYNC_SEND_MQTT_FEED_MESSAGE:
1016 SerialTemp.println(
"ASYNC_SEND_MQTT_FEED_MESSAGE");
1018 SerialCall.println(
"async_send_feed.0");
1020#ifdef USE_BLE_CLIENT_NETWORKING
1025#ifdef USE_MQTT_NETWORKING_NOT_NOW
1026 SerialCall.println(
"async_send_feed.1");
1028 SerialTemp.println(
" *** NO BLE connected so send wifi ASYNC_SEND_MQTT_FEED_MESSAGE");
1033 SerialCall.println(
"async_send_feed.2");
1040#ifdef USE_MQTT_NETWORKING
1054#ifdef USE_MQTT_NETWORKING
1060 char pubString[100];
1062 boolean isPaired = paired && strlen(paired)>0;
1064 SerialTemp.printf(
"Paired = %s\n", paired?paired:(
char*)
"none");
1073 strcat(pubString,
",'cmd':'feed'}");
1093 SerialDebug.printf(
"ASYNC_CALL_BUZZ %d\n",isBuzzOn);
1096 cmdToSend =
"{'cmd':'buzzon'}";
1098 cmdToSend =
"{'cmd':'buzzoff'}";
1105#ifdef USE_BLE_CLIENT_NETWORKING
1109 SerialLots.println(
"async_call_buzz_on/off -- not BLE connected.. send MQTT");
1111#ifdef USE_MQTT_NETWORKING
1123#ifdef USE_BLE_CLIENT_NETWORKING
1127 SerialLots.println(
"async_call_buzz_on -- not BLE connected.. send MQTT");
1129#ifdef USE_MQTT_NETWORKING
1135 SerialLots.println(
"async_call_buzz_on -- YES BLE connected.. send BLE");
1141 SerialDebug.println("Local, doit");
1152 SerialLots.println(
"ASYNC_SET_GATEWAY_ON");
1158 SerialLots.println(
"ASYNC_SET_GATEWAY_OFF");
1164 SerialLots.println(
"ASYNC_REBOOT");
1170 SerialLots.println(
"ASYNC_POWEROFF");
1175 SerialDebug.println(
"ASYNC_BLANKSCREEN");
1180#ifdef USE_MQTT_NETWORKING
1183 SerialDebug.print(
" ASYNC_SEND_MQTT_STATUS_URL: ");
1184 SerialDebug.println(statusURL);
1197#ifdef USE_MQTT_NETWORKING
1208#ifdef USE_MQTT_NETWORKING
1214 SerialLots.printf(
"NO COMMAND: %s", i);
1248 SerialLots.println(
"solidLightMessageCallback..");
1253 boolean lightOn =
true;
1254 lightOn = strstr(&message[0],
_ON_LIGHT);
1264#ifdef USE_WIFI_AP_MODULE
1276#ifdef USE_WIFI_AP_MODULE
1278#ifdef USE_BLE_CLIENT_NETWORKING
1289#ifdef USE_BLE_CLIENT_NETWORKING
1303 SerialLots.println(
"solidLight..");
1306 boolean lightOn = onOff;
1319 SerialDebug.println(
" ** #define Module Configuration **");
1322 SerialMin.println(
"[x] ESP_M5");
1324 SerialInfo.println(
"[ ] ESP_M5");
1328 SerialMin.println(
"[x] ESP_M5_CAMERA");
1332 SerialMin.println(
"[x] ESP_32");
1334 SerialInfo.println(
"[ ] ESP_32");
1336#ifdef USE_MQTT_NETWORKING
1338 SerialMin.println(
"[x] USE_MQTT_NETWORKING");
1340 SerialInfo.println(
"[ ] USE_MQTT_NETWORKING");
1342#ifdef USE_BLE_SERVER_NETWORKING
1344 SerialMin.println(
"[x] USE_BLE_SERVER_NETWORKING");
1346 SerialInfo.println(
"[ ] USE_BLE_SERVER_NETWORKING");
1348#ifdef USE_BLE_CLIENT_NETWORKING
1350 SerialMin.println(
"[x] USE_BLE_CLIENT_NETWORKING");
1352 SerialInfo.println(
"[ ] USE_BLE_CLIENT_NETWORKING");
1355#ifdef USE_BUTTON_MODULE
1357 SerialMin.println(
"[x] USE_BUTTON_MODULE");
1359 SerialInfo.println(
"[ ] USE_BUTTON_MODULE");
1362#ifdef USE_WIFI_AP_MODULE
1365 SerialMin.println(
"[x] USE_WIFI_AP_MODULE");
1367 SerialInfo.println(
"[ ] USE_WIFI_AP_MODULE");
1370#ifdef USE_STEPPER_MODULE
1371 SerialMin.println(
"[x] USE_STEPPER_MODULE");
1373 SerialInfo.println(
"[ ] USE_STEPPER_MODULE");
1377 SerialMin.println(
"[x] USE_UI_MODULE");
1379 SerialInfo.println(
"[ ] USE_UI_MODULE");
1382#ifdef USE_DISPLAY_MODULE
1383 SerialMin.println(
"[x] USE_DISPLAY_MODULE");
1385 SerialInfo.println(
"[ ] USE_DISPLAY_MODULE");
1389 SerialMin.println(
"[x] BOARD");
1391 SerialInfo.println(
"[ ] BOARD");
1393#ifdef USE_SPIFF_MODULE
1394 SerialMin.println(
"[x] USE_SPIFF_MODULE");
1396 SerialInfo.println(
"[ ] USE_SPIFF_MODULE");
1405#ifdef USE_SMART_CLICKER
1406 SerialMin.println(
"[x] USE_SMART_CLICKER");
1408 SerialInfo.println(
"[ ] USE_SMART_CLICKER");
1411#if (SERIAL_DEBUG_ERROR)
1412 SerialMin.println(
"[x] SERIAL_DEBUG_ERROR");
1414#if (SERIAL_DEBUG_DEBUG)
1415 SerialMin.println(
"[x] SERIAL_DEBUG_DEBUG");
1417#if (SERIAL_DEBUG_INFO)
1418 SerialMin.println(
"[x] SERIAL_DEBUG_INFO");
1420#if (SERIAL_DEBUG_MINIMAL)
1421 SerialMin.println(
"[x] SERIAL_DEBUG_MINIMAL");
1434 return strdup(stringA);
1446 else if (strlen(stringA) == 0)
1457 if (!str)
return false;
1460 while (i < strlen(str))
1478 float batVoltage = M5.Axp.GetBatVoltage();
1479 float batPercentage = (batVoltage < 3.2) ? 0 : ( batVoltage - 3.2 ) * 100;
1481 float batPercentage = 87.0;
1488 uint16_t vbatData = M5.Axp.GetVbatData();
1489 double vbat = vbatData * 1.1 / 1000;
1490 batPercentage = 100.0 * ((vbat - 3.0) / (4.07 - 3.0));
1492 if (batPercentage > 100.0)
1493 batPercentage = 100.0;
1494 return batPercentage;
1502#ifdef USE_MQTT_NETWORKING
1520 M5.IMU.getTempData(&temperature);
1523 if (temperature > maxtemp)
1528#ifdef USE_MQTT_NETWORKING
1534 SerialTemp.println(
" *** This would poweroff .. but you can send message");
1540 float temperature = 10.0;
1542 return temperature ;
1595 sprintf(buf,
"&%s=%s", key, val);
1609#ifdef USE_MQTT_NETWORKING
1613#ifdef USE_BLE_CLIENT_NETWORKING
1620#ifdef USE_WIFI_AP_MODULE
1626#ifdef USE_BLE_SERVER_NETWORKING
1644#ifdef NO_MORE_PREFERENCE_BLE_USE_DISCOVERED_PAIRED_DEVICE_SETTING
1658#ifdef USE_MQTT_NETWORKING
1684void main_setStatusJSON(
const char* JSONString)
1689void main_setStatusKeyValue(
const char* key,
const char* value)
1715#ifdef USE_MQTT_NETWORKING
1728 boolean sendToStepperModule =
false;
1729 SerialDebug.printf(
"***** processClientCommand_mainModule(%c) from client*****\n", cmd);
1733 if ((cmd == 0x00) || (cmd ==
's') || (cmd ==
'c'))
1735 sendToStepperModule =
true;
1737 else if (cmd ==
'a')
1740 SerialDebug.println(
"cmd=a startTimer");
1745 else if (cmd ==
'A')
1748 SerialDebug.println(
"cmd=A stopTimer");
1754 else if (cmd ==
'j')
1756 sendToStepperModule =
true;
1757 SerialLots.println(
"Setting FeedState = JACKPOT_FEED");
1761 else if (cmd ==
'u')
1763 SerialLots.println(
"Setting feederType = UNO");
1766 else if (cmd ==
'm')
1768 SerialLots.println(
"Setting feederType = MINI");
1772 else if (cmd ==
'L')
1774 SerialLots.println(
"Setting feederType = Tumbler");
1778 else if (cmd ==
'B')
1780 sendToStepperModule =
true;
1781 SerialDebug.println(
"Setting buzzStatus = BUZZON");
1785 else if (cmd ==
'b')
1787 sendToStepperModule =
true;
1789 SerialDebug.println(
"Setting buzzStatus = BUZZOFF");
1792 else if (cmd ==
'T')
1794 SerialDebug.println(
"*** Setting tilt = ON");
1797 else if (cmd ==
't')
1799 SerialDebug.println(
"Setting tilt = OFF");
1802 else if (cmd ==
'R')
1804 SerialLots.println(
"Clean Credentials");
1808 else if (cmd ==
'O')
1810 SerialLots.println(
"OTA Update.. ");
1814 else if (cmd ==
'X')
1816 SerialLots.println(
"Clean EPROM.. ");
1822 else if (cmd ==
'G')
1824 SerialLots.println(
"Setting Gateway = ON");
1827 else if (cmd ==
'g')
1829 SerialLots.println(
"Setting Gateway = OFF");
1832 else if (cmd ==
'_')
1835 SerialLots.println(
"unused cmd '_'");
1837 else if (cmd ==
'Z')
1839 sendToStepperModule =
false;
1841 SerialLots.println(
"Setting SM Zoom = zoomed");
1844 else if (cmd ==
'z')
1846 sendToStepperModule =
false;
1848 SerialLots.println(
"Setting SM Zoom = full SM");
1851 else if (cmd ==
'N')
1860 else if (cmd ==
'n')
1865 else if (cmd ==
'W')
1869 else if (cmd ==
'w')
1871 SerialTemp.println(
"w for swapWifi");
1875 else if (cmd ==
'P')
1881 else if (cmd ==
'D')
1886 else if (cmd ==
'd')
1891 else if (cmd ==
'E')
1898 else if (cmd ==
'e')
1905 else if (cmd ==
'r')
1910 else if (cmd ==
'H')
1913 SerialLots.println(
"Valid Commands: ");
1914 SerialLots.println(
" H == help, this message");
1915 SerialLots.println(
" 0x0, s, c == Single Feed ");
1916 SerialLots.println(
" a == AutoFeed On");
1917 SerialLots.println(
" A == AutoFeed Off");
1918 SerialLots.println(
" u == UNO ");
1919 SerialLots.println(
" m == MINI ");
1920 SerialLots.println(
" L == tumbler");
1921 SerialLots.println(
" D == counterclockwise motor direction");
1922 SerialLots.println(
" d == clockwise motor direction");
1924 SerialLots.println(
" B == Buzzer On");
1925 SerialLots.println(
" b == Buzzer Off");
1926 SerialLots.println(
" G == Gateway On");
1927 SerialLots.println(
" g == Gateway Off");
1928 SerialLots.println(
" R == clean credentials");
1929 SerialLots.println(
" X == clean EPROM");
1930 SerialLots.println(
" r == reboot ");
1931 SerialLots.println(
" O == OTA update");
1932 SerialLots.println(
" T == tiltOn");
1933 SerialLots.println(
" t == tiltOff");
1934 SerialLots.println(
" N == send WIFI Credential to BLEServer");
1935 SerialLots.println(
" n == next WIFI Credential");
1936 SerialLots.println(
" W == retry WIFI");
1937 SerialLots.println(
" w == swap WIFI");
1938 SerialLots.println(
" P == print SPIFF");
1939 SerialLots.println(
" E == use only PTFeeder naming");
1940 SerialLots.println(
" e == use naming PTFeeder:name");
1941 SerialLots.println(
" Z == Setting SM Zoom = zoomed");
1942 SerialLots.println(
" z == Setting SM Zoom = full SM");
1950 SerialLots.printf(
"*****invalid command '%c' from client*****\n", cmd);
1953#ifdef USE_STEPPER_MODULE
1954 if (sendToStepperModule)
1971 SerialLots.printf(
"Unix Time: %d\n", now);
1982 if (strncmp(cmd,
"sm",2) == 0)
1985 char *p = strchr(cmd,
'm');
1991 SerialLots.print(
"whichSMMode: ");
1992 SerialLots.print(cmd);
1993 SerialLots.print(
" => " );
1994 SerialLots.println(num);
2006 return (strcasecmp(cmd,mode)==0);
2012 SerialLots.printf(
"charSMMode_mainModule: %d\n", whichSMMode);
2053 SerialLots.print(
"setCurrentSMMode_mainModule:");
2054 SerialLots.println(whichSMMode);
2079 SerialTemp.print(
"incrementSMMode_mainModule:");
2095#ifdef USE_BLE_CLIENT_NETWORKING
2122 SerialTemp.printf(
"auto-settingGateway(%d)\n", isGEN3);
2129 SerialCall.printf(
"setConnectedBLEDevice_mainModule: %s\n", deviceName);
2135 char *colon = index(deviceName,
':');
2137 colon = index(colon,
':');
2141 while (*colon && *colon !=
',')
2154 SerialTemp.print(
"connectedBLEName= ");
2168 colon += strlen(
"Address:");
2170 while (*colon && *colon ==
' ')
2175 while (*colon && *colon !=
',')
2188 SerialTemp.print(
"_connectedBLEDeviceAddress= ");
2202 nameToUse = (
char*)
"";
2204#ifdef USE_BLE_CLIENT_NETWORKING
2221#ifdef USE_BLE_CLIENT_NETWORKING
2240#ifdef USE_BUTTON_MODULE
2247#ifdef USE_BUTTON_MODULE
2254#ifdef USE_BUTTON_MODULE
2261#ifdef USE_BUTTON_MODULE
void sendCommandBLEClient(String cmdString)
boolean isConnectedBLEClient()
returns whether connected over BLE as a client to a server(like a ESP feeder)
void sendFeedCommandBLEClient()
sends the "feed" command over bluetooth to the connected device..
boolean useBLEClient()
returns if the BLEClient is turned on.. note, if connected to a BLE device, then disconnect
void sendCommandBLEClient_13orLess(String cmdString)
send a string of 13 characters or less
void sendBLEMessageACKMessage()
send ACK over bluetooth, this right now is 0x01
char * getServiceName_BLEServerNetworking()
retrieve the service name (PTFEEDER, PTFeeder:Name, PTClicker:Name, etc)
void redrawSemanticMarker_displayModule(boolean startNew)
redraws the Semantic Marker image..
void blankScreen_displayModule()
blanks the screen
int getLoopTimer_displayModule()
returns the loop timer (just a timer..)
void publishMQTTMessageDefaultTopic(char *message)
Wrapper of the mqttclient publish.
void cleanEPROM_MQTTNetworking()
cleans the eprom info
void sendMessageMQTT(char *message)
void sendStatusMessageMQTT(const char *semanticMarker)
sends the semantic marker as a doc follow message #remoteMe (vs STATUS, as that triggers a status rep...
boolean processJSONMessageMQTT(char *ascii, char *topic)
process the JSON message (looking for FEED, etc). Note: topic can be nil, or if not,...
void sendDocFollowMessageMQTT(const char *semanticMarker)
sends the semantic marker as a doc follow message
boolean isConnectedMQTT_MQTTState()
value of MQTT connected
char * getDeviceNameMQTT()
called for things like the advertisement
boolean isConnectedWIFI_MQTTState()
value of WIFI connected
void restartWIFI_MQTTState()
restart the WIFI and then MQTT connection
#define MQTT_CALLBACK_FEED
void cleanEpromPreferences()
cleans the EPROM
void sendSemanticMarkerDocFollow_mainModule(const char *SMDocFollowAddress)
sends the SM on the DOCFOLLOW channel (publish it..)
void initCallbacksMain()
init the callbacks to dummy callbacks
#define MESSAGE_STORAGE_MAX
global for others to use..
boolean _connecteBLEisGEN3
whether connected GEN3
void setAsyncCallOTAUpdate(bool flag)
sets the async OTA flag (for next loop)
void main_cleanSavedWIFICredentials()
clean the saved WIFI credential, otherwise the AP mode doesn't work (6.3.22)
char _fullStatusString[300]
status string (URL query format)
boolean _asyncCallOTAUpdateFlag
3.28.22 .. implemented in ESP_IOT.ino
boolean _stopAllProcessing
testing..
void takePicture_MainModule()
take a picture (calls the camera module).. what to do with picture??? TODO
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...
void setConnectedBLEDevice_mainModule(char *deviceName, boolean isGEN3)
char _fullBLEDeviceName[100]
full: ""Name: PTFeeder:HowieFeeder, Address: 7c:9e:bd:48:af:92, serviceUUID: 0xdead"
#define CALLBACKS_MAX_BLE_SERVER
char * connectedBLEDeviceNameAddress_mainModule()
returns address part of name.
void cleanSSID_EPROM_MessageCallback(char *message)
clean the SSID eprom (MQTT_CLEAN_SSID_EPROM)
callbackSignature * createMemory(int max)
return dyamically created array of max
void toggleMinimalMenuMode_mainModule()
toggles the menu mode
char * charSMMode_mainModule(int whichSMMode)
returns string form whichSMMode, sg "sm0", sm1 ...
char _smMode_MainModule[10]
current smMode
void loop_mainModule()
called for the loop() of this plugin
char * getSemanticMarkerDocFollow_mainModule()
gets the semanticAddress SemanticMarker™
void registerCallbackMain(int callbacksModuleId, int callbackType, void(*callback)(char *))
register the callback based on the callbackType. use the callbacksModuleId for which one....
char * deviceName_mainModule()
gets the device name
void dummyCallbackMain(char *message)
example callback
#define CALLBACKS_MAX_MQTT
void initGlobals_mainModule()
init globals strings
char _deviceNameSave[50]
saved deviceName storage..
boolean connectedBLEDeviceIsGEN3_mainModule()
whether the connected is a GEN3 (so the name isn't valid)
int minMenuModesMax_mainModule()
returns the current max of the MIN menu modes (using the setting of min or expanded) to determine
#define CALLBACKS_BLE_SERVER
boolean _asyncCallFlags[ASYNC_CALL_MAX]
storage for asyncCallCommands
void processClientCommandChar_mainModule(char cmd)
single character version of processClientCommand (since many used that already)
int getFeedCount_mainModule()
feedcount info..
void onStatusMessageBLEServerCallback(char *message)
The callback for "status messages" of the bluetooth.
char * main_currentStatusURL()
returns a string in in URL so: status?battery=84'&buzzon='off' } .. etc
char * main_JSONStringForWIFICredentials()
retrieve a JSON string for the ssid and ssid_password: {'ssid':<ssid>,'ssidPassword':<pass>"}
int feedCountMax_mainModule()
returns the max for this feeder
void solidLightOnOff(boolean onOff)
callback for SOLID blinking led
void main_credentialsUpdated()
moved here 4.25.22 (entirely from ESP_IOT.ino)
void setup_mainModule()
called from the setup()
boolean stopAllProcesses_mainModule()
if stopped
void restartAllMenuStates_mainModule()
restarts all the menu states to the first one .. useful for getting a clean start....
void setSemanticMarkerDocFollow_mainModule(char *SMDocFollowAddress)
sed the address to follow
int whichSMMode_mainModule(char *cmd)
************** SM Mode Processing ***************
int _mainLoopCounter
a couinter to slow down the loop doing things..
void main_dispatchAsyncCommandWithString(int asyncCallCommand, char *parameter)
void initAsyncCallFlags()
initialize the async call flags (with and without parameters)
void solidLightMessageCallback(char *message)
callback for SOLID blinking led
boolean isEmptyString(char *stringA)
informs if null or empty string
void rebootDevice_mainModule()
void poweroff_mainModule()
power off
int maxMenuModes_mainModule()
returns the current max of the menu modes (using the setting of min or expanded) to determine
void buttonB_ShortPress_mainModule()
the short press of the side button
bool containsSubstring(String message, String substring)
check if the string contains the other string. This is a poor man's grammer checker
void decrementSMMode_mainModule()
increment the currentSMMode, wrapping and using the max menu
void onWriteBLEServerCallbackFinish(char *message)
The FINISH of callback for "onWrite" of the bluetooth "onWrite'.
void callCallbackMain(int callbacksModuleId, int callbackType, char *message)
performs the indirect callback based on the callbackType
int getCurrentSMMode_mainModule()
returns the current SM Mode
boolean _waitingForBigMessageEnd
store a big message #MSG_START .. #MSG_END
void stopProcessesForOTAUpdate_mainModule()
stop all loops... while OTA working..
void feedMessageCallback(char *message)
void resetFeedCount_mainModule()
sets the feed count max
boolean asyncCallOTAUpdate()
performs an async OTA update
void sendMessageString_mainModule(char *messageString)
adding a synchronous call to send a message over the network (assuming MQTT but not specified),...
char * main_currentStatusJSON()
returns a string in JSON format, such that {'battery':'84'}, {'buzzon':'off'} .. etc
void(* callbackSignature)(char *)
char * getFullBLEDeviceName_mainModule()
full: ""Name: PTFeeder:HowieFeeder, Address: 7c:9e:bd:48:af:92, serviceUUID: 0xdead"
int getFeederType_mainModule()
get the feeder type (Sepper 1,2,3 ...)
char _connectedBLEDeviceName[50]
saved BLE connected name 8.26.22
char * _lastSemanticMarkerDocFollow
char _connectedBLEDeviceAddress[50]
full: ""Address: 7c:9e:bd:48:af:92, serviceUUID: 0xdead"
void addMoreStatusQueryString()
void buttonA_LongPress_mainModule()
long press on buttonA (top button)
void addStatusBooleanFlag(const char *key, boolean flag)
adds to _fullStatusString a query string "&key=value"
void invokeAsyncCommands()
checks if any async commands are in 'dispatch' mode, and if so, invokes them, and sets their flag to ...
#define CALLBACKS_MAX_BLE_CLIENT
boolean startsWithChar(char *str, char c)
a char* version of startsWith (after skipping spaces)
callbackSignature * _allCallbacks[CALLBACKS_MODULE_MAX]
array of known size (CALLBACKS_MODULE_MAX) of callbackSignatures
void setCurrentSMMode_mainModule(int whichSMMode)
sets the current screen mode .. which can be used by Button and Display processing
char * getPairedDeviceOrAddress_mainModule()
returns if the paired device is not NONE .. returns address or device
char * getPairedDevice_mainModule()
returns if the paired device is not NONE
void onWriteBLEServerCallback(char *message)
The callback for "onWrite" of the bluetooth "onWrite'.
boolean _callbacksInitializedMain
flag for initializing if not yes
#define CALLBACKS_BLE_CLIENT
void main_dispatchAsyncCommand(int asyncCallCommand)
checks if any async commands are in 'dispatch' mode, and if so, invokes them, and sets their flag to ...
char _JSONStringForWIFICredentials[200]
global to store credentials when ever they are stored..
boolean matchesSMMode_mainModule(char *cmd, int whichSMMode)
returns if a match the mode. whichSMMode is 0..12 and == sm0 .. smn
int _feedCount_mainModule
5.3.22 added a feed count approach.. (NOTE: there is a _feedCount in Dispence.cpp ....
int _saveWhichSMMode
the saved SMMode
void refreshDelayButtonTouched_MainModule()
called by the feed operation to say the device is still running.. and count it as a button click.
char * connectedBLEDeviceName_mainModule()
returns the connected BLE Device name (the :NAME of advertisment, Address: 01:39:3f:33 part of name,...
boolean isMinimalMenuMode_mainModule()
returns which mode in (min or expanded)
char _asyncParameter[500]
the parameter being sent to those commands passing an argument
int getTimeStamp_mainModule()
void buttonB_LongPress_mainModule()
the long press of the side button
void blinkMessageCallback(char *message)
callback for blinking led
void restartProcessesForOTAUpdate_mainModule()
restart all loops... while OTA working..
char * createCopy(char *stringA)
#define CALLBACKS_MAX_BUTTON_MODULE
boolean _asyncCallFlagsParameters[ASYNC_CALL_PARAMETERS_MAX]
array of async flags for the different ASYNC_CALl values
void main_printModuleConfiguration()
void singleClickTouched(char *whichButton)
float getTemperature_mainModule()
retrieves the temperature .
void buttonA_ShortPress_mainModule()
boolean isValidPairedDevice_mainModule()
returns if the paired device is not NONE. Note, the paired Name might be an address now (see below)
char * main_nextJSONWIFICredential()
! cycle through the next WIFI saved credential
void onBLEServerCallback(char *message)
The callback for "onWrite" of the bluetooth "onWrite'.
void addStatusStringFlag(const char *key, char *val)
adds a query string "&key=value"
void incrementSMMode_mainModule()
increment the currentSMMode, wrapping and using the max menu
#define CALLBACKS_BUTTON_MODULE
char _messageStorage[MESSAGE_STORAGE_MAX]
void incrementFeedCount_mainModule()
increments .. and if MAX goes to 0 – and sends a message on MQTT
void main_saveWIFICredentials(char *ssid, char *ssid_password)
save the WIFI credential
void readPreferences_mainModule()
MainModule
char * getPairedDeviceAddress_mainModule()
returns if the paired device is not NONE
float getBatPercentage_mainModule()
start of the sensor updates ... TODO: tie these to the MQTT messaging as well..
int _callbacksFunctionsMAXS[CALLBACKS_MODULE_MAX]
the array of callback functions
#define ASYNC_CALL_FEED_COMMAND
sends a 'c' to the BLE end of the code (assuming a feeder is connected). Need to morph if a real feed...
#define MAX_SM_MIN_MODES
note for now, heep the max the same – so only goes through zoom or not zoom
void cleanEPROM_mainModule()
cleans the main module EPROM
#define ASYNC_CALL_MAX
the max one greater than last one
#define ASYNC_REBOOT
sets the GATEWAY mode off
#define ASYNC_CALL_BLE_CLIENT_PARAMETER
these are the async with a string parameter. This sends a BLE command
#define ASYNC_SEND_MQTT_FEED_MESSAGE
sends a message (like FEED) on the users topic
#define CALLBACKS_MODULE_MAX
#define ASYNC_CALL_CLEAN_CREDENTIALS
cleans out the credentials and restarts in AP (Access Point) mode.
#define ASYNC_SWAP_WIFI
swaps WIFI 'w'
#define ASYNC_SET_GATEWAY_ON
sets the GATEWAY mode on
#define MAX_SM_EXPANDED_MODES
#define ASYNC_RESTART_WIFI_MQTT
restarts the WIFI (after BLE interrupt over)
#define ASYNC_CALL_BUZZ_ON
sends a 'B' to the BLE end of the code (assuming a feeder is connected).
#define ASYNC_POWEROFF
sets the GATEWAY mode off
#define ASYNC_CALL_CLEAN_EPROM
cleans the EPROM totally, and reboots
#define ASYNC_BLANKSCREEN
blank the screen
#define ASYNC_CALL_PARAMETERS_MAX
the max one greater than last one
#define ASYNC_SEND_MQTT_STATUS_URL_MESSAGE
sends the status from the main module URL
#define ASYNC_SET_GATEWAY_OFF
sets the GATEWAY mode off
#define ASYNC_CALL_OTA_FILE_UPDATE_PARAMETER
these are the async with a string parameter
#define ASYNC_CALL_OTA_UPDATE
TODO: make this a registeration approach.
#define ASYNC_NEXT_WIFI
next WIFI 'n'
#define ASYNC_CALL_BUZZ_OFF
sends a 'b' to the BLE end of the code (assuming a feeder is connected).
#define ASYNC_JSON_MESSAGE_PARAMETER
these are the async with a string parameter
void updateMenuState(ModelKindEnum modelKind)
updates the model for the menu state, this sets max etc
void startStopTimer_mainModule(boolean startTimer)
void initModelStructs_ModelController()
initialize the objects
void restartAllMenuStates_ModelController()
restarts all the menu states to the first one .. useful for getting a clean start....
void performOTAUpdateSimple()
retrieves from constant location
void performOTAUpdate(char *hostname, char *httpAddress)
connects to host and grabs the http file and tries to update the binary (OTA)
void savePreferenceInt_mainModule(int preferenceID, int val)
sets an int preference
void savePreferenceBoolean_mainModule(int preferenceID, boolean flag)
save a boolean preference
boolean getPreferenceBoolean_mainModule(int preferenceID)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
void togglePreferenceBoolean_mainModule(int preferenceID)
toggles a preference boolean
int getPreferenceInt_mainModule(int preferenceID)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
char * getPreference_mainModule(int preferenceID)
char * getPreferenceString_mainModule(int preferenceID)
returns the preference but in it's own string buffer. As long as you use it before calling getPrefere...
void printPreferenceValues_mainModule()
print the preferences to SerialDebug
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_PAIRED_DEVICE_ADDRESS_SETTING
the paired device for guest device feeding (6.6.22) .. but the Address 9.3.22
#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_SENDWIFI_WITH_BLE
sends the WIFI to all except current device if set
#define PREFERENCE_SEMANTIC_MARKER_ZOOMED_VALUE
Display preferences (SemanticMarker etc) - boolean.
#define PREFERENCE_STEPPER_JACKPOT_FEED_VALUE
#define PREFERENCE_WIFI_CREDENTIAL_2_SETTING
#define PREFERENCE_MAIN_BLE_SERVER_VALUE
#define PREFERENCE_PAIRED_DEVICE_SETTING
the paired device for guest device feeding (6.6.22)
#define PREFERENCE_STEPPER_BUZZER_VALUE
stepper preferences
#define STEPPER_IS_TUMBLER
#define PREFERENCE_BLE_USE_DISCOVERED_PAIRED_DEVICE_SETTING
#define PREFERENCE_WIFI_CREDENTIAL_1_SETTING
#define WIFI_CREDENTIALS_MAX
for now, save 2 WIFI Credentials
#define PREFERENCE_FIRST_TIME_FEATURE_SETTING
a firsttime feature flag (only 1 per build) 7.12.22 defaulting to TRUE
#define PREFERENCE_IS_MINIMAL_MENU_SETTING
sets the max temp for a poweroff
#define PREFERENCE_DEVICE_NAME_SETTING
the device name itself (6.6.22)
#define PREFERENCE_HIGH_TEMP_POWEROFF_VALUE
sets the max temp for a poweroff
#define PREFERENCE_MAIN_GATEWAY_VALUE
#define PREFERENCE_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING
void printFile_SPIFFModule()
prints the spiff file to the SerialDebug output
void stepperModule_ProcessClientCmdFinal(char cmd)
the Blink the LED - and it will use the latest BUZZER status (so MQTT could set buzzer on....
void setup_tokenParser_mainModule()
setup a test ..
void blinkLED_UIModule()
blink the LED
void solidLightOnOff_UIModule(boolean onOff)
callback for SOLID blinking led
void clean_SSID_WIFICredentials()
returns true if the SSID is set, false otherwise. If set, then just exit..
void WIFI_APModule_updateMQTTInfo(char *ssid, char *ssid_password, char *username, char *password, char *guestPassword, char *deviceName, char *host, char *port, char *locationString)
sets the MQTT user/password. It's up to the code to decide who needs to know
boolean doneWIFI_APModule_Credentials()
called to see if the WIFIModule has finished bootstrapping..
void cleanEPROM_WIFI_APModule()
cleans the eprom info
void setDoneWIFI_APModuleFlag(boolean flag)
called to set the done flag