From a145dc9a9c745a643daefa01ea8df4e2a25b2757 Mon Sep 17 00:00:00 2001 From: Mathieu Maret Date: Mon, 14 Mar 2016 18:05:14 +0100 Subject: [PATCH] Home page show mqtt status --- WifiControlSensor/MQTT.ino | 4 ++++ WifiControlSensor/WebServer.ino | 1 + WifiControlSensor/WifiControlSensor.ino | 1 + 3 files changed, 6 insertions(+) diff --git a/WifiControlSensor/MQTT.ino b/WifiControlSensor/MQTT.ino index a6a4fe8..146a66a 100644 --- a/WifiControlSensor/MQTT.ino +++ b/WifiControlSensor/MQTT.ino @@ -26,6 +26,10 @@ int setupMQTT(char *server, char *user, char *passwd, int port) { return 0; } +int MQTT_isConnected(){ + return mqtt->connected(); +} + // Function to connect and reconnect as necessary to the MQTT server. // Should be called in the loop function and it will take care if connecting. int MQTT_connect() { diff --git a/WifiControlSensor/WebServer.ino b/WifiControlSensor/WebServer.ino index 57fce3a..6a6c84f 100644 --- a/WifiControlSensor/WebServer.ino +++ b/WifiControlSensor/WebServer.ino @@ -1,6 +1,7 @@ void handleRoot() { server.send(200, "text/html", "

You are connected


" "Current temperature " + String(temp, 2) + "C
" + "MQTT Status :" + (MQTT_isConnected()? "Connected":"Disconnected") +"
" "Setup
" "OTA mode
" "ON
" diff --git a/WifiControlSensor/WifiControlSensor.ino b/WifiControlSensor/WifiControlSensor.ino index 67acc21..d7bcb5f 100644 --- a/WifiControlSensor/WifiControlSensor.ino +++ b/WifiControlSensor/WifiControlSensor.ino @@ -70,6 +70,7 @@ int getTemperature(double &t); /* MQTT decl */ int MQTT_connect(); +int MQTT_isConnected(); int setupMQTT(char *server, char *user, char *passwd, int port); int publishMQTT(int temp);