 #include <ESP8266mDNS.h>
 #include <WiFiUdp.h>
 #include <ArduinoOTA.h>
+#include <WiFiClientSecure.h>
 #include <PubSubClient.h>
 #include <TimeLib.h>
 #include <ArduinoJson.h>

#define COOL_PIN 5
#define HEAT_PIN 4

#include "/usr/local/src/ap_setting.h"
const char* reporting_topic = "esp8266/nestbridge";

IPAddress mqtt_server = MQTT_SERVER;


  sendmqttMsg(reporting_topic, json, false);
}

void ICACHE_RAM_ATTR send_ac_cmd()
{
  DynamicJsonBuffer jsonBuffer;
  JsonObject& root = jsonBuffer.createObject();
  root["AC"] = !digitalRead(COOL_PIN);
  String json;
  root.printTo(json);

  sendmqttMsg(topic_ac_cmd, json, true);
}

void ICACHE_RAM_ATTR callback(char* intopic, byte* inpayload, unsigned int length)
{
}

bool verifytls()
{

  if (!sslclient.connect(mqtt_server, 8883))
  {
    return false;
  }

  if (sslclient.verify(MQTT_FINGERPRINT, MQTT_SERVER_CN))
  {
    sslclient.stop();
    return true;
  }
  else
  {
    sslclient.stop();
    return false;
  }
}

boolean reconnect()
{
  if (!client.connected())
  {
   if (verifytls())
   {
      if (client.connect((char*) clientName.c_str(), MQTT_USER, MQTT_PASS))
      {
         if ( ResetInfo == LOW) {
            client.publish(hellotopic, (char*) getResetInfo.c_str());
            ResetInfo = HIGH;
         } else {
            client.publish(hellotopic, "hello again 1 from nestbridge");
         }
         Serial.println("[MQTT] mqtt connected");
      }
      else
      {
         Serial.print("[MQTT] mqtt failed, rc=");
         Serial.println(client.state());
      }
   }
  }
  return client.connected();
}
