Author Topic: ESP32 + AT Firmware V2.4.0 + STM32 Lib  (Read 647 times)

0 Members and 1 Guest are viewing this topic.

Offline paulcaTopic starter

  • Super Contributor
  • ***
  • Posts: 4078
  • Country: gb
ESP32 + AT Firmware V2.4.0 + STM32 Lib
« on: October 31, 2022, 04:30:24 pm »
Quiet day at work.  So.

Starting with this: https://github.com/jrmejiaa/ESP8266

I 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:

Code: [Select]
AT+CIPSTA?
To get your IP address.  It will send a set of data messages like:
Code: [Select]
+CIPSTA.ip="10.0.0.205"
+CIPSTA.gateway="10.0.0.2"
+CIPSTA.netmash="255.255.255.0"
(sic?)

It will also send an

Code: [Select]
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:

Code: [Select]
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.
"What could possibly go wrong?"
Current Open Projects:  STM32F411RE+ESP32+TFT for home IoT (NoT) projects.  Child's advent xmas countdown toy.  Digital audio routing board.
 
The following users thanked this post: ozkarah


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf