From 07c96c19a53c2ecafdfe0cdc3fc72a1c71966f3c Mon Sep 17 00:00:00 2001 From: hsaturn Date: Mon, 22 Mar 2021 02:35:34 +0100 Subject: [PATCH] Better simple-client example --- examples/simple-client/simple-client.ino | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/examples/simple-client/simple-client.ino b/examples/simple-client/simple-client.ino index 484ae3e..45d1693 100644 --- a/examples/simple-client/simple-client.ino +++ b/examples/simple-client/simple-client.ino @@ -16,6 +16,9 @@ #include +static float temp=19; +static MqttClient client; + void setup() { Serial.begin(115200); @@ -29,8 +32,18 @@ void setup() { delay(500); Serial << '.'; } Serial << "Connected to " << ssid << "IP address: " << WiFi.localIP() << endl; + + client.connect("192.168.1.40", 1883); // Put here your broker ip / port + } void loop() { + client.loop(); + + delay(1000); + + temp += (random(100)>50 ? 0.1 : -0.1); + client.publish("sensor/temperature", String(temp)); + }