ESP_IOT v2.5
IOT ESP Coding
MQTTNetworking.h File Reference
#include "../../Defines.h"
#include "OTAImageUpdate.h"
Include dependency graph for MQTTNetworking.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define MQTT_CALLBACK_FEED   0
 
#define MQTT_CALLBACK_BLINK   1
 
#define MQTT_CALLBACK_TEMP   2
 
#define MQTT_CALLBACK_SOLID_LIGHT   3
 
#define MQTT_CLEAN_SSID_EPROM   4
 
#define MQTT_CALLBACK_TILT_MOTION_DETECTED   5
 
#define MQTT_CALLBACK_PIR_DETECTED   6
 
#define MQTT_MAX_CALLBACKS   7
 MAX must be updated to 1 more than last item.. More...
 

Functions

void setup_MQTTNetworking ()
 setup the MQTT part of networking More...
 
void loop_MQTTNetworking ()
 called for the loop() of this plugin More...
 
char * getDeviceNameMQTT ()
 NOTE: The following are only called from MainModule or ESP_IOT.ino (basically main) More...
 
void restartWIFI_MQTTState ()
 restart the WIFI and then MQTT connection 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 sendMessageMQTT (char *message)
 
void sendMessageNoChangeMQTT (char *message)
 just send a message but without any extras More...
 
void publishMQTTMessage (char *topic, char *message)
 Wrapper of the mqttclient publish. 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...
 
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 DOCFOLLOW More...
 
char * getLastDocFollowSemanticMarker_MQTTNetworking ()
 
void setLastDocFollowSemanticMarker_MQTTNetworking (char *semanticMarker)
 sets the last DocFollow SemanticMarker More...
 
void cleanEPROM_MQTTNetworking ()
 cleans the eprom info More...
 
boolean isConnectedWIFI_MQTTState ()
 value of WIFI connected More...
 
boolean isConnectedMQTT_MQTTState ()
 value of MQTT connected More...
 
void getChipInfo ()
 get the chip info More...
 
void restartDelayCheckWIFI_MQTTNetworking ()
 starts the delay for WIFI checking, called at startup, and each time the timer finished.. More...
 
void checkDelaySinceWIFICheck_MQTTNetworking ()
 checks delay for the WIFI connectivity More...
 
void checkAndReconnectWIFI_MQTTNetworking ()
 checks if the WIFI is off (or not reachable) and tries consecting again (the 'W' command) More...
 

Macro Definition Documentation

◆ MQTT_CALLBACK_BLINK

#define MQTT_CALLBACK_BLINK   1

Definition at line 32 of file MQTTNetworking.h.

◆ MQTT_CALLBACK_FEED

#define MQTT_CALLBACK_FEED   0

The MQTT + WIFI part

Created: on Jan 1, 2022, iDogWatch.com Author: Scott Moody 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); This must be called first before the setup or loop eg: void myCallback(char* message) { } setMessageCallback(&myCallback)

Definition at line 31 of file MQTTNetworking.h.

◆ MQTT_CALLBACK_PIR_DETECTED

#define MQTT_CALLBACK_PIR_DETECTED   6

Definition at line 39 of file MQTTNetworking.h.

◆ MQTT_CALLBACK_SOLID_LIGHT

#define MQTT_CALLBACK_SOLID_LIGHT   3

Definition at line 35 of file MQTTNetworking.h.

◆ MQTT_CALLBACK_TEMP

#define MQTT_CALLBACK_TEMP   2

Definition at line 33 of file MQTTNetworking.h.

◆ MQTT_CALLBACK_TILT_MOTION_DETECTED

#define MQTT_CALLBACK_TILT_MOTION_DETECTED   5

Definition at line 38 of file MQTTNetworking.h.

◆ MQTT_CLEAN_SSID_EPROM

#define MQTT_CLEAN_SSID_EPROM   4

Definition at line 36 of file MQTTNetworking.h.

◆ MQTT_MAX_CALLBACKS

#define MQTT_MAX_CALLBACKS   7

MAX must be updated to 1 more than last item..

Definition at line 42 of file MQTTNetworking.h.

Function Documentation

◆ checkAndReconnectWIFI_MQTTNetworking()

void checkAndReconnectWIFI_MQTTNetworking ( )

checks if the WIFI is off (or not reachable) and tries consecting again (the 'W' command)

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkDelaySinceWIFICheck_MQTTNetworking()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cleanEPROM_MQTTNetworking()

void cleanEPROM_MQTTNetworking ( )

cleans the eprom info

Definition at line 1348 of file MQTTNetworking.cpp.

Here is the caller graph for this function:

◆ getChipInfo()

void getChipInfo ( )

get the chip info

get the chip info

Definition at line 379 of file MQTTNetworking.cpp.

Here is the caller graph for this function:

◆ getDeviceNameMQTT()

char * getDeviceNameMQTT ( )

NOTE: The following are only called from MainModule or ESP_IOT.ino (basically main)

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.

Here is the caller graph for this function:

◆ getLastDocFollowSemanticMarker_MQTTNetworking()

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.

Here is the caller graph for this function:

◆ isConnectedMQTT_MQTTState()

boolean isConnectedMQTT_MQTTState ( )

value of MQTT connected

Definition at line 651 of file MQTTNetworking.cpp.

Here is the caller graph for this function:

◆ isConnectedWIFI_MQTTState()

boolean isConnectedWIFI_MQTTState ( )

value of WIFI connected

Definition at line 637 of file MQTTNetworking.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ loop_MQTTNetworking()

void loop_MQTTNetworking ( )

called for the loop() of this plugin

State: 0 .

  1. 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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ processJSONMessageMQTT()

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配置信息

See also
https://arduinojson.org

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.

Here is the caller graph for this function:

◆ publishBinaryFile()

void publishBinaryFile ( char *  topic,
uint8_t *  buf,
size_t  len 
)

◆ publishMQTTMessage()

void publishMQTTMessage ( char *  topic,
char *  message 
)

Wrapper of the mqttclient publish.

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ publishMQTTMessageDefaultTopic()

void publishMQTTMessageDefaultTopic ( char *  message)

Wrapper of the mqttclient publish.

Definition at line 248 of file MQTTNetworking.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restartDelayCheckWIFI_MQTTNetworking()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ restartWIFI_MQTTState()

void restartWIFI_MQTTState ( )

restart the WIFI and then MQTT connection

Definition at line 3725 of file MQTTNetworking.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendDocFollowMessageMQTT()

void sendDocFollowMessageMQTT ( const char *  semanticMarker)

sends the semantic marker as a doc follow message DOCFOLLOW

sends the semantic marker as a doc follow message DOCFOLLOW

Definition at line 1428 of file MQTTNetworking.cpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessageMQTT()

void sendMessageMQTT ( char *  message)

process an MQTT message looking for keywords (barklet language) NOT exposed yet... 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 "#"

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ sendMessageNoChangeMQTT()

void sendMessageNoChangeMQTT ( char *  message)

just send a message but without any extras

Definition at line 1383 of file MQTTNetworking.cpp.

Here is the call graph for this function:

◆ sendStatusMessageMQTT()

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.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ setLastDocFollowSemanticMarker_MQTTNetworking()

void setLastDocFollowSemanticMarker_MQTTNetworking ( char *  semanticMarker)

sets the last DocFollow SemanticMarker

Definition at line 427 of file MQTTNetworking.cpp.

Here is the caller graph for this function:

◆ setup_MQTTNetworking()

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.

Here is the call graph for this function:
Here is the caller graph for this function: