2#include "../../Defines.h"
5#define USE_NEW_M5ATOMCLASS
7#ifdef USE_NEW_M5ATOMCLASS
9#include "../M5AtomClassModule/M5AtomClassType.h"
11#include "../M5AtomClassModule/M5Atom_SocketModuleClass.h"
12#include "../M5AtomClassModule/M5Atom_QRCodeModuleClass.h"
13#include "../M5AtomClassModule/M5Atom_HDriverModuleClass.h"
15#include "../M5AtomClassModule/M5Atom_Core2ModuleClass.h"
17#include "../M5AtomClassModule/M5Atom_TinyGPSModuleClass.h"
19#include "../M5AtomClassModule/M5Atom_CameraModuleClass.h"
22#include "../M5AtomClassModule/M5Atom_NoModuleClass.h"
27#include "../ATOM_LED_Module/M5Display.h"
30#pragma mark BUTTON Processing of M5
40#pragma mark M5AtomClassType
63#define NUM_M5ATOM_CLASS 7
73#pragma mark SensorClassType
75#define USE_SENSOR_CLASS
76#ifdef USE_SENSOR_CLASS
78#include "../SensorClass/SensorClassType.h"
79#include "../SensorClass/BuzzerSensorClass.h"
80#include "../SensorClass/KeyUnitSensorClass.h"
82#include "../SensorClass/PIRSensorClass.h"
85#include "../SensorClass/ChainButtonClassType.h"
87#define NUM_SENSOR_CLASS_TYPES 4
123 for (
int i=0; i< count; i++)
160 for (
int i=0; i< count; i++)
185 SerialDebug.println(
" *** initSensorClassTypeArray ***");
200 int whichSensorClassIndex = 0;
201 SerialDebug.println(
"setup_SensorClassIypes");
213 SerialDebug.printf(
"**** sensors are more than max .. FIX CODE");
215 SerialDebug.printf(
"Created %d SensorClassTypes\n", whichSensorClassIndex);
229 for (
int i=0; i< count; i++)
232 SerialDebug.printf(
"Looking for sensor: %s, %ld, %ld\n", sensor->
sensorName, sensor->
pin1, sensor->
pin2);
235 boolean foundMatchingClassType =
false;
240 char *sensorIdentity = whichSensorClassType->
classIdentity();
241 if (strcmp(sensor->
sensorName, sensorIdentity)==0)
246#ifdef ALL_ARE_SENSOR_CLASS
255 switch (whichSensorClassType->
type())
260 SerialDebug.printf(
"whichSensorClass == ChainButtonClassType\n");
272 SerialDebug.printf(
"whichSensorClass == SensorClassType\n");
288 whichSensorClassType->
setup();
290 foundMatchingClassType =
true;
295 if (strcmp(sensor->
sensorName,
"BuzzerSensorClass")==0)
309 else if (strcmp(sensor->
sensorName,
"PIRSensorClass")==0)
322 if (!foundMatchingClassType)
324 SerialDebug.printf(
"Missing SensorClass definition: %s\n", sensor->
sensorName);
330 for (
int i=0; i< count; i++)
336 SerialDebug.printf(
"Missing class definition: %s\n", sensor->
sensorName);
341 SerialDebug.println(
"Finish initSensorClassTypeArray");
378 return MAIN_BLE_SERVER_SERVICE_NAME_PTFeeder;
380 return MAIN_BLE_SERVER_SERVICE_NAME_PTClicker;
411#define MESSAGE_STORAGE_MAX 500
453 SerialMin.println(
"setup_mainModule");
454#ifdef BOOTSTRAP_CLEAN
458#define TEMP_FIX_LOOP_NO
483 SerialMin.println(
"FIRST TIME TURNING off the BLE_SERVER for the M5");
511#define TRY_DUPLICATES_works
520 SerialDebug.println(
"END setup_mainModule");
523#if defined(ESP_M5_CAMERA) || defined(ESP_32)
525int _mainLoopCounter = 0;
539#if defined(ESP_M5_CAMERA) || defined(ESP_32)
542 if (_mainLoopCounter++ > 30)
547 _mainLoopCounter = 0;
552#pragma mark Serial Input Processor
559 if (Serial.available())
562 String command = Serial.readStringUntil(
'\n');
564 SerialDebug.println(command);
568 if (command ==
"help")
570 SerialDebug.println(
"Enter any Single Char or JSON msg, type '.' for commands");
571 SerialDebug.println(
"r -- reboot");
572 SerialDebug.println(
". -- shows single char commands");
573 SerialDebug.println(
"Example JSON to change WIFI (copy and modify with your values)");
574 SerialDebug.println(
" supports single quotes for values");
575 SerialDebug.println(
"{'ssid':'Bob', 'ssidPassword':'scott'}");
578 else if (command ==
"r")
589#pragma mark button processing
590#ifdef USE_BUTTON_MODULE
658 SerialTemp.println(
"incrementFeedCount_mainModule");
686 if (substring.length() == 0 )
688 bool found = strstr(&message[0], &substring[0]);
689 SerialLots.printf(
"containsSubstring-%d - %s in: %s\n", found, &substring[0], &message[0]);
694#include "../MQTTModule/MQTTNetworking.h"
697#include "../BLEServerModule/BLEServerNetworking.h"
700#include "../BLEClientModule/BLEClientNetworking.h"
701#ifdef USE_BUTTON_MODULE
702#include "../ButtonModule/ButtonProcessing.h"
708#define CALLBACKS_MQTT 0
709#define CALLBACKS_BUTTON_MODULE 1
710#define CALLBACKS_BLE_CLIENT 2
711#define CALLBACKS_BLE_SERVER 3
717void callCallbackMain(
int callbacksModuleId,
int callbackType,
char *message);
722#define CALLBACKS_MAX_MQTT MQTT_MAX_CALLBACKS
723#define CALLBACKS_MAX_BUTTON_MODULE MAX_CALLBACKS_BM
724#define CALLBACKS_MAX_BLE_CLIENT BLE_CLIENT_MAX_CALLBACKS
725#define CALLBACKS_MAX_BLE_SERVER BLE_SERVER_MAX_CALLBACKS
731 SerialLots.printf(
"No callback defined .. %s\n", message);
755 SerialLots.printf(
"creatingCallbacks %d size: %d\n", max,
sizeof(
callbackSignature *));
757 for (
int i=0; i< max; i++)
761 return callbackArray;
785#ifdef USE_BUTTON_MODULE
802 SerialLots.printf(
"registerCallbackMain %d, %d\n", callbacksModuleId, callbackType);
808 if (callbackType < 0 || callbackType >= max)
810 SerialError.printf(
"#### Error outside callback range - 1, %d\n", callbackType);
825 if (callbackType < 0 || callbackType >= max)
827 SerialError.printf(
"#### Error outside callback range - 2, %d\n", callbackType);
831 void (*callbackFunction)(
char *) =
_allCallbacks[callbacksModuleId][callbackType];
832 (*callbackFunction)(message);
839 return valCmdString.equalsIgnoreCase(
"on") ||
840 valCmdString.equalsIgnoreCase(
"1") ||
841 valCmdString.equalsIgnoreCase(
"true");
850 SerialCall.printf(
"messageSetVal(%s,%s)\n", setName, valValue);
877#pragma mark USE_NEW_M5ATOMCLASS
896 SerialTemp.print(
"feedMessageCallback_main: ");
897 SerialTemp.println(message);
898 char * rxValue = (
char*)
"c";
915 SerialTemp.print(
"Paired Device: ");
918 SerialTemp.printf(
"Gateway: Feeding over the BLE CLIENT network .. if connected: %d\n",
isConnectedBLEClient());
924 SerialLots.println(
"after send feed via ble");
928 SerialDebug.println(
"FEED now send STATUS");
939 SerialDebug.println(
" *** main_credentialsUpdated .. setDoneWIFI_APModuleFlag **");
949 SerialCall.print(
"onWriteBLEServerCallback: ");
950 SerialCall.println(message);
956 SerialCall.print(
"onStatusMessageBLEServerCallback");
957 SerialCall.print(message);
966 SerialDebug.print(
"onWriteBLEServerCallback_main: ");
967 SerialDebug.println(message);
971 if (strlen(message) == 1)
974 if (strcmp(message,
"#MSG_START")==0)
982 if (strcmp(message,
"#MSG_END")==0)
1004 message = (
char*)
"s";
1008 message = (
char*)
"B";
1012 message = (
char*)
"b";
1032 SerialDebug.printf(
"Perform BLE Command '%s'\n", message);
1034 char cmd = message[0];
1046 SerialDebug.println(
"*********");
1054#define TRY_ASYNC_BLE_PROCESSING
1055#ifdef TRY_ASYNC_BLE_PROCESSING
1070#ifdef USE_BUTTON_MODULE
1072 refreshDelayButtonTouched_ButtonProcessing();
1106 boolean isValid = pairedDevice && strlen(pairedDevice)>0 && strcmp(pairedDevice,
"NONE")!= 0;
1110 isValid = pairedDeviceAddress && strlen(pairedDeviceAddress)>0 && strcmp(pairedDeviceAddress,
"NONE")!= 0;
1111 SerialLots.printf(
"isValidDeviceAddress(%s,%d)\n", pairedDeviceAddress?pairedDeviceAddress:(
char*)
"NULL", isValid);
1113 SerialLots.printf(
"isValidPairedDevice_mainModule(%s,%d)\n", pairedDevice?pairedDevice:(
char*)
"NULL", isValid);
1123 if (pairedDevice && strlen(pairedDevice)>0 && strcmp(pairedDevice,
"NONE")!= 0)
1125 SerialLots.printf(
"getPairedDeviceOrAddress_mainModule(%s)\n", pairedDevice);
1126 return pairedDevice;
1129 if (pairedDeviceAddress && strlen(pairedDeviceAddress)>0 && strcmp(pairedDeviceAddress,
"NONE")!= 0)
1131 SerialLots.printf(
"getPairedDeviceOrAddress_mainModule(%s)\n", pairedDeviceAddress);
1132 return pairedDeviceAddress;
1159 SerialTemp.println(
" **** POWEROFF ***");
1161#ifndef ESP_M5_CAMERA
1162#ifndef M5STICKCPLUS2
1164#ifndef ESP_M5_ATOM_S3
1177 SerialDebug.println(
"CLEANING EPROM PREFERENCES");
1190 SerialDebug.println(
"REBOOTING...");
1216 if (strcmp(credential,
"NONE")==0)
1220 SerialTemp.print(
"main_nextJSONWIFICredential:");
1221 SerialTemp.println(credential);
1226 SerialTemp.print(
"main_nextJSONWIFICredential:");
1236 SerialMin.print(
"main_saveWIFICredentials");
1245 if (strcmp(credential,
"NONE")==0)
1264 SerialMin.println(
"main_cleanSavedWIFICredentials");
1305 SerialDebug.printf(
"main_setScannedDeviceName(%s)\n", deviceName);
1312 SerialDebug.printf(
"main_setScannedGroupName(%s)\n", groupName);
1314 if (groupName && strlen(groupName)>0)
1336void main_updateMQTTInfo(
char *ssid,
char *ssid_password,
char *username,
char *password,
char *guestPassword,
char *deviceName,
char * host,
char * port,
char *locationString)
1338 SerialMin.printf(
"main_updateMQTTInfo(%s,%s,%s,%s,%s, %s, d=%s)\n", ssid?ssid:
"NULL", ssid_password?ssid_password:
"", username?username:
"NULL", password?password:
"NULL", guestPassword?guestPassword:
"NULL", locationString?locationString:
"NULL", deviceName?deviceName:
"NULL");
1360 switch (syncCallCommand)
1376 SerialDebug.println(
"NO BuzzerSensorClass defined");
1419 SerialError.printf(
"ERROR: async call out of range: %d\n", asyncCallCommand);
1424 SerialTemp.printf(
"1.main_dispatchAsyncCommand: %d\n", asyncCallCommand);
1439 SerialError.printf(
"ERROR: async call out of range: %d\n", asyncCallCommand);
1444 SerialTemp.print(
"2.main_dispatchAsyncCommandWithString:");
1445 SerialTemp.print(asyncCallCommand);
1446 SerialTemp.print(
": ");
1455 SerialDebug.println(
"SYNC_REBOOT");
1471 SerialCall.printf(
"invokeAsyncCommands(%d)\n", i);
1476 SerialTemp.print(
"ASYNC_CALL_BLE_CLIENT_PARAMETER: ");
1486 SerialTemp.print(
"ASYNC_CALL_OTA_FILE_UPDATE_PARAMETER: ");
1494 char httpAddress[100];
1502 if (thirdSlash == 3)
1507 hostname[i] = (char)0;
1509 strcpy(httpAddress,a);
1514 SerialTemp.print(
"will performOTAUpdate: ");
1515 SerialTemp.print(hostname);
1516 SerialTemp.print(
" with httpAddress: ");
1517 SerialTemp.println(httpAddress);
1524 SerialDebug.print(
"ASYNC_JSON_MESSAGE_PARAMETER: ");
1536 SerialDebug.print(
"ASYNC_JSON_MQTT_MESSAGE_PARAMETER: ");
1553 SerialDebug.print(
"ASYNC_REST_CALL_MESSAGE_PARAMETER: ");
1555#ifdef USE_REST_MESSAGING
1575 SerialLots.println(
"ASYNC_CALL_OTA_UPDATE");
1580 SerialTemp.println(
"ASYNC_CALL_CLEAN_CREDENTIALS");
1586 SerialTemp.println(
"ASYNC_CALL_CLEAN_EPROM");
1590 SerialLots.println(
"ASYNC_CALL_FEED_COMMAND");
1598 SerialTemp.println(
"ASYNC_SEND_MQTT_FEED_MESSAGE");
1600 SerialCall.println(
"async_send_feed.1");
1608 char pubString[100];
1610 boolean isPaired = paired && strlen(paired)>0;
1612 SerialTemp.printf(
"Paired = %s\n", paired?paired:(
char*)
"none");
1621 strcat(pubString,
",'cmd':'feed'}");
1641 SerialTemp.println(
" *** NO BLE connected so send wifi ASYNC_SEND_MQTT_FEED_MESSAGE");
1646 SerialCall.println(
"async_send_feed.2");
1672 SerialTemp.println(
"ASYNC_CLICK_SOUND");
1684 SerialDebug.printf(
"ASYNC_CALL_BUZZ %d\n",isBuzzOn);
1688 cmdToSend =
"{'cmd':'buzzon'}";
1693 cmdToSend =
"{'cmd':'buzzoff'}";
1704 SerialLots.println(
"async_call_buzz_on/off -- not BLE connected.. send MQTT");
1720 SerialLots.println(
"async_call_buzz_on -- not BLE connected.. send MQTT");
1727 SerialLots.println(
"async_call_buzz_on -- YES BLE connected.. send BLE");
1739 SerialLots.println(
"ASYNC_SET_GATEWAY_ON");
1745 SerialLots.println(
"ASYNC_SET_GATEWAY_OFF");
1751 SerialDebug.println(
"ASYNC_REBOOT");
1757 SerialDebug.println(
"ASYNC_POWEROFF");
1762 SerialDebug.println(
"ASYNC_BLANKSCREEN");
1774 SerialDebug.print(
" ASYNC_SEND_MQTT_STATUS_URL: ");
1775 SerialDebug.println(statusURL);
1779#ifdef M5BUTTON_MODULE
1783 statusM5ButtonModule();
1808 SerialLots.printf(
"NO COMMAND: %s", i);
1816#ifdef M5BUTTON_MODULE
1817 SerialDebug.println(
"changeButtonColor_MainModule");
1833 for (
int i = 0; i < 17; i = i + 8) {
1858 switch (thresholdKind)
1871 switch (thresholdKind)
1886#define GROUP_TOPIC_TO_SEND (char*)"usersP/groups"
1926 SerialLots.println(
"solidLightMessageCallback..");
1931 boolean lightOn =
true;
1932 lightOn = strstr(&message[0],
_ON_LIGHT);
1976 SerialLots.println(
"solidLight..");
1979 boolean lightOn = onOff;
1990 SerialDebug.println(
" ** #define Module Configuration **");
1991 SerialDebug.println(PARTITION_SCHEME);
1992 SerialDebug.printf(
"M5Stack Version = %s\n", (
char*)M5STACK_VERSION);
1994 SerialDebug.println(
" ** BUILDS **");
1998 SerialMin.println(
"[x] ESP_M5");
2000 SerialMin.println(
"[ ] ESP_M5");
2004 SerialMin.println(
"[x] ESP_M5_CAMERA");
2006 SerialMin.println(
"[ ] ESP_M5_CAMERA");
2010 SerialMin.println(
"[x] ESP_32");
2012 SerialMin.println(
"[ ] ESP_32");
2014#ifdef M5CORE2_MODULE
2016 SerialMin.println(F(
"[x] M5CORE2_MODULE"));
2018 SerialMin.println(F(
"[ ] M5CORE2_MODULE"));
2021#ifdef ESP_M5_SMART_CLICKER_CONFIGURATION
2022 SerialMin.println(F(
"[x] ESP_M5_SMART_CLICKER_CONFIGURATION"));
2024 SerialMin.println(F(
"[ ] ESP_M5_SMART_CLICKER_CONFIGURATION"));
2026#ifdef ESP_M5_ATOM_LITE
2027 SerialMin.println(F(
"[x] ESP_M5_ATOM_LITE"));
2029 SerialMin.println(F(
"[ ] ESP_M5_ATOM_LITE"));
2032 SerialDebug.println(F(
" ** MQTT BLE NETWORKING **"));
2036 SerialMin.println(
"[x] USE_MQTT_NETWORKING");
2040 SerialMin.println(
"[x] USE_BLE_SERVER_NETWORKING");
2044 SerialMin.println(F(
"[x] USE_BLE_CLIENT_NETWORKING"));
2049 SerialMin.println(F(
"[x] USE_WIFI_AP_MODULE"));
2052#ifdef USE_BUTTON_MODULE
2054 SerialMin.println(
"[x] USE_BUTTON_MODULE");
2056 SerialMin.println(
"[ ] USE_BUTTON_MODULE");
2059#ifdef M5BUTTON_MODULE
2061 SerialMin.println(
"[x] M5BUTTON_MODULE");
2063 SerialMin.println(
"[ ] M5BUTTON_MODULE");
2067#ifdef USE_STEPPER_MODULE
2068 SerialMin.println(
"[x] USE_STEPPER_MODULE");
2070 SerialMin.println(
"[ ] USE_STEPPER_MODULE");
2074 SerialMin.println(
"[x] USE_UI_MODULE");
2076 SerialMin.println(
"[ ] USE_UI_MODULE");
2079#ifdef USE_DISPLAY_MODULE
2080 SerialMin.println(
"[x] USE_DISPLAY_MODULE");
2082 SerialMin.println(
"[ ] USE_DISPLAY_MODULE");
2086 SerialMin.println(F(
"[x] BOARD"));
2088 SerialMin.println(F(
"[ ] BOARD"));
2090#ifdef USE_SPIFF_MODULE
2093 SerialMin.println(
"[ ] USE_SPIFF_MODULE");
2095#ifdef USE_SPIFF_MQTT_SETTING
2098#ifdef USE_SPIFF_QRATOM_SETTING
2103 SerialMin.println(F(
"[x] USE_FAST_LED"));
2105 SerialMin.println(F(
"[ ] USE_FAST_LED"));
2107#ifdef KEY_UNIT_SENSOR_CLASS
2108 SerialMin.println(F(
"[x] KEY_UNIT_SENSOR_CLASS"));
2110 SerialMin.println(F(
"[ ] KEY_UNIT_SENSOR_CLASS"));
2112#ifdef USE_LED_BREATH
2113 SerialMin.println(F(
"[x] USE_LED_BREATH"));
2115 SerialMin.println(F(
"[ ] USE_LED_BREATH"));
2118#if (SERIAL_DEBUG_ERROR)
2119 SerialMin.println(F(
"[x] SERIAL_DEBUG_ERROR"));
2121#if (SERIAL_DEBUG_DEBUG)
2122 SerialMin.println(F(
"[x] SERIAL_DEBUG_DEBUG"));
2124#if (SERIAL_DEBUG_INFO)
2125 SerialMin.println(F(
"[x] SERIAL_DEBUG_INFO"));
2127#if (SERIAL_DEBUG_MINIMAL)
2128 SerialMin.println(F(
"[x] SERIAL_DEBUG_MINIMAL"));
2140 return strdup(stringA);
2150 return strdup(stringA);
2162 else if (strlen(stringA) == 0)
2173 if (!str)
return false;
2176 while (i < strlen(str))
2193 float batVoltage = 1;
2194 float batPercentage = 100;
2196#ifndef M5STICKCPLUS2
2200#elif defined(M5CORE2_MODULE)
2202 batVoltage = M5.Axp.GetBatVoltage();
2203 batPercentage = (batVoltage < 3.2) ? 0 : ( batVoltage - 3.2 ) * 100;
2205 batVoltage = M5.Axp.GetBatVoltage();
2206 batPercentage = (batVoltage < 3.2) ? 0 : ( batVoltage - 3.2 ) * 100;
2210 uint16_t vbatData = M5.Axp.GetVbatData();
2211 double vbat = vbatData * 1.1 / 1000;
2212 batPercentage = 100.0 * ((vbat - 3.0) / (4.07 - 3.0));
2217 if (batPercentage > 100.0)
2218 batPercentage = 100.0;
2219 return batPercentage;
2233 SerialDebug.printf(
"sendMessageStringTopic_mainModule(%s) - topic=%s\n", messageString, topicString);
2234 if (strlen(messageString) > 0 && messageString[0] ==
'{')
2258#ifndef M5STICKCPLUS2
2259 M5.IMU.getTempData(&temperature);
2263#ifdef USER_THE_MAX_TEMP_FEATURE
2265 if (temperature > maxtemp)
2275 SerialTemp.println(
" *** This would poweroff .. but you can send message");
2282 float temperature = 10.0;
2284 return temperature ;
2328#pragma mark USE_NEW_M5ATOMCLASS
2334#ifdef M5CORE2_MODULE
2340 return (
char*)
"'tbd':'x'";
2352 sprintf(buf,
"&%s=%s", key, val);
2380#ifdef OVERLOADS_TIME_T
2408#ifdef NO_MORE_PREFERENCE_BLE_USE_DISCOVERED_PAIRED_DEVICE_SETTING
2448 sprintf(
_fullStatusString,
"status?T=%d&v=%s&dev=%s",time, VERSION_SHORT, deviceName);
2451#pragma mark USE_NEW_M5ATOMCLASS
2472void main_setStatusJSON(
const char* JSONString)
2477void main_setStatusKeyValue(
const char* key,
const char* value)
2511 SerialDebug.printf(
"factoryMotorClockwise = %d, isClockwiseFlag = %d\n",factoryMotorClockwise, isClockwiseFlag);
2513 if (factoryMotorClockwise && isClockwiseFlag)
2515 SerialDebug.println(
"setClockwiseMotorDirection -- same so no change");
2517 else if (factoryMotorClockwise && !isClockwiseFlag)
2520 isClockwiseFlag = !isClockwiseFlag;
2524 else if (!factoryMotorClockwise && isClockwiseFlag)
2527 isClockwiseFlag = !isClockwiseFlag;
2531 else if (!factoryMotorClockwise && !isClockwiseFlag)
2533 SerialDebug.println(
"setClockwiseMotorDirection -- same so no change");
2546 boolean sendToStepperModule =
false;
2547 SerialDebug.printf(
"***** processClientCommand_mainModule(%c) from client*****\n", cmd);
2559 sendToStepperModule =
true;
2564 SerialDebug.println(
"cmd=a startTimer");
2572 SerialDebug.println(
"cmd=A stopTimer");
2580 sendToStepperModule =
true;
2581 SerialLots.println(
"Setting FeedState = JACKPOT_FEED");
2587 SerialDebug.println(
"Setting feederType = UNO");
2600 SerialDebug.println(
"Setting feederType = MINI");
2611 SerialDebug.println(
"Setting feederType = Tumbler");
2626 SerialDebug.println(
"Toggle Buzzer via BLE: 'F'");
2633#ifdef LOCAL_NOT_REMOTE
2644 SerialDebug.println(
"Toggle remove Buzzer via BLE: 'f'");
2648 SerialDebug.printf(
"connectedBLEDeviceName = %s\n", connectedBLEDeviceName);
2650 if (connectedBLEDeviceName)
2652 SerialDebug.printf(
"Call Toggle Buzzer via BLE: 'F' - dev=%s\n", connectedBLEDeviceName);
2661 sendToStepperModule =
true;
2662 SerialDebug.println(
"Setting buzzStatus = BUZZON");
2675 sendToStepperModule =
true;
2677 SerialDebug.println(
"Setting buzzStatus = BUZZOFF");
2682 SerialDebug.println(
"*** Setting tilt = ON");
2687 SerialDebug.println(
"Setting tilt = OFF");
2692 SerialDebug.println(
"Clean Credentials");
2697#ifdef NOT_SUPPORTED_RIGHT_NOW
2700 SerialDebug.println(
"OTA Update.. ");
2707 SerialDebug.println(
"Clean EPROM.. ");
2713 SerialDebug.println(
"Clean SSID from EPROM.. ");
2714 char cleanWIFI[100];
2715 strcpy(cleanWIFI,
"{'ssid':'','ssidPassword':''}");
2716 SerialDebug.println(cleanWIFI);
2726 SerialDebug.println(
"Setting Gateway = ON");
2731 SerialDebug.println(
"Setting Gateway = OFF");
2737 SerialDebug.println(
"unused cmd '_'");
2739#ifdef OLD_FOR_M5_DISPLAY
2742 sendToStepperModule =
false;
2744 SerialDebug.println(
"Setting SM Zoom = zoomed");
2749 sendToStepperModule =
false;
2751 SerialDebug.println(
"Setting SM Zoom = full SM");
2761 SerialDebug.println(
"clean SPIFF file");
2768 SerialDebug.println(
"upload SPIFF to web");
2785 spiffFlag = !spiffFlag;
2787 SerialDebug.printf(
"Changing current USE_SPIFF = %s\n", spiffFlag?
"NOYES":
"NO");
2815 SerialDebug.println(
"w for swapWifi");
2823 SerialDebug.printf(
"PREFERENCE_STEPPER_AUTO_MOTOR_DIRECTION_SETTING true");
2833 SerialDebug.printf(
"PREFERENCE_STEPPER_AUTO_MOTOR_DIRECTION_SETTING false");
2840 SerialDebug.printf(
"PREFERENCE_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING counter clockwise");
2848 SerialDebug.printf(
"PREFERENCE_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING clockwise");
2856 SerialDebug.printf(
"PREFERENCE_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING reverse direction");
2861 currentDirection = !currentDirection;
2867 SerialDebug.printf(
"PREFERENCE_BLE_SERVER_USE_DEVICE_NAME_SETTING false");
2876 SerialDebug.printf(
"PREFERENCE_BLE_SERVER_USE_DEVICE_NAME_SETTING true");
2886 SerialDebug.println(
"REBOOT ...");
2893 SerialDebug.printf(
"(%c) POWEROFF ...", cmd);
2901 SerialDebug.println(
"Clearing Sensors");
2939 SerialDebug.println(
" *** performing m5atom OTA Update");
2942 performOTAUpdate((
char*)
"http://KnowledgeShark.org", (
char*)
"OTA/TEST/M5Atom/ESP_IOT.ino.m5stick_c_plus.bin");
2947 SerialDebug.println(
" *** performing m5atom OTA Update - DAILY");
2950 performOTAUpdate((
char*)
"http://KnowledgeShark.org", (
char*)
"OTA/TEST/M5Atom/daily/ESP_IOT.ino.m5stick_c_plus.bin");
2954 SerialDebug.println(
" *** performing m5atom OTA Update - BOOTSTRAP");
2957 performOTAUpdate((
char*)
"http://KnowledgeShark.org", (
char*)
"OTA/Bootstrap/ESP_M5_BOOTSTRAP.ino.m5stack_stickc_plus.bin");
2976 SerialDebug.println(
" *** performing m5atom OTA Update - M5Clicker");
2979 performOTAUpdate((
char*)
"http://KnowledgeShark.org", (
char*)
"OTA/Bootstrap/ESP_M5_BOOTSTRAP.ino.m5stack_stickc_plus.bin");
2984 SerialDebug.println(
"'C' change color touched");
2994 char sendCapture[100];
2995 strcpy(sendCapture,
"{'send':'capture'}");
2996 SerialDebug.println(sendCapture);
3012 SerialMin.println(
"Valid Commands: ");
3013 SerialMin.println(
" . = help, this message");
3014 SerialMin.println(
" p = poweroff if can");
3015 SerialMin.println(
" 0x0, s, c == Single Feed - via BLE to connected device");
3016 SerialMin.println(
" a == AutoFeed On");
3017 SerialMin.println(
" A == AutoFeed Off");
3018 SerialMin.println(
" u == UNO ");
3019 SerialMin.println(
" m == MINI ");
3020 SerialMin.println(
" L == tumbler");
3021 SerialMin.println(
" H == autoMotorDirection on");
3022 SerialMin.println(
" h == autoMotorDirection off");
3023 SerialMin.println(
" D == FACTORY counter clockwise motor direction");
3024 SerialMin.println(
" d == FACTORY clockwise motor direction");
3025 SerialMin.println(
" Q == change motor direction opposite of current");
3028 SerialMin.println(
" F == Toggle Buzzer on/off");
3030 SerialMin.println(
" f == Toggle Buzzer on/off on BLE connected device");
3032 SerialMin.println(
" B == Buzzer On");
3033 SerialMin.println(
" b == Buzzer Off");
3034 SerialMin.println(
" G == Gateway On");
3035 SerialMin.println(
" g == Gateway Off");
3036 SerialMin.println(
" R == clean credentials");
3037 SerialMin.println(
" X == clean EPROM");
3038 SerialMin.println(
" x == clean SSID from EPROM");
3039 SerialMin.println(
" r == reboot ");
3042 SerialMin.println(
" T == tiltOn");
3043 SerialMin.println(
" t == tiltOff");
3044 SerialMin.println(
" N == send WIFI Credential to BLEServer");
3045 SerialMin.println(
" n == next WIFI Credential");
3046 SerialMin.println(
" W == retry WIFI");
3047 SerialMin.println(
" w == swap WIFI");
3048 SerialMin.println(
" C == change m5 atom to random color");
3049 SerialMin.println(
" i == take pic, {send:capture}");
3051 SerialMin.println(
" SPIFF internal memory ");
3052#ifndef OLD_FOR_M5_DISPLAY
3053 SerialMin.println(
" Z == clean SPIFF file");
3054 SerialMin.println(
" z == upload SPIFF to web");
3056 SerialMin.println(
" P == print SPIFF");
3057 SerialMin.printf (
" S == toggle SPIFF %s\n", spiffFlag?
"OFF":
"ON");
3059 SerialMin.println(
" BLE Naming ");
3061 SerialMin.println(
" E == use only PTFeeder naming");
3062 SerialMin.println(
" e == use naming PTFeeder:name");
3063#ifdef OLD_FOR_M5_DISPLAY
3064 SerialMin.println(
" Z == Setting SM Zoom = zoomed");
3065 SerialMin.println(
" z == Setting SM Zoom = full SM");
3067 SerialMin.println(
" Configurations of M5Atom ");
3069 SerialMin.println(
" k == no sensors");
3070 SerialMin.println(
" 1 == L9100S_DCStepper (current main)");
3072 SerialMin.println(
" 2 == ChainSensors (12.21.25))");
3073 SerialMin.println(
" 3 == *** PTStepperClass (original code - with M5");
3074 SerialMin.printf (
" 4 == M5AtomCamera\n");
3075 SerialMin.println(
" 8 == SMART Button, Clicker");
3076 SerialMin.println(
" 9 == M5TinyGPS, Clicker");
3077 SerialMin.println(
" 0 == M5AtomScanner, Clicker");
3080#ifdef NOT_SUPPORTED_RIGHT_NOW
3081 SerialMin.println(
" O == OTA update");
3083 SerialMin.println(
" OTA Updates of M5Atom ");
3084 SerialMin.println(
" 5 == m5atom DEV OTA update");
3085 SerialMin.println(
" 6 == m5atom DAILY TEST DEV OTA update");
3086 SerialMin.println(
" 7 == go back to m5atom BOOTSTRAP");
3089 SerialMin.println();
3090 SerialMin.println(
"Full API at: https://github.com/konacurrents/SemanticMarkerAPI");
3091 SerialMin.println();
3101 SerialMin.printf(
"*****invalid command '%c' from client (use '.' for help) *****\n", cmd);
3105#ifdef USE_STEPPER_MODULE
3106 if (sendToStepperModule)
3119 SerialDebug.printf(
"setConfiguration: %s\n", configurationName);
3121 if (strcmp(configurationName,
"PTStepper")==0)
3124 SerialDebug.println(
"Default PTStepperClass");
3128#ifdef DONT_ADD_TO_SENSORS
3161#pragma mark CHAIN BUTTON
3164 else if (strcmp(configurationName,
"ChainButtonClass")==0)
3167 SerialDebug.println(
"Default ChainButtonClass **** NEED WORK ****");
3182 savePreference_mainModule(
PREFERENCE_CHAIN_SENSORS_SETTING,
"ChainButtonClass,1,0,SM_MatrixCell,8,$all,ButtonClass,1,1,feed,,$pair,JoystickClass,2,0,feed,,$localhost");
3207 else if (strcmp(configurationName,
"ULN2003_StepperClass")==0)
3216 SerialDebug.println(
"Default ULN2003_StepperClass");
3240 else if (strcmp(configurationName,
"M5AtomCamera")==0)
3243 SerialDebug.println(
"Default M5AtomCamera");
3263 else if (strcmp(configurationName,
"M5TinyGPS")==0)
3266 SerialDebug.println(
"Default M5AtomTinyGPS");
3286 else if (strcmp(configurationName,
"M5AtomScanner")==0)
3289 SerialDebug.println(
"Default M5AtomScanner");
3309 else if (strcmp(configurationName,
"M5NoModule")==0)
3312 SerialDebug.println(
"Default M5AtomNoModule");
3334 SerialDebug.printf(
" **** Unknown Configuration: %s\n", configurationName);
3351 SerialMin.printf(
"Unix Time: %d\n", now);
3363 if (strncmp(cmd,
"sm",2) == 0)
3366 char *p = strchr(cmd,
'm');
3372 SerialLots.print(
"whichSMMode: ");
3373 SerialLots.print(cmd);
3374 SerialLots.print(
" => " );
3375 SerialLots.println(num);
3388 return (strcasecmp(cmd,mode)==0);
3394 SerialLots.printf(
"charSMMode_mainModule: %d\n", whichSMMode);
3434 SerialLots.print(
"setCurrentSMMode_mainModule:");
3435 SerialLots.println(whichSMMode);
3460 SerialTemp.print(
"incrementSMMode_mainModule:");
3500 SerialTemp.printf(
"auto-settingGateway(%d)\n", isGEN3);
3507 SerialCall.printf(
"setConnectedBLEDevice_mainModule: %s\n", deviceName);
3513 char *colon = index(deviceName,
':');
3515 colon = index(colon,
':');
3519 while (*colon && *colon !=
',')
3532 SerialTemp.print(
"connectedBLEName= ");
3537 seems to be crashing..
3539 char connectMessage[300];
3541 SerialTemp.println(connectMessage);
3557 colon += strlen(
"Address:");
3559 while (*colon && *colon ==
' ')
3564 while (*colon && *colon !=
',')
3577 SerialTemp.print(
"_connectedBLEDeviceAddress= ");
3591 nameToUse = (
char*)
"";
3631#ifdef USE_BUTTON_MODULE
3633 loop_ButtonProcessing();
3637#ifdef M5CORE2_MODULE
3639#elif defined(M5_ATOM)
3641#pragma mark USE_NEW_M5ATOMCLASS
3650 SerialDebug.println(
"*** _whichM5AtomClassType NULL ***");
3656#elif defined(M5BUTTON_MODULE)
3657 loop_M5ButtonModule();
3664 SerialDebug.println(
"setup_Sensors_mainModule");
3665#ifdef USE_BUTTON_MODULE
3667 setup_ButtonProcessing();
3671 SerialDebug.println(
" ***** M5_ATOM define ****");
3673#ifdef M5CORE2_MODULE
3679#pragma mark M5AtomClassType
3682#ifdef USE_NEW_M5ATOMCLASS
3695 int whichM5AtomIndex = 0;
3696 SerialDebug.println(
"setup_M5Atoms");
3713 SerialDebug.printf(
"**** sensors are more than max .. FIX CODE");
3715 SerialDebug.printf(
"Created %d M5AtomClassTypes\n", whichM5AtomIndex);
3727 SerialDebug.println(
"NULL M5AtomClassType");
3740 SerialDebug.printf(
"** Found M5AtomClass = %s\n", atomKind);
3744 SerialDebug.printf(
"****^^^ Cannot find M5AtomClass = %s\n", atomKind);
3746 SerialDebug.println(
"Defaulting to _M5Atom_HDriverModuleClass");
3754#pragma mark USE_NEW_M5ATOMCLASS
3761#elif defined(M5BUTTON_MODULE)
3762 setup_M5ButtonModule();
3769#ifdef USE_BUTTON_MODULE
3770 buttonA_ShortPress();
3772#ifdef M5CORE2_MODULE
3774#elif defined(M5_ATOM)
3775#pragma mark USE_NEW_M5ATOMCLASS
3779 SerialDebug.println(
"buttonA_ShortPress_mainModule");
3783#elif defined(M5BUTTON_MODULE)
3784 buttonA_ShortPress_M5ButtonModule();
3792#ifdef USE_BUTTON_MODULE
3793 buttonA_LongPress();
3795#ifdef M5CORE2_MODULE
3797#elif defined(M5_ATOM)
3799#pragma mark USE_NEW_M5ATOMCLASS
3803 SerialDebug.println(
"buttonA_LongPress_mainModule");
3807#elif defined(M5BUTTON_MODULE)
3808 buttonA_LongPress_M5ButtonModule();
3816#ifdef USE_BUTTON_MODULE
3817 buttonA_LongLongPress();
3819#ifdef M5CORE2_MODULE
3820 buttonA_LongLongPress_M5Core2Module();
3821#elif defined(M5_ATOM)
3823#pragma mark USE_NEW_M5ATOMCLASS
3827 SerialDebug.println(
"buttonA_LongLongPress_mainModule");
3831#elif defined(M5BUTTON_MODULE)
3832 buttonA_LongLongPress_M5ButtonModule();
3840#ifdef USE_BUTTON_MODULE
3841 buttonB_LongPress();
3843#ifdef M5BUTTON_MODULE
3845 buttonB_LongPress_M5ButtonModule();
3851#ifdef USE_BUTTON_MODULE
3852 buttonB_ShortPress();
3855#ifdef M5BUTTON_MODULE
3857 buttonB_ShortPress_M5ButtonModule();
3860#pragma mark BUTTON Processing of M5
3872 if (M5.BtnA.wasReleasefor(4500))
3875 SerialDebug.println(
"MainModule **** LONG LONG PRESS ***");
3878 else if (M5.BtnA.wasReleasefor(1000))
3881 SerialDebug.println(
"MainModule **** LONG PRESS ***");
3884 else if (M5.BtnA.wasReleased())
3887 SerialDebug.println(
"MainModule **** SHORT PRESS ***");
3902 if (M5.BtnB.wasReleasefor(4500))
3905 SerialDebug.println(
"MainModule **** LONG LONG PRESS ***");
3908 else if (M5.BtnB.wasReleasefor(1000))
3911 SerialDebug.println(
"MainModule **** LONG PRESS ***");
3914 else if (M5.BtnB.wasReleased())
3917 SerialDebug.println(
"MainModule **** SHORT PRESS ***");
3950#pragma mark PIN_USE_STRUCT
3951#pragma mark PIN USE to see if overlaps.
3958 char *pinUseArray[PIN_USE_MAX];
3960 long pinNumArray[PIN_USE_MAX];
3982 char pinUseSample[100];
3983 sprintf(pinUseSample,
"PIN_USE: %2d = %s, %s %s", pin, pinName.c_str(), moduleName.c_str(), isI2C?
"(I2C)":
"");
3985 char *pinUse = (
char*)calloc(strlen(pinUseSample)+1,
sizeof(char));
3986 strcpy(pinUse, pinUseSample);
3997 SerialError.printf(
"*** ERROR .. too many PINS defined ***");
4002 SerialDebug.printf(
"** PIN_USE: %s = %d, module=%s %s\n", pinName.c_str(), pin, moduleName.c_str(), isI2C?
"(I2C)":
"");
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)
#define BLE_SERVER_CALLBACK_ONWRITE
void addToTextMessages_displayModule(String text)
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 setup_M5Core2Module()
void loop_M5Core2Module()
called for the loop() of this plugin
char * currentStatusJSON_M5Core2Module()
void messageSend_M5Core2Module(char *sendValue)
void messageSetVal_M5Core2Module(char *setName, char *valValue, boolean deviceNameSpecified)
void buttonA_ShortPress_M5Core2Module()
CRGB getRandomColor()
7.24.25 return a (semi) random color
void fillpix(CRGB Color)
color the button light
void publishMQTTMessageDefaultTopic(char *message)
Wrapper of the mqttclient publish.
void cleanEPROM_MQTTNetworking()
cleans the eprom info
void sendMessageNoChangeMQTT_Topic(char *message, char *topic)
just send a message but without any extras
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 sendMessageMQTT_Topic(char *message, char *topic)
for now only send if it start message starts with "#"
void sendDocFollowMessageMQTT(const char *semanticMarker)
sends the semantic marker as a doc follow message
void sendMessageNoChangeMQTT(char *message)
just send a message but without any extras
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
8.16.25 MQTT
void cleanEpromPreferences()
cleans the EPROM
void sendSemanticMarkerDocFollow_mainModule(const char *SMDocFollowAddress)
sends the SM on the DOCFOLLOW channel (publish it..)
M5Atom_NoModuleClass * _M5Atom_NoModuleClass
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)
void messageSend_mainModule(char *sendValue, boolean deviceNameSpecified)
TODO: have a callback regist approach.
boolean _asyncCallOTAUpdateFlag
3.28.22 .. implemented in ESP_IOT.ino
boolean _stopAllProcessing
testing..
M5Atom_Core2ModuleClass * _M5Atom_Core2ModuleClass
char * createCopy2(const char *stringA)
#define CALLBACKS_MQTT
8.16.25 MQTT
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...
ChainButtonClass * _ChainButtonClass
void setConnectedBLEDevice_mainModule(char *deviceName, boolean isGEN3)
char _fullBLEDeviceName[100]
full: ""Name: PTFeeder:HowieFeeder, Address: 7c:9e:bd:48:af:92, serviceUUID: 0xdead"
SensorClassType * _SensorClassTypes[NUM_SENSOR_CLASS_TYPES]
#define CALLBACKS_MAX_BLE_SERVER
KeyUnitSensorClass * _KeyUnitSensorClass
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 * main_getUsername()
#define NUM_SENSOR_CLASS_TYPES
5.14.25
char * groupTopicFullName(char *groupName)
returns a groupTopic to use as a topic
char _smMode_MainModule[10]
current smMode
void loop_mainModule()
called for the loop() of this plugin
char * getSemanticMarkerDocFollow_mainModule()
gets the semanticAddress SemanticMarkerâ„¢
void main_setScannedGroupName(char *groupName)
void registerCallbackMain(int callbacksModuleId, int callbackType, void(*callback)(char *))
register the callback based on the callbackType. use the callbacksModuleId for which one....
M5Atom_HDriverModuleClass * _M5Atom_HDriverModuleClass
char * deviceName_mainModule()
gets the device name
int getLUXThreshold_mainModule(int thresholdKind)
get the threshold val
void dummyCallbackMain(char *message)
example callback
#define CALLBACKS_MAX_MQTT
void initGlobals_mainModule()
init globals strings
void sendStatusMQTT_mainModule()
1.1.24 send status of this device after events..
PinUseStruct _pinUseStruct
7.31.25 add this for a status, saw that QRCode was using 22 also .. so buzer didn't work.
char _deviceNameSave[50]
saved deviceName storage..
void initSensorClassTypeArray()
boolean connectedBLEDeviceIsGEN3_mainModule()
whether the connected is a GEN3 (so the name isn't valid)
boolean _shortPress_MainModule
5.6.25 use the M5Atom ClassType
char * semanticMarkerToJSON_mainModule(char *semanticMarker)
char * main_currentStatusURL(boolean fullStatus)
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 main_setScannedDeviceName(char *deviceName)
set the scanned device name
void processClientCommandChar_mainModule(char cmd)
single character version of processClientCommand (since many used that already)
boolean _longLongPress_MainModule
char _scannedDeviceName[100]
int getFeedCount_mainModule()
feedcount info..
void onStatusMessageBLEServerCallback(char *message)
The callback for "status messages" of the bluetooth.
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
char _scannedGroupTopicName[100]
M5Atom_CameraModuleClass * _M5Atom_CameraModuleClass
void setClockwiseMotorDirection_mainModule(boolean isClockwiseFlag)
8.18.24 setting this will check for the factory setting..
void solidLightOnOff(boolean onOff)
callback for SOLID blinking led
void sendMessageStringTopic_mainModule(char *messageString, char *topicString)
adding a synchronous call to send a message over the network (assuming MQTT but not specified),...
char * main_getScannedGroupNameTopic()
void checkButtonB_MainModule()
big button on front of M5StickC Plus
uint32_t _chipID_MainModule
3.17.24 the unqiue chip id
void main_credentialsUpdated()
moved here 4.25.22 (entirely from ESP_IOT.ino)
void setup_mainModule()
called from the setup()
void loopSensorClassTypeArray()
11.27.25 Turkey Day, loop
void main_dispatchSyncCommand(int syncCallCommand)
the main sync command (no parameters yet)
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
PIRSensorClass * _PIRSensorClass
boolean isTrueString_mainModule(String valCmdString)
whether the string is TRUE, ON, 1
char * main_getPassword()
return password
int whichSMMode_mainModule(char *cmd)
************** SM Mode Processing ***************
M5Atom_SocketModuleClass * _M5Atom_SocketModuleClass
instances of the M5AtomClassType
void main_dispatchAsyncCommandWithString(int asyncCallCommand, char *parameter)
void initAsyncCallFlags()
initialize the async call flags (with and without parameters)
void registerPinUse_mainModule(long pin, String pinName, String moduleName, boolean isI2C)
void solidLightMessageCallback(char *message)
callback for SOLID blinking led
M5AtomClassType * _M5AtomClassTypes[NUM_M5ATOM_CLASS]
3.31.25 create array of plugs
M5AtomClassType * _whichM5AtomClassType
use this one...
boolean isEmptyString(char *stringA)
informs if null or empty string
void rebootDevice_mainModule()
void setConfiguration_mainModule(char *configurationName)
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
#define GROUP_TOPIC_TO_SEND
boolean isPTFeeder_mainModule()
gets if PTFeeder a surrogate for the M5Atom class
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
M5Atom_QRCodeModuleClass * _M5Atom_QRCodeModuleClass
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 _longPress_MainModule
boolean _waitingForBigMessageEnd
store a big message #MSG_START .. #MSG_END
void buttonA_LongLongPress_mainModule()
long long press on buttonA (top button)
void stopMotor_mainModule()
added 9.29.22 to support wildcards #196
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()
status in JSON format, needs to return something as a ',' is already added before calling this....
M5AtomClassType * whichM5AtomClassType()
6.6.25 get the current M5AtomClassType
void(* callbackSignature)(char *)
void changeButtonColor_MainModule()
2.21.25 add a way to change the button color (if any)
void setup_Sensors_mainModule()
1.22.24 setup of buttons
char * getFullBLEDeviceName_mainModule()
full: ""Name: PTFeeder:HowieFeeder, Address: 7c:9e:bd:48:af:92, serviceUUID: 0xdead"
void checkButtonA_MainModule()
big button on front of M5StickC Plus
char _groupTopicName[100]
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)
void showText_mainModule(String text)
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 _chipIdString_MainModule[15]
string like: 10311304
char * getPairedDevice_mainModule()
returns if the paired device is not NONE
void onWriteBLEServerCallback(char *message)
The callback for "onWrite" of the bluetooth "onWrite'.
char * _MQTT_Password
12.14.23
char * getServerServiceName_mainModule()
void setLUXThreshold_mainModule(int thresholdKind, int luxVal)
set the threshold val
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 ....
BuzzerSensorClass * _BuzzerSensorClass
int _saveWhichSMMode
the saved SMMode
PinUseStruct * getPinUseStruct_mainModule()
get the pin use array
char * getChipIdString()
3.17.24 get the chip id as a string
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,...
uint32_t getChipId()
3.17.24 get the chip id
boolean isMinimalMenuMode_mainModule()
returns which mode in (min or expanded)
char _asyncParameter[500]
the parameter being sent to those commands passing an argument
void loop_Sensors_mainModule()
1.22.24 add setup and loop at main so it can call appropriate plugs
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 * main_getScannedDeviceName()
return devicename
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
char _fullStatusString[500]
status string (URL query format)
void main_printModuleConfiguration()
M5Atom_TinyGPSModuleClass * _M5Atom_TinyGPSModuleClass
void messageSetVal_mainModule(char *setName, char *valValue, boolean deviceNameSpecified)
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 messageSetVal_SensorClassTypeArray(char *setName, char *valValue, boolean deviceNameSpecified)
void main_saveWIFICredentials(char *ssid, char *ssid_password)
save the WIFI credential
void readPreferences_mainModule()
reads the preferences. Save is everytime the savePreference is called
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 THRESHOLD_KIND_DARK
#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 unless MQTT
#define ASYNC_REST_CALL_MESSAGE_PARAMETER
send REST call
#define ASYNC_SEND_MQTT_FEED_MESSAGE
sends a message (like FEED) on the users topic
#define CALLBACKS_MODULE_MAX
#define ASYNC_JSON_MQTT_MESSAGE_PARAMETER
these are the async with a string parameter
#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 THRESHOLD_KIND_LIGHT
#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_CLICK_SOUND
5.15.25 add a BUZZ command (or CLICK)
#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)
8.16.25 MQTT
void savePreferenceInt_mainModule(int preferenceID, int val)
sets an int preference
void savePreferenceBoolean_mainModule(int preferenceID, boolean flag)
save a boolean preference
void printSensors_mainModule(SensorsStruct *sensors)
print sensors, passing in a struct
SensorsStruct * getSensors_mainModule()
return the sensors defined
void initChainSensorStringsFromEPROM_mainModule()
void setSensorsString_mainModule(char *sensorsString)
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 registerChain_mainModule(String classType, int buttonNumber, int pressKind, String setString, String valString, String deviceString)
void togglePreferenceBoolean_mainModule(int preferenceID)
toggles a preference boolean
char * getPreferenceATOMKind_MainModule()
new 1.4.24 setting ATOM kind (eg. M5AtomSocket, M5AtomScanner)
void savePreferenceFloat_mainModule(int preferenceID, float val)
called to set a preference (which will be an identifier and a string, which can be converted to a num...
int getM5ATOMKind_MainModule()
new 1.4.24 setting ATOM kind (eg. ATOM_KIND_M5_SCANNER, ATOM_KIND_M5_SOCKET)
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)
SensorStruct * getSensor_mainModule(char *sensorName)
return the sensor specified or null
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_USE_SPIFF_SETTING
8.22.22 to turn on/off SPIFF use (more below..)
#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_SENSOR_PLUGS_SETTING
#define PREFERENCE_STEPPER_FACTORY_CLOCKWISE_MOTOR_DIRECTION_SETTING
#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_STEPPER_RPM_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 PREFERENCE_USE_SPIFF_MQTT_SETTING
#define PREFERENCE_CHAIN_SENSORS_SETTING
#define WIFI_CREDENTIALS_MAX
for now, save 2 WIFI Credentials
#define BUTTON_SHORT_PRESS
#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_USE_SPIFF_QRATOM_SETTING
For MQTT writing to the QRATOM.
#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_STEPPER_ANGLE_FLOAT_SETTING
#define BUTTON_LONG_PRESS
#define PREFERENCE_STEPPER_2FEED_SETTING
#define PREFERENCE_STEPPER_AUTO_MOTOR_DIRECTION_SETTING
#define PREFERENCE_MAIN_GATEWAY_VALUE
#define PREFERENCE_STEPPER_CLOCKWISE_MOTOR_DIRECTION_SETTING
#define PREFERENCE_MAIN_BLE_CLIENT_VALUE
#define PREFERENCE_ATOM_KIND_SETTING
1.4.24 What kind of ATOM plug (set, M5AtomKind, val= {M5AtomSocket, M5AtomScanner}
void sendStrings_SPIFFModule(int numberOfLines)
sends SPIFF module strings over MQTT, starting at the number back specified. This will use the curren...
void printFile_SPIFFModule()
prints the spiff file to the SerialDebug output
void deleteFiles_SPIFFModule()
delete the spiff files..
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 ..
char * semanticMarkerToJSON_TokenParser(char *semanticMarker)
void blinkLED_UIModule()
blink the LED
void solidLightOnOff_UIModule(boolean onOff)
turns on/off a solid light
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
void setup()
Pure Virtual Function.
virtual void messageSend_M5AtomClassType(char *sendValue, boolean deviceNameSpecified)=0
virtual void loop_M5AtomClassType()=0
loop the PTStepper (so timer can run)
virtual boolean isPTFeeder_M5AtomClassType()
virtual void buttonA_ShortPress_M5AtomClassType()=0
virtual char * currentStatusJSON_M5AtomClassType()=0
virtual void buttonA_LongPress_M5AtomClassType()=0
long press on buttonA (top button)
virtual void messageSetVal_M5AtomClassType(char *setName, char *valValue, boolean deviceNameSpecified)=0
these are from the ATOM
virtual void setup_M5AtomClassType()=0
setup the PTStepper
virtual void stop_M5AtomClassType()=0
stop the motor
virtual char * currentStatusURL_M5AtomClassType()=0
virtual void buttonA_LongLongPress_M5AtomClassType()
11.25.25 Add LONG LONG press for the AP mode
void setup()
Pure Virtual Function.
virtual void loop()=0
Pure Virtual Function.
virtual Type type() const
void setPinValues(int pin1, int pin2)
virtual void messageSetVal_SensorClassType(char *setName, char *valValue, boolean deviceNameSpecified)
virtual void setup()=0
Pure Virtual Function.
virtual void messageLocal_SensorClassType(char *message)
5.15.25 try a special command local to this class
long pinNumArray[PIN_USE_MAX]
each pin
char * pinUseArray[PIN_USE_MAX]
string describing the module, etc
SensorClassType * sensorClassType
and the pointer to matching SensorClassType
SensorStruct * sensors
array of sensorStruct