#esp32-modem-freeRTOS
- Board esp32 by Espressif Systems 3.0.7
- WiFi.h v1.2.7
- HTTPClient v2.2.0
- EspMQTTClient.h v1.13.3
- TimeLib v1.6.1
- esp32-BG95 v1.0.5
Edit editable_macros.h file to change macros according to your needs Check examples folder to see examples. Each example imports a credentials.h file that is not present on this repository. You have to create it at your own
Create the "credentials.h" file in demo-mqtt folder Edit the file according to your setup
// WIFI credentials
#define WIFI_SSID "ssid"
#define WIFI_PASSWORD "password"
// MQTT credentials
#define MQTT_HOST_1 "mqtt host"
#define MQTT_PORT_1 1883
#define MQTT_USER_1 "device"
#define MQTT_PASSWORD_1 "device"
#define MQTT_PROJECT "esp32/freeRTOS2"
#define MQTT_UID_PREFIX "uid:"
#define MQTT_WILL_SUBTOPIC "status"
#define MQTT_WILL_PAYLOAD "offline"
All topics start with the prefix :project/:uid/... ':project' and ':uid' are passed with mqtt_configure_connection method
This library implements an independent process to manage LTE and WiFi interfaces
- Manage APN connection (LTE)
- Manage Context connection (LTE)
- Manage WIFI connection
- Manage TCP+SSL multi-connection (LTE for now)
- Manage MQTT/MQTTS multi-connection (WIFI+LTE)
- Manage HTTP/HTTPS multi-requests (WIFI+LTE)
- Read messages from Queue and sends to modem
- Get messages from modem and write on respective Queue
- SMS not supported for now
- HTTP (WIFI/LTE)
- HTTPS (WIFI/LTE)
- MQTT (WIFI/LTE)
- TCP (LTE)
void init(const char* ssid, const char* password) void init(uint16_t cops, uint8_t mode, uint8_t pwkey) void loop() bool set_context(uint8_t contextID, String apn, String user, String pwd)
void tcp_configure_connection(uint8_t clientID, uint8_t contextID, String host, uint16_t port) void tcp_setup(void(*callback1)(uint8_t clientID),void(*callback2)(uint8_t clientID)) TCP_MSG* tcp_getNextMessage(TCP_MSG *pxRxedMessage) bool tcp_pushMessage(uint8_t clientID, const char* data, uint16_t len)
bool http_pushMessage(uint8_t contextID, uint8_t clientID, String host, String path, String method) HTTP_HEADER_MSG* http_header_getNextMessage(HTTP_HEADER_MSG *pxRxedMessage) HTTP_BODY_MSG* http_body_getNextMessage(HTTP_BODY_MSG *pxRxedMessage)
void mqtt_configure_connection(uint8_t clientID, uint8_t contextID, String project, String uid, String host, uint16_t port, String user, String pwd) void mqtt_set_will_topic(uint8_t clientID, String topic, String payload) void mqtt_add_subscribe_topic(uint8_t clientID, uint8_t index, String topic) void mqtt_setup(void(*callback)()) bool mqtt_pushMessage(uint8_t clientID, const String& topic, const String& message, uint8_t qos, uint8_t retain) MQTT_MSG* mqtt_getNextMessage(MQTT_MSG *pxRxedMessage)
Run programs inside examples folder to check how it works
Establishes connection to a server, do a request and reads its response
Two processes running simultaneously: - One process is controlling the modem and executing requests - The other one is used to send and received requests to and from the first process
Two processes running simultaneously: - One process is controlling the modem, handling mqtt connection and executing requests - The other one is used to send and received requests to and from the first process
Not available for now
Not available for now
void init(const char* ssid, const char* password);
void init(uint16_t cops, uint8_t mode, uint8_t pwkey);
void loop();
bool set_context(uint8_t contextID, String apn, String user, String pwd);
#TCP configure connection
- call it before tcp_setup
- changes tcp connection parameters
- while clientID has contextID != 0, loop function will try to keep connection activated
- @clientID 0-5, limited to MAX_TCP_CONNECTIONS defined in bgxx library
- @contextID 1-16, limited to MAX_CONNECTIONS defined in bgxx library
- @host - IP or DNS of server
- @port
void tcp_configure_connection(uint8_t clientID, uint8_t contextID, String host, uint16_t port)
#TCP setup
- configures callbacks to be called when connection is established and closed
void tcp_setup(void(*callback1)(uint8_t clientID),void(*callback2)(uint8_t clientID))
#TCP getNextMessage
- use it to get received messages.
- returns a pointer to TCP_MSG struct containing the received message
- if no message is available it returns NULL
TCP_MSG* tcp_getNextMessage(TCP_MSG *pxRxedMessage)
#TCP pushMessage
- use it to send tcp messages
- @clientID 0-5, tcp index client
- @data - payload to be sent
- @len - payload len
- @retain true|false
bool tcp_pushMessage(uint8_t clientID, const char* data, uint16_t len)
- use it to do http requests
- @contextID 1-11, context id
- @clientID 0-5, tcp index client
- @host
- @port
- @path
- @method
bool http_pushMessage(uint8_t contextID, uint8_t clientID, String host, String path, String method)
- use it to get http header messages.
- returns a pointer to HTTP_HEADER_MSG struct containing the received message
- if no message is available it returns NULL
HTTP_HEADER_MSG* http_header_getNextMessage(HTTP_HEADER_MSG *pxRxedMessage)
- use it to get http body messages.
- returns a pointer to HTTP_BODY_MSG struct containing the received message
- if no message is available it returns NULL
HTTP_BODY_MSG* http_body_getNextMessage(HTTP_BODY_MSG *pxRxedMessage)
void mqtt_configure_connection(uint8_t clientID, uint8_t contextID, String project, String uid, String host, uint16_t port, String user, String pwd);
void mqtt_set_will_topic(uint8_t clientID, String topic, String payload);
void mqtt_add_subscribe_topic(uint8_t clientID, uint8_t index, String topic);
void mqtt_setup(void(*callback)());
bool mqtt_pushMessage(uint8_t clientID, const String& topic, const String& message, uint8_t qos, uint8_t retain);
void init(uint16_t cops, uint8_t mode, uint8_t pwkey);