ESP_IOT v2.5
IOT ESP Coding
|
#include "../../Defines.h"
#include "MQTTNetworking.h"
#include "OTAImageUpdate.h"
#include <ArduinoJson.h>
#include <Preferences.h>
#include <WiFi.h>
#include <PubSubClient.h>
Go to the source code of this file.
Macros | |
#define | ESP_EPROM_NAME "ESP32" |
Ambers 22nd birthday.. 2.20.22. More... | |
#define | MAXglobalMQTTAttempts 10 |
#define | MAX_MQTT_ATTEMPTS 10 |
#define | MAX_WIFI_CONNECT_ATTEMPTS 30 |
#define | OTA "#OTA" |
#define | STATUS "#STATUS" |
#define | REMOTE "#remoteMe" |
#define | REMOTE2 "#REMOTE" |
#define | FEED "#FEED" |
#define | FEED_2 "#feedme" |
#define | ACK_FEED "#actMe" |
#define | ACK_FEED2 "#ackMe" |
#define | CONNECTED "#connectedMe" |
#define | NOT_CONNECTED "#noconnectedMe" |
#define | NO_ACK_FEED "#noactMe" |
#define | PLAY_ME "#playMe" |
#define | DOCFOLLOW "#docFollow" |
#define | DOCFOLLOW2 "#DOCFOLLOW" |
#define | DOCSYNC "#docSync" |
#define | NO_CAN "#NO_CAN" |
#define | FOLLOW_ME "#followMe" |
#define | MAX_MESSAGE 600 |
define this storage once, and use everwhere.. More... | |
#define | _preferencesJSONName "JSONPrefs" |
Points to strings read from JSON (limited to 15 char key name) More... | |
#define | TRY_MORE_ASYNC_PROCESSING |
#define | WIFI_MQTT_STATES |
4.26.22 50 year anniverssery of Grateful Dead in Frankfurt 1972 More... | |
#define | SINGLE_DELAY |
a call to see if the WIFI is connected More... | |
#define | ACK_FOR_PAIR_TOO |
#define | NO_NEED_AND_GRU_CRASH |
Enumerations | |
enum | WIFI_MQTTStates { preSetupWIFI , waitingForWIFI , preSetupMQTT , waitingForMQTT , connectedWIFI , connectedMQTT , disconnectedWIFI , disconnectedMQTT } |
state variables More... | |
enum | MQTTMessageTopicType { userTopic , dawgpackTopic , superTopic } |
break up the MQTT Handler 8.12.22 as per "My guess is that you have your data collection (from some I2C device) and data delivery intermingled. Separate them so that you have the data in hand before you make the network connection. That will reduce the possibility of timeouts and race conditions. It also makes it easier to add new collection and delivery processes. The more asynchronous you can make these steps, the more robust your application will be overall." More... | |
Functions | |
void | updatePreferencesInEPROM () |
just update the EPROM, and send that to the WIFI_AP module as well More... | |
void | setupWIFI (char *arg_ssid, char *arg_password) |
setup the WIFI using ssid and password More... | |
void | processBarkletMessage (String message, String topic) |
process an MQTT message looking for keywords (barklet language) More... | |
void | setupMQTT (char *mqttServerString, char *mqttPortString, char *mqttPasswordString, char *mqttUserString, char *deviceNameString, char *uuidString) |
setup the MQTT server More... | |
boolean | processJSONMessageMQTT (char *ascii, char *topic) |
process the JSON message (looking for FEED, etc). Note: topic can be nil, or if not, it's an MQTT topic (so send replies if you want) More... | |
void | checkMQTTMessages_loop () |
check for MQTT messages, called from the main loop() More... | |
void | blinkBlueLightMQTT () |
blinks the blue light More... | |
void | callPreSetupMQTT () |
called to setup the MQTT (which is really the _mqttClient setup). Done on it's own thread.. More... | |
void | MQTTModule_readPreferences () |
setup the WIFI More... | |
PubSubClient | _mqttClient (_espClient) |
The PubSub MQTT Client. More... | |
void | performOTAUpdateMethod () |
perform the OTA update. This calls the OTAImageUpdate methods (via preformOTAUpdateSimple()) More... | |
void | cleanSSID_EPROM_Method () |
calls the method for cleaning the SSID eprom. This calls the WIFI_APModule callback More... | |
void | performFeedMethod (char *topic) |
calls the FEED message via the callback (which calls the BLE code) More... | |
int | getUptime () |
returns seconds since first booted More... | |
boolean | skipMessageProcessing () |
this is sent from the backend as a message {'guest':'guest password'} .. but lets' add to the credentials.. More... | |
void | publishMQTTMessage (char *topic, char *message) |
Wrapper of the mqttclient publish. NOTE: this might need to be in the loop as well, as the BLE could be the way the message arrived, and we are sending out over MQTT (while in the BLE thread). Don't know?? More... | |
void | publishMQTTMessageDefaultTopic (char *message) |
Wrapper of the mqttclient publish. More... | |
void | publishBinaryFile (char *topic, uint8_t *buf, size_t len) |
publish a binary file.. More... | |
String | getJSONConfigString () |
retrieve the Configuration JSON string in JSON format.. More... | |
char * | getDeviceNameMQTT () |
called for things like the advertisement More... | |
void | getChipInfo () |
create a unique ID (but it needs to be stored.. otherwise it's unique each time?? More... | |
const char * | getDynamicStatusFunc () |
char * | getLastDocFollowSemanticMarker_MQTTNetworking () |
void | setLastDocFollowSemanticMarker_MQTTNetworking (char *semanticMarker) |
sets the last DocFollow SemanticMarker More... | |
void | initAllArrayStorage () |
Put all the storage initialization here.. More... | |
void | setLastMessageStatus (char *token) |
void | emptyLastMessageStatus () |
empty the status message More... | |
char * | currentMessageStatusURL () |
returns a string in in URL so: status?battery=84'&buzzon='off' } .. etc More... | |
const char * | getDynamicMessageFunc () |
used by the displayModule to call this for each new status More... | |
void | setupWIFI_loop () |
the loop part of WIFI More... | |
void | finishWIFI_Setup () |
end of WIFI loop.. More... | |
void | reconnectMQTT_loop () |
void | startDelay_WIFI_MQTTState () |
init the delay, this uses the array of delays so we can change easier.. More... | |
boolean | delayFinished_WIFI_MQTTState () |
if finished.. More... | |
void | stopDelay_WIFI_MQTTState () |
stop the delay More... | |
void | setup_MQTTNetworking () |
setup the MQTT part of networking More... | |
boolean | isConnectedWIFI_MQTTState () |
value of WIFI connected More... | |
boolean | isConnectedMQTT_MQTTState () |
value of MQTT connected More... | |
void | loop_MQTTNetworking () |
called for the loop() of this plugin More... | |
char * | wifiStatus_MQTT () |
show the status in string form (from Library/Adruino... WiFiType.h) More... | |
void | startDelayCheckWIFI_MQTTNetworking (int seconds) |
init the delay More... | |
int | getDelayCheckWIFISeconds_MQTTNetworking () |
get the delay values More... | |
void | restartDelayCheckWIFI_MQTTNetworking () |
starts the delay for WIFI checking, called at startup, and each time the timer finished.. More... | |
boolean | delayCheckWIFIFinished_MQTTNetworking () |
if finished.. More... | |
void | stopDelayCheckWIFI_MQTTNetworking () |
stop the delay (not called) More... | |
void | checkDelaySinceWIFICheck_MQTTNetworking () |
checks delay for the WIFI connectivity More... | |
void | checkAndReconnectWIFI_MQTTNetworking () |
print a SPIFF timestamp.. More... | |
void | printWIFIInfo () |
print the WIFI info More... | |
boolean | isDawgpackTopic () |
helper to know it's a dawgpack topic (and not process in most cases). Only support DOCFOLLOW for now.. More... | |
boolean | isSuperTopic () |
helper to know it's a superuser topic (and not process in most cases). More... | |
void | classifyTopic (char *topic) |
classify a topic More... | |
void | printTopicType () |
prints the topic on debug More... | |
void | callbackMQTTHandler (char *topic, byte *payload, unsigned int length) |
called when data on the MQTT socket More... | |
bool | stringMatch (String message, String substring) |
check if the string matches More... | |
boolean | bluetoothOnline () |
! should be a definition that the bluetooth is ONLINE More... | |
void | cleanEPROM_MQTTNetworking () |
cleans the eprom info More... | |
void | sendMessageMQTT (char *message) |
void | sendMessageNoChangeMQTT (char *message) |
just send a message but without any extras More... | |
void | sendStatusMessageMQTT_deviceName (char *deviceName, const char *semanticMarker) |
sends the semantic marker as a doc follow message #remoteMe (vs STATUS, as that triggers a status reply.. ) More... | |
void | sendStatusMessageMQTT (const char *semanticMarker) |
sends the semantic marker as a doc follow message #remoteMe (vs STATUS, as that triggers a status reply.. ) More... | |
void | sendDocFollowMessageMQTT (const char *semanticMarker) |
sends the semantic marker as a doc follow message More... | |
boolean | isTrueString (String valCmdString) |
whether the string is TRUE, ON, 1 More... | |
void | invokeCurrentSMModePage (char *topic) |
send message to ourself to change to current specifed SM Mode More... | |
void | restartWIFI_MQTTState () |
restart the WIFI and then MQTT connection More... | |
Variables | |
Preferences | _preferencesMQTTNetworking |
3.3.22 Using the new JSON library which is supposed to catch syntax errors without blowing up More... | |
int | _globalMQTTAttempts = 0 |
int | _startTimestamp = 0 |
uptime since last reboot. More... | |
WiFiClient | _espClient |
The WIFI client. More... | |
int | _counterLoop |
int | _maxCounterLoop |
const char * | _ntpServer = "pool.ntp.org" |
define here as well.. NOTE: this could be passed is as well... TODO More... | |
boolean | _MQTTRunning = false |
char | _fullMessageIn [MAX_MESSAGE] |
message received on subscription More... | |
char | _fullMessageOut [MAX_MESSAGE] |
message to send out More... | |
char | _semanticMarkerString [MAX_MESSAGE] |
char * | _ssidString |
char * | _ssidPasswordString |
char * | _mqttServerString |
char * | _mqttPortString |
char * | _mqttPasswordString |
char * | _mqttGuestPasswordString |
char * | _mqttUserString |
char * | _mqttTopicString |
char * | _deviceNameString |
char * | _uuidString |
char * | _jsonVersionString |
char * | _jsonHeaderString |
char * | _jsonLocationString |
boolean | _newMQTTMessageArrived = false |
String | _topic |
the topic the new message came in on.. More... | |
String | _fullJSONString |
storage for the full JSON message string to send around.. More... | |
uint32_t | _chipId = 0 |
char | _chipName [50] |
char | _lastDocFollowSemanticMarker [200] |
storage for last doc follow semantic marker More... | |
int | _countSinceLastChangedMessageStatus = 0 |
a counter to erase the last message if not changed in N calls.. More... | |
char | _lastMessageStatusURL [100] |
storage of the last message status More... | |
WIFI_MQTTStates | _WIFI_MQTTState = preSetupWIFI |
the state we are in.. More... | |
float | _WIFI_MQTTStateDelays [] |
the delay in seconds for each state More... | |
unsigned long | _delayStart_WIFI_MQTTState |
the time the delay started More... | |
boolean | _delayRunning_WIFI_MQTTState = false |
true if still waiting for delay to finish More... | |
float | _delaySeconds_WIFI_MQTTState |
length of delay More... | |
boolean | _setupMQTTNetworkingAlready = false |
try a flag so setupMQTTnetworking only called 1 times.. More... | |
unsigned long | _delayCheckWIFIStart_MQTTNetworking |
the time the delay started More... | |
boolean | _delayCheckWIFIRunning_MQTTNetworking = false |
true if still waiting for delayCheckWIFI to finish More... | |
int | _delayCheckWIFISeconds_MQTTNetworking |
length of delay More... | |
enum MQTTMessageTopicType | _MQTTMessageTopicType = userTopic |
#define _preferencesJSONName "JSONPrefs" |
Points to strings read from JSON (limited to 15 char key name)
Definition at line 191 of file MQTTNetworking.cpp.
#define ACK_FEED "#actMe" |
Definition at line 131 of file MQTTNetworking.cpp.
#define ACK_FEED2 "#ackMe" |
Definition at line 132 of file MQTTNetworking.cpp.
#define ACK_FOR_PAIR_TOO |
#define CONNECTED "#connectedMe" |
Definition at line 133 of file MQTTNetworking.cpp.
#define DOCFOLLOW "#docFollow" |
Definition at line 137 of file MQTTNetworking.cpp.
#define DOCFOLLOW2 "#DOCFOLLOW" |
Definition at line 138 of file MQTTNetworking.cpp.
#define DOCSYNC "#docSync" |
Definition at line 139 of file MQTTNetworking.cpp.
#define ESP_EPROM_NAME "ESP32" |
Ambers 22nd birthday.. 2.20.22.
MQTTModule The MQTT + WIFI part
Created: on Jan 1, 2022 Author: Scott Moody test..
Definition at line 46 of file MQTTNetworking.cpp.
#define FEED "#FEED" |
Definition at line 129 of file MQTTNetworking.cpp.
#define FEED_2 "#feedme" |
Definition at line 130 of file MQTTNetworking.cpp.
#define FOLLOW_ME "#followMe" |
DOCFOLLOW syntax 8.11.22 syntax: #followMe {AVM=<avm address>} .. no quotes
Definition at line 143 of file MQTTNetworking.cpp.
#define MAX_MESSAGE 600 |
define this storage once, and use everwhere..
Definition at line 182 of file MQTTNetworking.cpp.
#define MAX_MQTT_ATTEMPTS 10 |
Definition at line 86 of file MQTTNetworking.cpp.
#define MAX_WIFI_CONNECT_ATTEMPTS 30 |
Definition at line 89 of file MQTTNetworking.cpp.
#define MAXglobalMQTTAttempts 10 |
Definition at line 84 of file MQTTNetworking.cpp.
#define NO_ACK_FEED "#noactMe" |
Definition at line 135 of file MQTTNetworking.cpp.
#define NO_CAN "#NO_CAN" |
Definition at line 140 of file MQTTNetworking.cpp.
#define NO_NEED_AND_GRU_CRASH |
#define NOT_CONNECTED "#noconnectedMe" |
Definition at line 134 of file MQTTNetworking.cpp.
#define OTA "#OTA" |
Definition at line 123 of file MQTTNetworking.cpp.
#define PLAY_ME "#playMe" |
Definition at line 136 of file MQTTNetworking.cpp.
#define REMOTE "#remoteMe" |
Definition at line 127 of file MQTTNetworking.cpp.
#define REMOTE2 "#REMOTE" |
Definition at line 128 of file MQTTNetworking.cpp.
#define SINGLE_DELAY |
a call to see if the WIFI is connected
Definition at line 727 of file MQTTNetworking.cpp.
#define STATUS "#STATUS" |
Definition at line 125 of file MQTTNetworking.cpp.
#define TRY_MORE_ASYNC_PROCESSING |
the publishMQTTMessage is placed here as a placeholder for making the mqtt publish. If needed, this could be moved to another thread (or the next loop)
Definition at line 225 of file MQTTNetworking.cpp.
#define WIFI_MQTT_STATES |
4.26.22 50 year anniverssery of Grateful Dead in Frankfurt 1972
Definition at line 505 of file MQTTNetworking.cpp.
enum MQTTMessageTopicType |
break up the MQTT Handler 8.12.22 as per "My guess is that you have your data collection (from some I2C device) and data delivery intermingled. Separate them so that you have the data in hand before you make the network connection. That will reduce the possibility of timeouts and race conditions. It also makes it easier to add new collection and delivery processes. The more asynchronous you can make these steps, the more robust your application will be overall."
add globals for knowing the type of message. call the check message processing state variables
Enumerator | |
---|---|
userTopic | |
dawgpackTopic | |
superTopic |
Definition at line 1034 of file MQTTNetworking.cpp.
enum WIFI_MQTTStates |
state variables
Enumerator | |
---|---|
preSetupWIFI | |
waitingForWIFI | |
preSetupMQTT | |
waitingForMQTT | |
connectedWIFI | |
connectedMQTT | |
disconnectedWIFI | |
disconnectedMQTT |
Definition at line 517 of file MQTTNetworking.cpp.
PubSubClient _mqttClient | ( | _espClient | ) |
The PubSub MQTT Client.
void blinkBlueLightMQTT | ( | ) |
blinks the blue light
https://www.arduino.cc/en/Tutorial/Foundations/DigitalPins
Definition at line 859 of file MQTTNetworking.cpp.
boolean bluetoothOnline | ( | ) |
! should be a definition that the bluetooth is ONLINE
Definition at line 1342 of file MQTTNetworking.cpp.
void callbackMQTTHandler | ( | char * | topic, |
byte * | payload, | ||
unsigned int | length | ||
) |
called when data on the MQTT socket
too many printouts which actully slows things down.. start with actMe (or collect a count of #actme and report that??)
classify the topic type
NOTE: This assumes the callbackMQTTHandler is only called once per message processed, as the next time in the loop(), it processes this _fullMessage since the _newMQTTMessageArrived == true
Definition at line 1092 of file MQTTNetworking.cpp.
void callPreSetupMQTT | ( | ) |
called to setup the MQTT (which is really the _mqttClient setup). Done on it's own thread..
Definition at line 1011 of file MQTTNetworking.cpp.
void checkAndReconnectWIFI_MQTTNetworking | ( | ) |
print a SPIFF timestamp..
checks if the WIFI is off (or not reachable) and tries consecting again (the 'W' command)
The setup() will call restartDelay_MQTTNetworking Each loop will call checkDelaySinceButtonTouched_MQTTNetworking checks if the WIFI is off (or not reachable) and tries consecting again (the 'W' command)
start outputing SPIFF info
it seems the WIFI can reconnect – but all the MQTT isn't restarted.. So if our internal state things WIFI is off, reconnect anyway..
try reconnecting if not connected (and ssid is available)
start outputing SPIFF info
restart the WIFI and then MQTT connection
Definition at line 799 of file MQTTNetworking.cpp.
void checkDelaySinceWIFICheck_MQTTNetworking | ( | ) |
checks delay for the WIFI connectivity
check and reconnect to the WIFI is not connected
restart the timer
Definition at line 781 of file MQTTNetworking.cpp.
void checkMQTTMessages_loop | ( | ) |
check for MQTT messages, called from the main loop()
don't do the loop at same time as check, do it at another time..
save some part of this message for later display by SemanticMarker 8.4.22
11.7.22 if it's an #actMe .. don't show
call the MQTT infrastructure loop which does it's MQTT messaging
Definition at line 1307 of file MQTTNetworking.cpp.
void classifyTopic | ( | char * | topic | ) |
classify a topic
set the topic type
Definition at line 1055 of file MQTTNetworking.cpp.
void cleanEPROM_MQTTNetworking | ( | ) |
cleans the eprom info
Definition at line 1348 of file MQTTNetworking.cpp.
void cleanSSID_EPROM_Method | ( | ) |
calls the method for cleaning the SSID eprom. This calls the WIFI_APModule callback
call the callback for cleaning the SSID eprom..
Definition at line 1842 of file MQTTNetworking.cpp.
char * currentMessageStatusURL | ( | ) |
returns a string in in URL so: status?battery=84'&buzzon='off' } .. etc
increment the count
Definition at line 476 of file MQTTNetworking.cpp.
boolean delayCheckWIFIFinished_MQTTNetworking | ( | ) |
if finished..
Definition at line 760 of file MQTTNetworking.cpp.
boolean delayFinished_WIFI_MQTTState | ( | ) |
if finished..
Definition at line 571 of file MQTTNetworking.cpp.
void emptyLastMessageStatus | ( | ) |
empty the status message
Definition at line 469 of file MQTTNetworking.cpp.
void finishWIFI_Setup | ( | ) |
end of WIFI loop..
Definition at line 973 of file MQTTNetworking.cpp.
void getChipInfo | ( | ) |
create a unique ID (but it needs to be stored.. otherwise it's unique each time??
get the chip info
Definition at line 379 of file MQTTNetworking.cpp.
int getDelayCheckWIFISeconds_MQTTNetworking | ( | ) |
get the delay values
Definition at line 748 of file MQTTNetworking.cpp.
char * getDeviceNameMQTT | ( | ) |
called for things like the advertisement
NOTE: The following are only called from MainModule or ESP_IOT.ino (basically main)
callback with the message if required (like sending the FEED message) !function pointers: https://www.cprogramming.com/tutorial/function-pointers.html define as: void callback(char* message) call processMessage(message, &callback);
Definition at line 366 of file MQTTNetworking.cpp.
const char * getDynamicMessageFunc | ( | ) |
used by the displayModule to call this for each new status
Definition at line 489 of file MQTTNetworking.cpp.
const char * getDynamicStatusFunc | ( | ) |
This uses the String (*getStatusFunc)(void)) to re-create this.. used by the displayModule to call this for each new status
Definition at line 399 of file MQTTNetworking.cpp.
String getJSONConfigString | ( | ) |
retrieve the Configuration JSON string in JSON format..
Definition at line 353 of file MQTTNetworking.cpp.
char * getLastDocFollowSemanticMarker_MQTTNetworking | ( | ) |
retrieves the last DocFollow SemanticMarker (from the message DOCFOLLOW | #followMe {AVM=<SM>} Or the JSON: {'set':'semanticMarker','val','<URL>}
Definition at line 421 of file MQTTNetworking.cpp.
int getUptime | ( | ) |
returns seconds since first booted
Definition at line 166 of file MQTTNetworking.cpp.
void initAllArrayStorage | ( | ) |
Put all the storage initialization here..
Definition at line 438 of file MQTTNetworking.cpp.
void invokeCurrentSMModePage | ( | char * | topic | ) |
send message to ourself to change to current specifed SM Mode
send message to ourself to process the current mode..
Definition at line 2304 of file MQTTNetworking.cpp.
boolean isConnectedMQTT_MQTTState | ( | ) |
value of MQTT connected
Definition at line 651 of file MQTTNetworking.cpp.
boolean isConnectedWIFI_MQTTState | ( | ) |
value of WIFI connected
Definition at line 637 of file MQTTNetworking.cpp.
boolean isDawgpackTopic | ( | ) |
helper to know it's a dawgpack topic (and not process in most cases). Only support DOCFOLLOW for now..
Definition at line 1045 of file MQTTNetworking.cpp.
boolean isSuperTopic | ( | ) |
helper to know it's a superuser topic (and not process in most cases).
Definition at line 1050 of file MQTTNetworking.cpp.
boolean isTrueString | ( | String | valCmdString | ) |
whether the string is TRUE, ON, 1
Definition at line 2287 of file MQTTNetworking.cpp.
void loop_MQTTNetworking | ( | ) |
called for the loop() of this plugin
State: 0 .
waitingForWIFI (delaying when Nice writeup: https://microcontrollerslab.com/esp32-mqtt-publish-multiple-sensor-readings-node-red/
called for the loop() of this plugin
check if should try to reconnect to WIF
check if a delay was running.. for the STATE..
Definition at line 663 of file MQTTNetworking.cpp.
void MQTTModule_readPreferences | ( | ) |
setup the WIFI
*********************** END METHODS invoked from BLE (JSON) and MQTT messages ***************
read any values from EPROM
This is in case corruption when changing what's written.. defining BOOTSTRAP will clean up the EPROM read the eprom..
seems the JSON object only returns these const char*, and not easy to just create a char *, so they are created in their own memory..
the MQTT host/port/user/password (topic is created in this code...)
Note: This is where the code could look for backward compatability, etc..
sets the MQTT user/password. It's up to the code to decide who needs to know (currently saves in the WIFI_APModule
Definition at line 1963 of file MQTTNetworking.cpp.
void performFeedMethod | ( | char * | topic | ) |
calls the FEED message via the callback (which calls the BLE code)
//!calls the FEED message via the callback (which calls the BLE code) NOTE: this will send a BLE command if connected via the GATEWAY to a GEN3 (or other gateway in the future) NOTE: This sends the _full message on the topic ..
get the temperature
get the connected status save some part of this message for later display by SemanticMarker 8.4.22 set the feed
FOR NOW , copy the code and create a _fullMessageOut that is for the Paired device...
5.21.22 WORKS!! topic is the topic we can in on.. so could be super user..
5.21.22 WORKS!! topic is the topic we can in on.. so could be super user..
Definition at line 1851 of file MQTTNetworking.cpp.
void performOTAUpdateMethod | ( | ) |
perform the OTA update. This calls the OTAImageUpdate methods (via preformOTAUpdateSimple())
*********************** METHODS invoked from BLE (JSON) and MQTT messages ***************
perform the OTA update. This calls the OTAImageUpdate methods (via preformOTAUpdateSimple())
dispatches a call to the command specified. This is run on the next loop()
Definition at line 1819 of file MQTTNetworking.cpp.
void printTopicType | ( | ) |
prints the topic on debug
Definition at line 1067 of file MQTTNetworking.cpp.
void printWIFIInfo | ( | ) |
print the WIFI info
Definition at line 959 of file MQTTNetworking.cpp.
void processBarkletMessage | ( | String | message, |
String | topic | ||
) |
process an MQTT message looking for keywords (barklet language)
process an MQTT message looking for keywords (this version uses the Barklet Language Grammer 2014
) NOTE: The processJSONMessage() is part of this (called if straight JSON). TODO: merge these two methods..
https://stackoverflow.com/questions/7352099/stdstring-to-char
convert String to char *
flag to send the message back on MQTT
debug printout..
new 4.12.22 if this is straight JSON .. then sent to the processJSONmessage
If the dawgpack, only process the DOCFOLLOW message
note: these messages are sent to MQTT. But the messages comming down originated on WebSocket barklets language so the 'remoteMe ..." gets up there, but not back to the rest. It's rewritten by nodered. save some part of this message for later display by SemanticMarker 8.4.22 set the status process the pair if match FOR NOW , copy the code and create a _fullMessageOut that is for the Paired device... retrieve the service name (PTFEEDER, PTFeeder:Name, PTClicker:Name, etc) 5.21.22 WORKS!! topic is the topic we can in on.. so could be super user.. retrieve the service name (PTFEEDER, PTFeeder:Name, PTClicker:Name, etc) flag for whether feed will occur. it won't if a device is specified and it's not our device (unless super topic) check against the super feeder. If super feeder, then feed all devices, otherwise logic below perform the feed message already sent ... 3.25.22 – trying the CLEAN the ePROM SSID call the callback for cleaning the SSID eprom.. 3.8.22 – trying the OTA. IT WORKS!!! NOW: 2 versions, 3.28.22, try to parse {v:'version starts with.." ) -- or just contains substring. eg. OTA Version-1.6a ... and check against our "VERSION"
dispatches a call to the command specified. This is run on the next loop()
5.21.22 WORKS!! topic is the topic we can in on.. so could be super user..
Definition at line 1451 of file MQTTNetworking.cpp.
boolean processJSONMessageMQTT | ( | char * | ascii, |
char * | topic | ||
) |
process the JSON message (looking for FEED, etc). Note: topic can be nil, or if not, it's an MQTT topic (so send replies if you want)
process the JSON message, which can be configuration information. This is called from outside on things like a Bluetooth message.. return true if valid JSON, and false otherwise. This looks for '{' as the starting character (after possible spaces in front). A topic can be sent, or nil
use the default user topic if not specified...
empty the status for the last message. Then various places the feed or status, etc are set
Basically processing as a JSON if the "{" is somewhere.. could still be invalid code
devName is if a dev=<NAME> was specified, then dissregard if not our device
this is to ensure that the credentials are not processed.. there is a return 'true' after processing commands
for dawgPack, only support the DOCFOLLOW message for now 8.19.22
a couple commands, like bleserveron require a device name to be specified (so everyone listening doesn't perform operation)
if a dev:<dev> is specified, then only process if the device name is that same
parses a line of text, The caller then uses queryMatchesName() to see if their name matches
we are in gateway mode, and the paired device isn't ours..
after this, if true, then ifDeviceNameSpecified .. then it's a good name..
as per issue #122, if a device is in gateway mode, and paired with a device name specified, then the message can be sent
per #206 .. only change the page when not in doc_follow 11.9.22
Issue: #222 for #206, this sets the current mode to SM_doc_follow, but when at that page in the the current mode (which is now SM_doc_follow) won't let the page go somewhere else (except in this case we are the same page). Only but a physical button click. I THINK THE ANSWER: if current and next are the same an SM_doc_follow, then do the page change..
the 4th page, start of smart clicker
create the SemanticMarker address
call the displayModuleFunc passing our dynamic status fund
create the SemanticMarker address
tack on the device name..
call the displayModuleFunc passing our dynamic status fund
NOTE this could be "NONE" the "P:" is so the display knows this is a paired device command
#issue 136 create a SM for the WIFI syntax WIFI:S:<SSID>;T:<WEP|WPA|blank>;P:<PASSWORD>;H:<true|false|blank>;
calls the OTA update method (this doesn't return as device is rebooted...)
calls the method for cleaning the SSID eprom. This calls the WIFI_APModule callback
print status of the WIFI and MQTT
request a STATUS be sent.
TODO: duplicate and depreciate these and replace with set:buzz,val:on
resetFirstTime
for now just reboot which will use this perference
for now just reboot which will use this perference
for now just reboot which will use this perference
for now just reboot which will use this perference
for now just reboot which will use this perference
for now just reboot which will use this perference
zoom == the NON semantic marker version.. so min menu is true
zoom only if in the max menu set..
zoom only if in the max menu set..
send message to ourself to process the current mode..
These are the ASYNC_CALL_PARAMETERS_MAX NO: just change our credentials ...
request a CAPTURE be sent.
and print any preferences to show
publich back on topic
{'guest':'guest password'}
use the name/cat/uuid ..
5.12.22
options: hightemp, feedcount, timeout
set flag (if a boolean command)
try 5.12.22 {'set':'item'},{'val':'value'} eg. set:hightemp, val:80) TODO: confirm valid integer values...
set the high temp value..
9.29.22 duplicating a couple of 'set':'cmd', 'val':'feed", since the QUERY for a device is sent that way sometimes.. request a STATUS be sent. 11.9.22 restarts all the menu states to the first one .. useful for getting a clean start. This doesn't care if the menu is being shown set the stepperangle. set the timeout from no click to poweroff called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean) 10.4.22 called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean) called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean) the setup for this module MQTT: set: timerdelay, val:seconds set the timer delay (0 == stop). start or stop the timer.. MQTT: set: starttimer, val: true/false (true == start timer, false = stop timer) start or stop the timer.. start or stop the timer.. add stepper type called to set a preference (which will be an identifier and a string, which can be converted to a number or boolean) note since clockwise == 0 we set the opposite of the value.. add stepper type set the location rename device since renaming, lets set a STATUS out.. request a STATUS be sent. pairnow is for invoking the pair when there isn't a user interface. Basically once an ESP32 gets connected, especially to a GEN3, the pairnow will make it paired for future. 10.24.22 TRUE will pair, FALSE will unpair performs the pairing.. to whatever is currently connected, this means a message could make that happen for a device (ESP-32) with no user interface. just unpair .. don't skip performs the unpairing paireddev the paired device (used with BLEUsePairedDeviceName and gen3Only saves the pair device name TODO: the feed device should use the pair as well.. (DONE..) paired address is null until found.. Keep whatever is set ...??? set the screen color 0..n sets the gen3only flag (only look for BLEServers that are GEN3) sets the gen3only flag for now just reboot which will use this perference BLEUsePairedDeviceName (Says to only look for BLEServers with the paired name.. sets the BLEUseDeviceName flag == the BLEServer will add the name, eg PTFeeder:ScoobyDoo sets the bleusedevicename flag for now just reboot which will use this perference and re-create the service name.. send message to ourself to process the current mode.. send message to ourself to process the current mode.. store the JSON version of these credentials.. per #224 this will also set WIFI_CREDENTIAL_2 (even if it's also setting #1) NOTE: this saving has to be done before calling processJSON (since the string is goofed upand == 'ssid' not the full string now process the credentials, which will set CREDENTIAL_1 print the preferences to SerialDebug if flag then blankscreen, otherwise wake the screen.. blanks the screen wakes up the screen 8.17.22 SubDawgpack for now just reboot which will use this perference start a dawgpack subscription 8.15.22 Also subscribe to the dawgpack .. but restrict what it can effect. For example, start with STATUS and DOCFOLLOW TODO: duplicate and depreciate these and replace with set:buzz,val:on this uses the ASYNC since it involves a BLE command, and has to be done outside of this WIFI (MQTT) operation.. for now just reboot which will use this perference for now just reboot which will use this perference zoom == the NON semantic marker version.. so min menu is true zoom only if in the max menu set.. zoom only if in the max menu set.. send message to ourself to process the current mode.. 9.22.22 added button press from messages.. 5.24.22 send:<request> .. Note these are for cmd without an argument.. NOTE: This will be calling ourself request a TEMP be sent. request a STATUS be sent. request a CAPTURE be sent. request a VOLUME be sent. this return is important!!! end process commands.. TRY without 1.30.22 (RAMS win) and it works.. if can talk BLE, then reboot.. 2.2.22 @verbatim { "ssid" : "SunnyWhiteriver", "ssidPassword" : "sunny2021", "mqtt_topic": "usersP/bark/test", "mqtt_user" : "test", "deviceName" : "HowieFeeder", "mqtt_password" : "password..", "mqtt_guestPassword" : "password", "uuid" : "scott", "mqtt_port" : "1883", "mqtt_server" : "idogwatch.com", "mqtt_status" : "Success", "location": "whatever to reply with, GPS, state, city, etc.." } todo pass the guest password too
! Store wifi config. 存储wifi配置信息
5.25.22 (50 years since Grateful Dead London Show
To support just setting the ssid and password, a JSON of {ssid:s,ssidPassword:p} is supported, so don't null out if mqtt aren't provided.. this should work (since the SSID is what's checked to go to the AP mode)
the MQTT host/port/user/password (topic is created in this code...)
reset the MQTT attempts
setup the WIFI if the ssid string (at least) is specified
new: go out and let the process work... set the state, then the 'loop' will call setupWIF(...)
call the callback specified from the caller (eg. NimBLE_PetTutor_Server .. or others)
don't save the preferences, since it didn't have enough information..
NOTE: this writes over entire values, since it's a string vs an JSON object
new 4.8.22 .. trying to kick out of AP mode if the credentials are good..
putting here .. time might have gone too fast..
Definition at line 2312 of file MQTTNetworking.cpp.
void publishBinaryFile | ( | char * | topic, |
uint8_t * | buf, | ||
size_t | len | ||
) |
publish a binary file..
https://randomnerdtutorials.com/esp32-http-get-post-arduino/ https://randomnerdtutorials.com/esp32-cam-post-image-photo-server/ https://raw.githubusercontent.com/RuiSantosdotme/ESP32-CAM-Arduino-IDE/master/ESP32-CAM-HTTP-POST-Image/ESP32-CAM-HTTP-POST-Image.ino Lets do a POSt to my whats-this site..
Definition at line 261 of file MQTTNetworking.cpp.
void publishMQTTMessage | ( | char * | topic, |
char * | message | ||
) |
Wrapper of the mqttclient publish. NOTE: this might need to be in the loop as well, as the BLE could be the way the message arrived, and we are sending out over MQTT (while in the BLE thread). Don't know??
Wrapper of the mqttclient publish.
publish on the mqttClient object
see if this pushs the publish out.. (otherwise a reply might occure .. an break our _fullMessage)
Definition at line 228 of file MQTTNetworking.cpp.
void publishMQTTMessageDefaultTopic | ( | char * | message | ) |
Wrapper of the mqttclient publish.
Definition at line 248 of file MQTTNetworking.cpp.
void reconnectMQTT_loop | ( | ) |
reconnects and re-subscribes NOTE: we need the host info...
call the callback for cleaning the SSID eprom..
try making a bigger packet.. 10.23.22 (seems to help) Looking at the PubSubClient.cpp, if (this->bufferSize < MQTT_MAX_HEADER_SIZE + 2+strnlen(topic, this->bufferSize) + plength) {
Only subscribe if turned on.. 8.17.22
8.15.22 Also subscribe to the dawgpack .. but restrict what it can effect. For example, start with STATUS and DOCFOLLOW
reset the global attempts .. since we connected
Definition at line 1145 of file MQTTNetworking.cpp.
void restartDelayCheckWIFI_MQTTNetworking | ( | ) |
starts the delay for WIFI checking, called at startup, and each time the timer finished..
timed events starts the delay for WIFI checking, called at startup, and each time the timer finished..
Definition at line 754 of file MQTTNetworking.cpp.
void restartWIFI_MQTTState | ( | ) |
restart the WIFI and then MQTT connection
Definition at line 3725 of file MQTTNetworking.cpp.
void sendDocFollowMessageMQTT | ( | const char * | semanticMarker | ) |
sends the semantic marker as a doc follow message
sends the semantic marker as a doc follow message DOCFOLLOW
Definition at line 1428 of file MQTTNetworking.cpp.
void sendMessageMQTT | ( | char * | message | ) |
just send a message (let the internals to figure out topics, etc.. so the BLE can send something on the MQTT for now only send if it start message starts with "#"
Definition at line 1359 of file MQTTNetworking.cpp.
void sendMessageNoChangeMQTT | ( | char * | message | ) |
just send a message but without any extras
Definition at line 1383 of file MQTTNetworking.cpp.
void sendStatusMessageMQTT | ( | const char * | semanticMarker | ) |
sends the semantic marker as a doc follow message #remoteMe (vs STATUS, as that triggers a status reply.. )
Definition at line 1423 of file MQTTNetworking.cpp.
void sendStatusMessageMQTT_deviceName | ( | char * | deviceName, |
const char * | semanticMarker | ||
) |
sends the semantic marker as a doc follow message #remoteMe (vs STATUS, as that triggers a status reply.. )
Definition at line 1405 of file MQTTNetworking.cpp.
void setLastDocFollowSemanticMarker_MQTTNetworking | ( | char * | semanticMarker | ) |
sets the last DocFollow SemanticMarker
Definition at line 427 of file MQTTNetworking.cpp.
void setLastMessageStatus | ( | char * | token | ) |
retrieves a token string.. without spaces. Currently this will be things like
add just the version and device name to start, but add the msg=
Make up a shorter version of the message
TODO: make sure no spaces ... unless escaped
Definition at line 446 of file MQTTNetworking.cpp.
void setup_MQTTNetworking | ( | ) |
setup the MQTT part of networking
THIS IS the setup() and loop() but using the "component" name, eg MQTTNetworking() called from the setup()
init variables..
starts the delay for WIFI checking, called at startup, and each time the timer finished..
Definition at line 595 of file MQTTNetworking.cpp.
void setupMQTT | ( | char * | mqttServerString, |
char * | mqttPortString, | ||
char * | mqttPasswordString, | ||
char * | mqttUserString, | ||
char * | deviceNameString, | ||
char * | uuidString | ||
) |
setup the MQTT server
setup the MQTT (called after the WIFI connected)
print the WIFI info AGAIN..
Definition at line 1281 of file MQTTNetworking.cpp.
void setupWIFI | ( | char * | arg_ssid, |
char * | arg_password | ||
) |
setup the WIFI using ssid and password
setup the WIFI using ssid and password (called from setup_MQTTNetworking() .. the main setup for this module)
start the WIFI mode and begin
set the counters..
reset the global attempts .. since we are trying to reconnect
Definition at line 871 of file MQTTNetworking.cpp.
void setupWIFI_loop | ( | ) |
the loop part of WIFI
the loop part of WIFI. Call this each time the timer is up (the delay() ) and only go to the next state if state changes to waitingForMQTT
call the callback for cleaning the SSID eprom..
Definition at line 902 of file MQTTNetworking.cpp.
boolean skipMessageProcessing | ( | ) |
this is sent from the backend as a message {'guest':'guest password'} .. but lets' add to the credentials..
whether message should be skipped for display and debug printouts uses _fullMessageIn global
Definition at line 212 of file MQTTNetworking.cpp.
void startDelay_WIFI_MQTTState | ( | ) |
init the delay, this uses the array of delays so we can change easier..
Definition at line 561 of file MQTTNetworking.cpp.
void startDelayCheckWIFI_MQTTNetworking | ( | int | seconds | ) |
init the delay
Definition at line 737 of file MQTTNetworking.cpp.
void stopDelay_WIFI_MQTTState | ( | ) |
stop the delay
Definition at line 582 of file MQTTNetworking.cpp.
void stopDelayCheckWIFI_MQTTNetworking | ( | ) |
stop the delay (not called)
Definition at line 773 of file MQTTNetworking.cpp.
bool stringMatch | ( | String | message, |
String | substring | ||
) |
check if the string matches
Definition at line 1336 of file MQTTNetworking.cpp.
void updatePreferencesInEPROM | ( | ) |
just update the EPROM, and send that to the WIFI_AP module as well
basically if only the ssid/pass are sent, that is all that's written to EPROM even if the other information is available.. So recreate the JSON instead.. seems c++ you cannot re-use output as it just appends to it.. unreal
JSON
open the preferences
save in EPROM
Close the Preferences
sets the MQTT user/password. It's up to the code to decide who needs to know (currently saves in the WIFI_APModule
NEW: 2.21.22 TRY: reading back..
check ... _fullMessageOut Close the Preferences
Definition at line 3738 of file MQTTNetworking.cpp.
char * wifiStatus_MQTT | ( | ) |
show the status in string form (from Library/Adruino... WiFiType.h)
Definition at line 709 of file MQTTNetworking.cpp.
uint32_t _chipId = 0 |
Definition at line 375 of file MQTTNetworking.cpp.
char _chipName[50] |
Definition at line 376 of file MQTTNetworking.cpp.
int _counterLoop |
Definition at line 151 of file MQTTNetworking.cpp.
int _countSinceLastChangedMessageStatus = 0 |
a counter to erase the last message if not changed in N calls..
Definition at line 433 of file MQTTNetworking.cpp.
boolean _delayCheckWIFIRunning_MQTTNetworking = false |
true if still waiting for delayCheckWIFI to finish
Definition at line 733 of file MQTTNetworking.cpp.
int _delayCheckWIFISeconds_MQTTNetworking |
length of delay
Definition at line 735 of file MQTTNetworking.cpp.
unsigned long _delayCheckWIFIStart_MQTTNetworking |
the time the delay started
Definition at line 731 of file MQTTNetworking.cpp.
boolean _delayRunning_WIFI_MQTTState = false |
true if still waiting for delay to finish
Definition at line 557 of file MQTTNetworking.cpp.
float _delaySeconds_WIFI_MQTTState |
length of delay
Definition at line 559 of file MQTTNetworking.cpp.
unsigned long _delayStart_WIFI_MQTTState |
the time the delay started
Definition at line 555 of file MQTTNetworking.cpp.
char* _deviceNameString |
Definition at line 200 of file MQTTNetworking.cpp.
WiFiClient _espClient |
The WIFI client.
Definition at line 146 of file MQTTNetworking.cpp.
String _fullJSONString |
storage for the full JSON message string to send around..
Definition at line 350 of file MQTTNetworking.cpp.
char _fullMessageIn[MAX_MESSAGE] |
message received on subscription
Definition at line 184 of file MQTTNetworking.cpp.
char _fullMessageOut[MAX_MESSAGE] |
message to send out
Definition at line 186 of file MQTTNetworking.cpp.
int _globalMQTTAttempts = 0 |
Definition at line 82 of file MQTTNetworking.cpp.
char* _jsonHeaderString |
Definition at line 203 of file MQTTNetworking.cpp.
char* _jsonLocationString |
Definition at line 204 of file MQTTNetworking.cpp.
char* _jsonVersionString |
Definition at line 202 of file MQTTNetworking.cpp.
char _lastDocFollowSemanticMarker[200] |
storage for last doc follow semantic marker
examples https://SemanticMarker.org/bot/status?v=v5&dev=M5WRR&b=71&temp=59&c=0&t=8&W=on&M=on&B=on&C=off&A=off&T=off&S=on&bleS=PTClicker:M5WRR&Z=off&G=on&P=DukeGEN3&t=8 https://SemanticMarker.org/bot/status?v=v5&dev=M55&b=94&temp=54&c=1&t=2&W=on&M=on&B=on&C=on&A=off&T=off&S=on&bleS=PTClicker:M55&Z=off&G=off&t=2
Definition at line 418 of file MQTTNetworking.cpp.
char _lastMessageStatusURL[100] |
storage of the last message status
Definition at line 435 of file MQTTNetworking.cpp.
int _maxCounterLoop |
Definition at line 152 of file MQTTNetworking.cpp.
char* _mqttGuestPasswordString |
Definition at line 197 of file MQTTNetworking.cpp.
enum MQTTMessageTopicType _MQTTMessageTopicType = userTopic |
char* _mqttPasswordString |
Definition at line 196 of file MQTTNetworking.cpp.
char* _mqttPortString |
Definition at line 195 of file MQTTNetworking.cpp.
boolean _MQTTRunning = false |
Definition at line 179 of file MQTTNetworking.cpp.
char* _mqttServerString |
Definition at line 194 of file MQTTNetworking.cpp.
char* _mqttTopicString |
Definition at line 199 of file MQTTNetworking.cpp.
char* _mqttUserString |
Definition at line 198 of file MQTTNetworking.cpp.
boolean _newMQTTMessageArrived = false |
These are set by the MQTT callback.. flag to let the processor know there are new messages
Definition at line 345 of file MQTTNetworking.cpp.
const char* _ntpServer = "pool.ntp.org" |
define here as well.. NOTE: this could be passed is as well... TODO
Definition at line 176 of file MQTTNetworking.cpp.
Preferences _preferencesMQTTNetworking |
3.3.22 Using the new JSON library which is supposed to catch syntax errors without blowing up
added 1.1.2022 by iDogWatch.com CURRENTLY, this code below only has constant: usersP/bark as a super subscription This could be passed in via JSON later..
Definition at line 70 of file MQTTNetworking.cpp.
char _semanticMarkerString[MAX_MESSAGE] |
Definition at line 188 of file MQTTNetworking.cpp.
boolean _setupMQTTNetworkingAlready = false |
try a flag so setupMQTTnetworking only called 1 times..
Definition at line 592 of file MQTTNetworking.cpp.
char* _ssidPasswordString |
Definition at line 193 of file MQTTNetworking.cpp.
char* _ssidString |
Definition at line 192 of file MQTTNetworking.cpp.
int _startTimestamp = 0 |
uptime since last reboot.
Definition at line 118 of file MQTTNetworking.cpp.
String _topic |
the topic the new message came in on..
Definition at line 347 of file MQTTNetworking.cpp.
char* _uuidString |
Definition at line 201 of file MQTTNetworking.cpp.
WIFI_MQTTStates _WIFI_MQTTState = preSetupWIFI |
the state we are in..
Definition at line 537 of file MQTTNetworking.cpp.
float _WIFI_MQTTStateDelays[] |
the delay in seconds for each state
Definition at line 539 of file MQTTNetworking.cpp.