ESP32 version that could work

This commit is contained in:
hsaturn
2021-04-10 17:47:21 +02:00
parent 6afd3939b3
commit ba6a96976a
2 changed files with 13 additions and 5 deletions

View File

@@ -1,10 +1,12 @@
#include <ESP8266WiFi.h>
#include "TinyMqtt.h" // https://github.com/hsaturn/TinyMqtt #include "TinyMqtt.h" // https://github.com/hsaturn/TinyMqtt
/** Simple Client /** Simple Client
* *
* This is the simplest Mqtt client configuration * This is the simplest Mqtt client configuration
* *
* 1 - edit my_credentials.h to setup wifi essid/password
* 2 - change BROKER values (or keep emqx.io test broker)
*
* pro - small memory footprint (both ram and flash) * pro - small memory footprint (both ram and flash)
* - very simple to setup and use * - very simple to setup and use
* *
@@ -13,6 +15,9 @@
* - local publishes takes more time (because they go outside) * - local publishes takes more time (because they go outside)
*/ */
const char* BROKER = "broker.emqx.io";
const uint16_t BROKER_PORT = 1883;
#include <my_credentials.h> #include <my_credentials.h>
static float temp=19; static float temp=19;
@@ -32,8 +37,7 @@ void setup()
Serial << "Connected to " << ssid << "IP address: " << WiFi.localIP() << endl; Serial << "Connected to " << ssid << "IP address: " << WiFi.localIP() << endl;
client.connect("192.168.1.40", 1883); // Put here your broker ip / port client.connect(BROKER, BROKER_PORT); // Put here your broker ip / port
} }
void loop() void loop()

View File

@@ -1,6 +1,10 @@
#pragma once #pragma once
#include <ESP8266WiFi.h> #ifdef ESP8266
#include <ESPAsyncTCP.h> #include <ESPAsyncTCP.h>
#elif defined(ESP32)
#include <WiFi.h>
#include <AsyncTCP.h> // https://github.com/me-no-dev/AsyncTCP
#endif
#include <vector> #include <vector>
#include <set> #include <set>
#include <string> #include <string>