diff --git a/arduino_mqtt/arduino_mqtt.ino b/arduino_mqtt/arduino_mqtt.ino
index c0b635f..e49c9a1 100644
--- a/arduino_mqtt/arduino_mqtt.ino
+++ b/arduino_mqtt/arduino_mqtt.ino
@@ -1,5 +1,5 @@
#include
-#include
+#include
#include
#include
#include
@@ -29,6 +29,7 @@ const char* mqttServer = "192.168.1.11";
const int mqttPort = 1883;
const char* mqttUser = "yourMQTTuser";
const char* mqttPassword = "yourMQTTpassword";
+const char topic[] = "solar/114182126368/0/power";
//Diplay and DHT update data
long previousMillis = 0;
@@ -41,22 +42,44 @@ float temperature;
//Start WiFi client
WiFiClient espClient;
-PubSubClient MQTTclient(espClient);
+MqttClient MQTTclient(espClient);
-void callback(char* topic, byte* payload, unsigned int length) {
+// void callback(char* topic, byte* payload, unsigned int length) {
- Serial.print("Message arrived in topic: ");
- Serial.println(topic);
+// Serial.print("Message arrived in topic: ");
+// Serial.println(topic);
- Serial.print("Message:");
+// Serial.print("Message:");
+// global_power = "";
+// for (int i = 0; i < length; i++) {
+// Serial.print((char)payload[i]);
+// global_power += char(payload[i]);
+// }
+// }
+
+void onMqttMessage(int messageSize) {
+ // Serial.println("Received a message with topic '");
+ // Serial.print(MQTTclient.messageTopic());
+ // Serial.print("', length ");
+ // Serial.print(messageSize);
+ // Serial.println(" bytes:");
+
global_power = "";
- for (int i = 0; i < length; i++) {
- Serial.print((char)payload[i]);
- global_power += char(payload[i]);
+ while (MQTTclient.available()) {
+ //Serial.print((char)MQTTclient.read());
+ global_power += char(MQTTclient.read());
}
-}
+ // Serial.println(global_power);
+ // Serial.println();
+}
void showDisplay() {
+ //int length = global_power.length();
+ //Serial.println(lenght);
+ if (global_power.length() > 5) {
+ global_power = global_power.substring(0,global_power.length()-1);
+ }
+
display.clearDisplay();
display.setTextSize(1);
display.setTextColor(WHITE);
@@ -92,11 +115,29 @@ String prepareHtmlPage()
htmlPage += F("
"
"Humidity: ");
htmlPage += humidity;
+ htmlPage += "
";
+ htmlPage += F(""
+ "MQTT Connected: ");
+ htmlPage += MQTTclient.connected();
htmlPage += "
";
htmlPage += F("