amc2022:esp32_mqtt:start
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| amc2022:esp32_mqtt:start [2022/05/24 13:27] – created rolf001 | amc2022:esp32_mqtt:start [2023/01/05 14:38] (current) – external edit 127.0.0.1 | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== ESP32 MQTT Connection ====== | ====== ESP32 MQTT Connection ====== | ||
| + | |||
| + | {{https:// | ||
| ===== Jude's Code ===== | ===== Jude's Code ===== | ||
| - | <code> | + | <file c++ ESP32_MQTT_Jude_V001.ino> |
| - | #include <WiFi.h> | + | |
| - | #include < | + | |
| - | + | ||
| - | // WiFi | + | |
| - | const char *ssid = " | + | |
| - | const char *password = " | + | |
| - | + | ||
| - | // MQTT Broker | + | |
| - | const char *mqtt_broker = " | + | |
| - | const char *topic = " | + | |
| - | const char *mqtt_username = " | + | |
| - | const char *mqtt_password = " | + | |
| - | const int mqtt_port = 1883; | + | |
| - | + | ||
| - | WiFiClient espClient; | + | |
| - | PubSubClient client(espClient); | + | |
| - | + | ||
| - | void setup() { | + | |
| - | // Set software serial baud to 115200; | + | |
| - | | + | |
| - | // connecting to a WiFi network | + | |
| - | | + | |
| - | while (WiFi.status() != WL_CONNECTED) { | + | |
| - | | + | |
| - | | + | |
| - | } | + | |
| - | | + | |
| - | // | + | |
| - | | + | |
| - | | + | |
| - | while (!client.connected()) { | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | if (client.connect(client_id.c_str(), | + | |
| - | | + | |
| - | } else { | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | } | + | |
| - | } | + | |
| - | // publish and subscribe | + | |
| - | | + | |
| - | | + | |
| - | | + | |
| - | + | ||
| - | | + | |
| - | } | + | |
| - | void callback(char *topic, byte *payload, unsigned int length) { | + | TO BE UPDATED! |
| - | | + | |
| - | | + | |
| - | | + | |
| - | for (int i = 0; i < length; i++) { | + | |
| - | | + | |
| - | } | + | |
| - | | + | |
| - | | + | |
| - | } | + | |
| - | void loop() { | + | </file> |
| - | | + | |
| - | } | + | |
| - | </code> | + | |
amc2022/esp32_mqtt/start.1653391633.txt.gz · Last modified: 2023/01/05 14:38 (external edit)