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#ifdef USE_MQTT_NETWORKING
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
41//! MAX must be updated to 1 more than last item..
42#define MQTT_MAX_CALLBACKS 7
43
44//!THIS IS the setup() and loop() but using the "component" name, eg MQTTNetworking()
45//! called from the setup()
47
48//! called for the loop() of this plugin
50
51//! NOTE: The following are only called from MainModule or ESP_IOT.ino (basically main)
52
53//!called for things like the advertisement
54char *getDeviceNameMQTT();
55
56//!restart the WIFI and then MQTT connection
58
59//!process the JSON message, which can be configuration information. This is called from outside on things like a Bluetooth message..
60//!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
61boolean processJSONMessageMQTT(char *ascii, char* topic);
62
63//!process an MQTT message looking for keywords (barklet language) NOT exposed yet...
64//! just send a message (let the internals to figure out topics, etc..
65//!so the BLE can send something on the MQTT
66//! for now only send if it start message starts with "#"
67 void sendMessageMQTT(char *message);
68
69//! just send a message but without any extras
70void sendMessageNoChangeMQTT(char *message);
71
72//! Wrapper of the mqttclient publish
73void publishMQTTMessage(char *topic, char *message);
74
75//! Wrapper of the mqttclient publish
76void publishMQTTMessageDefaultTopic(char *message);
77
78//! publish a binary file..
79void publishBinaryFile(char *topic, uint8_t * buf, size_t len);
80
81//! sends the semantic marker as a doc follow message #remoteMe (vs STATUS, as that triggers a status reply.. )
82void sendStatusMessageMQTT(const char *semanticMarker);
83
84//! sends the semantic marker as a doc follow message #DOCFOLLOW
85void sendDocFollowMessageMQTT(const char *semanticMarker);
86
87//! retrieves the last DocFollow SemanticMarker (from the message #DOCFOLLOW | #followMe {AVM=<SM>}
88//! Or the JSON: {'set':'semanticMarker','val','<URL>}
90
91//! sets the last DocFollow SemanticMarker
92void setLastDocFollowSemanticMarker_MQTTNetworking(char *semanticMarker);
93
94//!cleans the eprom info
96
97//!value of WIFI connected
99//!value of MQTT connected
101//!get the chip info
102void getChipInfo();
103
104//!timed events
105//!starts the delay for WIFI checking, called at startup, and each time the timer finished..
107//!checks delay for the WIFI connectivity
109//!checks if the WIFI is off (or not reachable) and tries consecting again (the 'W' command)
111
112#endif // USE_MQTT_NETWORKING
113
114#endif // MQTTNetworking_h
115
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
void publishMQTTMessage(char *topic, char *message)
Wrapper of the mqttclient publish.
void sendMessageMQTT(char *message)
void checkDelaySinceWIFICheck_MQTTNetworking()
checks delay for the WIFI connectivity
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 publishBinaryFile(char *topic, uint8_t *buf, size_t len)
publish a binary file..
boolean processJSONMessageMQTT(char *ascii, char *topic)
process the JSON message (looking for FEED, etc). Note: topic can be nil, or if not,...
void sendDocFollowMessageMQTT(const char *semanticMarker)
sends the semantic marker as a doc follow message 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
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