 #include <Ticker.h>
 #include "/usr/local/src/rpi2_setting.h"
 
+extern "C" {
+#include "user_interface.h"
+}
+
 #define BUTTON_PIN 0
 #define RELAY_PIN 12
 #define LED_PIN 13
 
-#define BETWEEN_RELAY_ACTIVE 5000
+#define BETWEEN_RELAY_ACTIVE 1000
 
 IPAddress mqtt_server = MQTT_SERVER;
 
-char* subscribe_topic = "light/bedroomlight";
+const char* subscribe_topic = "light/bedroomlight";
+const char* reporting_topic = "light/bedroomlight/report";
+
 long lastReconnectAttempt = 0;
 volatile bool bUpdated = false;
 volatile bool bRelayState = false;

    if (bRelayReady)
    {
      change_light();
      lastRelayActionmillis = millis();
      bUpdated = false;
    }

  digitalWrite(LED_PIN, !state);     // set pin to the opposite state
}

bool ICACHE_RAM_ATTR sendmqttMsg(const char* topictosend, String payloadtosend, bool retain = false)
{
  unsigned int msg_length = payloadtosend.length();

  byte* p = (byte*)malloc(msg_length);
  memcpy(p, (char*) payloadtosend.c_str(), msg_length);

  if (client.publish(topictosend, p, msg_length, retain))
  {
    free(p);
    client.loop();

    Serial.print("[MQTT] out topic : ");
    Serial.print(topictosend);
    Serial.print(" payload: ");
    Serial.print(payloadtosend);
    Serial.println(" published");

    return true;

  } else {
    free(p);
    client.loop();

    Serial.print("[MQTT] out topic : ");
    Serial.print(topictosend);
    Serial.print(" payload: ");
    Serial.print(payloadtosend);
    Serial.println(" publish failed");

    return false;
  }
}

void ICACHE_RAM_ATTR sendCheck()
{
  String payload;
  if (bRelayState)
  {
      payload = "on";
  }
  else
  {
      payload = "false";
  }
  sendmqttMsg(reporting_topic, payload, true);
}

void ICACHE_RAM_ATTR parseMqttMsg(String receivedpayload, String receivedtopic)
{
  char json[] = "{\"cmd\":\"off\"}";
