ESP_IOT v2.5
IOT ESP Coding
MQTTNetworking.h
Go to the documentation of this file.
1/** The MQTT + WIFI part
2
3
4 Created: on Jan 1, 2022, iDogWatch.com
5 Author: Scott Moody
6
7 */
8//#include <string>
9
10
11#ifndef MQTTNetworking_h
12#define MQTTNetworking_h
13
14#include "../../Defines.h"
15//! 8.16.25 MQTT
16
17#include "OTAImageUpdate.h"
18//does this make those .h available?
19
20/*******************************MQTT*************************************/
21
22//!callback with the message if required (like sending the FEED message)
23//!!function pointers: https://www.cprogramming.com/tutorial/function-pointers.html
24//!define as: void callback(char* message)
25//! call processMessage(message, &callback);
26//! This must be called first before the setup or loop
27//! eg: void myCallback(char* message) { }
28//! setMessageCallback(&myCallback)
29//void setMessageCallbacks(void (*callback)(char*), void (*blinkTheLED)());
30
31#define MQTT_CALLBACK_FEED 0
32#define MQTT_CALLBACK_BLINK 1
33#define MQTT_CALLBACK_TEMP 2
34//SOLID_LIGHT uses string parameter, "ON", "OFF"
35#define MQTT_CALLBACK_SOLID_LIGHT 3
36#define MQTT_CLEAN_SSID_EPROM 4
37//NEW 4.1.22 (what to do if no MQTT??)
38#define MQTT_CALLBACK_TILT_MOTION_DETECTED 5
39#define MQTT_CALLBACK_PIR_DETECTED 6
40//! 8.18.25 take out until test ...
41//#define MQTT_CALLBACK_SSID_DETECTED 7
42
43//! MAX must be updated to 1 more than last item..
44#define MQTT_MAX_CALLBACKS 7
45
46//!THIS IS the setup() and loop() but using the "component" name, eg MQTTNetworking()
47//! called from the setup()
49
50//! called for the loop() of this plugin
52
53//! NOTE: The following are only called from MainModule or ESP_IOT.ino (basically main)
54
55//!called for things like the advertisement
56char *getDeviceNameMQTT();
57
58//!restart the WIFI and then MQTT connection
60
61//!process the JSON message, which can be configuration information. This is called from outside on things like a Bluetooth message..
62//!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
63boolean processJSONMessageMQTT(char *ascii, char* topic);
64
65//!process an MQTT message looking for keywords (barklet language) NOT exposed yet...
66//! just send a message (let the internals to figure out topics, etc..
67//!so the BLE can send something on the MQTT
68//! for now only send if it start message starts with "#"
69 void sendMessageMQTT(char *message);
70
71//! for now only send if it start message starts with "#"
72void sendMessageMQTT_Topic(char *message, char *topic);
73
74//! just send a message but without any extras
75void sendMessageNoChangeMQTT(char *message);
76
77//! just send a message but without any extras, using a topic specified
78void sendMessageNoChangeMQTT_Topic(char *message, char *topic);
79
80//! Wrapper of the mqttclient publish
81void publishMQTTMessage(char *topic, char *message);
82
83//! Wrapper of the mqttclient publish
84void publishMQTTMessageDefaultTopic(char *message);
85
86//! publish a binary file..
87//! fileExtension is .jpg, .json, .txt etc
88void publishBinaryFile(char *topic, uint8_t * buf, size_t len, String fileExtension);
89
90//! 8.17.25
91//! for use by others, like RTSP
92//! return the WiFi Client
93//WiFiClient getWIFIClient();
94
95//! send semantic /smrun
96//! 3.25.24 this is an HTTP not https
97void publishSMRunMessage(char* smrunMessage);
98
99//! sends the semantic marker as a doc follow message #remoteMe (vs STATUS, as that triggers a status reply.. )
100void sendStatusMessageMQTT(const char *semanticMarker);
101
102//! sends the semantic marker as a doc follow message #DOCFOLLOW
103void sendDocFollowMessageMQTT(const char *semanticMarker);
104
105//! retrieves the last DocFollow SemanticMarker (from the message #DOCFOLLOW | #followMe {AVM=<SM>}
106//! Or the JSON: {'set':'semanticMarker','val','<URL>}
108
109//! sets the last DocFollow SemanticMarker
110void setLastDocFollowSemanticMarker_MQTTNetworking(char *semanticMarker);
111
112//!cleans the eprom info
114
115//!value of WIFI connected
117//!value of MQTT connected
119//!get the chip info
120void getChipInfo();
121
122//!timed events
123//!starts the delay for WIFI checking, called at startup, and each time the timer finished..
125//!checks delay for the WIFI connectivity
127//!checks if the WIFI is off (or not reachable) and tries consecting again (the 'W' command)
129
130//! 9.16.23 some debug information
131//! retrieve the Configuration JSON string in JSON format..
132String getJSONConfigString();
133
134//! retrieve the WIFIInfoString
135String get_WIFIInfoString();
136
137//! 9.18.23 LA (after Eagle Rock bike ride, Van Morrison tomorrow)
139
140//!Decode the URL (exposed 12.17.23 for the scanner
141String MQTT_urlDecode(String input);
142
143//! 3.22.24 get the WIFI SSID for the status
144String get_WIFI_SSID();
145
146#ifdef USE_SPIFF_MODULE
147//! publish a binary file..
148//! fileExtension is .jpg, .json, .txt etc
149void publishSPIFFFile_MQTT(char *topic, char *path, int len);
150#endif
151
152
153#else //PLACEHOLDERS
154
155//!process the JSON message, which can be configuration information. This is called from outside on things like a Bluetooth message..
156//!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
157boolean processJSONMessageMQTT(char *ascii, char* topic);
158
159//! send semantic /smrun
160//! 3.25.24 this is an HTTP not https
161void publishSMRunMessage(char* smrunMessage);
162
163
164//!Decode the URL (exposed 12.17.23 for the scanner
165String MQTT_urlDecode(String input);
166
167
168#endif // MQTTNetworking_h
169
void publishBinaryFile(char *topic, uint8_t *buf, size_t len, String fileExtension)
void publishMQTTMessageDefaultTopic(char *message)
Wrapper of the mqttclient publish.
void checkAndReconnectWIFI_MQTTNetworking()
checks if the WIFI is off (or not reachable) and tries consecting again (the 'W' command)
void cleanEPROM_MQTTNetworking()
cleans the eprom info
String get_WIFIInfoString()
retrieve the WIFIInfoString
void publishMQTTMessage(char *topic, char *message)
Wrapper of the mqttclient publish.
void sendMessageNoChangeMQTT_Topic(char *message, char *topic)
just send a message but without any extras, using a topic specified
void publishSPIFFFile_MQTT(char *topic, char *path, int len)
void sendMessageMQTT(char *message)
void checkDelaySinceWIFICheck_MQTTNetworking()
checks delay for the WIFI connectivity
String getJSONConfigString()
retrieve the Configuration JSON string in JSON format..
void setup_MQTTNetworking()
setup the MQTT part of networking
void sendStatusMessageMQTT(const char *semanticMarker)
sends the semantic marker as a doc follow message #remoteMe (vs STATUS, as that triggers a status rep...
void getChipInfo()
get the chip info
void loop_MQTTNetworking()
called for the loop() of this plugin
char * getLastDocFollowSemanticMarker_MQTTNetworking()
void cleanMQTTpasswordsUpdateInEPROM()
9.18.23 LA (after Eagle Rock bike ride, Van Morrison tomorrow)
boolean processJSONMessageMQTT(char *ascii, char *topic)
process the JSON message (looking for FEED, etc). Note: topic can be nil, or if not,...
String get_WIFI_SSID()
3.22.24 get the WIFI SSID for the status
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 DOCFOLLOW
void restartDelayCheckWIFI_MQTTNetworking()
starts the delay for WIFI checking, called at startup, and each time the timer finished....
void setLastDocFollowSemanticMarker_MQTTNetworking(char *semanticMarker)
sets the last DocFollow SemanticMarker
String MQTT_urlDecode(String input)
Decode the URL (exposed 12.17.23 for the scanner.
void sendMessageNoChangeMQTT(char *message)
just send a message but without any extras
boolean isConnectedMQTT_MQTTState()
value of MQTT connected
char * getDeviceNameMQTT()
NOTE: The following are only called from MainModule or ESP_IOT.ino (basically main)
boolean isConnectedWIFI_MQTTState()
value of WIFI connected
void restartWIFI_MQTTState()
restart the WIFI and then MQTT connection
void publishSMRunMessage(char *smrunMessage)