25 lines
589 B
C++
25 lines
589 B
C++
#include <WiFi.h>
|
|
#include <PubSubClient.h>
|
|
|
|
// WiFi
|
|
const char *ssid = "xxxxx"; // Enter your WiFi name
|
|
const char *password = "xxxxx"; // Enter WiFi password
|
|
|
|
// MQTT Broker
|
|
const char *mqtt_broker = "";
|
|
const char *topic = "reinhold/test";
|
|
const int mqtt_port = 1883;
|
|
const char *client_id = "m5-esp";
|
|
|
|
Wifi.begin(ssid, password);
|
|
|
|
client.setServer(mqtt_broker, mqtt_port);
|
|
client.setCallback(callback);
|
|
client.connect(client_id.c_str());
|
|
|
|
|
|
void callback(char *topic, byte *payload, unsigned int length) {
|
|
for (int i = 0; i < length; i++) {
|
|
Serial.print((char) payload[i]);
|
|
}
|
|
} |