Quiet day at work. So.
Starting with this:
https://github.com/jrmejiaa/ESP8266I adapted it to
* use the ESP32 AT V2.4 command set
* added "parallel data channel" support
* added an initial set of MQTT sub client functions
So both command/control messages can be sent and acknowledge synchronously, while data is being received asynchronously.
To explain. When you ask the ESP32 AT something, like:
AT+CIPSTA?
To get your IP address. It will send a set of data messages like:
+CIPSTA.ip="10.0.0.205"
+CIPSTA.gateway="10.0.0.2"
+CIPSTA.netmash="255.255.255.0"
(sic?)
It will also send an
OK
The later you can expect, synchronously. i.e. you can spin waiting on OK or ERROR until you get a response or you give up in error.
The former, while expected in this example, can arrive at anytime asynchronously.
When you subscribe to an MQTT topic, for example, messages off the wire arrive randomly.
The code successfully splits data messages out from control response messages, allowing normal request/response style command/control to carry on, unaffected by the data flow. (In theory
[tm])
You can do things like subscribe and unsubscribe to channels while messages are still flowing and processing.
An example without error code:
Wifi_Enable();
Wifi_FactoryReset(); // TODO detect is already connecting with last saved by "WIFICONNECTED"
Wifi_Init();
Wifi_SetMode(WifiMode_Station)) {
Wifi_Station_ConnectToAp("cmmwguest", "guestguest", NULL);
Wifi_MQTT_Init(&mqttCfg);
Wifi_MQTT_Configure(&mqttCfg);
Wifi_MQTT_Connect(&mqttCfg);
Wifi_MQTT_Subscribe("home/clock", 0);
data_ch_t *ready_buffer = NULL;
while (ready_buffer == NULL) {
ready_buffer = DataChan_GetReadyBuffer();
}
// ready_buffer is your raw message
// some time later.....
DataChan_ReleaseReadyBuffer(&ready_buffer);
Next are functions parsing the MQTT raw messages into usable strings.
I'm thinking with a bit of tidy up I could put it on the public Git Hub. Anyone interested?
I've even thinking of creating a dev board already setup, so "maker style" IoT becomes and HomeAssistant stuff becomes far more accessible on STM32?
At least it will to me, and that's most important.
TODO list includes fixing the original ESP8266 library functions which request data, to use the data channel for data responses and the command channel for OK/ERROR.
TODO lots of code clean up
TODO add publish functions
TODO slap lip stick on it and push to gitlab/hub.