   unsigned long intervalon;  // ms
   unsigned long intervaloff; // ms
   unsigned long timerMillis;
+  unsigned long nextTimercheck;
 } ir_data;
 
+// mqtt
+void callback(char* intopic, byte* inpayload, unsigned int length);
+
+const char* hellotopic  = "HELLO";
+const char* willTopic   = "clients/nodemcu";
+const char* willMessage = "0";
+const char* substopic   = "esp8266/arduino/solar";
+
+String clientName;
+
+PubSubClient mqttclient(mqtt_server, 1883, callback, wifiClient);
+
+// Timelib
+unsigned int localPort = 12390;
+const int timeZone = 9;
+
+// temp received by mqtt
+Average<float> ave(20);
+
+// ir
 IRrecv irrecv(IR_RX_PIN);
 lgWhisen lgWhisen;
+
+boolean reconnect() {
+  if (!mqttclient.connected())
+  {
+    if (mqttclient.connect((char*) clientName.c_str(), willTopic, 0, true, willMessage))
+    {
+      mqttclient.publish(willTopic, "1", true);
+      mqttclient.loop();
+      mqttclient.publish(hellotopic, "hello again 1 from nodemcu ");
+      mqttclient.loop();
+      mqttclient.subscribe(substopic);
+      mqttclient.loop();
+      yield();
+    }
+  }
+  return mqttclient.connected();
+}
+
+void ICACHE_RAM_ATTR callback(char* intopic, byte* inpayload, unsigned int length)
+{
+  String receivedtopic = intopic;
+  String receivedpayload ;
+
+  for (int i = 0; i < length; i++) {
+    receivedpayload += (char)inpayload[i];
+  }
+
+  Serial.printf("[MQTT] payload: %s\n", receivedpayload.c_str());
+  if (length <= 200)
+  {
+    parseMqttMsg(receivedpayload, receivedtopic);
+  }
+}
+
+void parseMqttMsg(String receivedpayload, String receivedtopic)
+{
+  char json[] = "{\"DS18B20\":28.00,\"FreeHeap\":32384,\"RSSI\":-74,\"millis\":2413775}";
+
+  receivedpayload.toCharArray(json, 200);
+  StaticJsonBuffer<200> jsonBuffer;
+  JsonObject& root = jsonBuffer.parseObject(json);
+
+  if (!root.success()) {
+    return;
+  }
+
+  if (root.containsKey("DS18B20"))
+  {
+    ave.push(root["DS18B20"]);
+  }
+}
 
 void chane_ac_temp_flow()
 {

  Returns true if the connection was established successfully.
*/
bool connectToSlack()
{
  // Step 1: Find WebSocket address via RTM API (https://api.slack.com/methods/rtm.start)
  HTTPClient http;
  String uri_to_post = "/api/rtm.start?token=";
  uri_to_post += SLACK_BOT_TOKEN;

#include <ESP8266mDNS.h>
#include <ArduinoOTA.h>
#include <WiFiUdp.h>
#include <Average.h>

extern "C" {
#include "user_interface.h"
}
#include "/usr/local/src/ap_setting.h"
#include "/usr/local/src/slack_setting.h"

const char* api_fingerprint = "AB F0 5B A9 1A E0 AE 5F CE 32 2E 7C 66 67 49 EC DD 6D 6A 38";

