   }
 }
 
+void plug_set(uint8_t status) {
+  if (status == 0) {
+    Serial.println(0);
+    digitalWrite(PIN_CONTROL, LOW);
+  } else if (status == 1) {
+    Serial.println(1);
+    digitalWrite(PIN_CONTROL, HIGH);
+  }
+}
+
 void messageReceived(String topic, String payload, char *bytes, unsigned int length) {
+  StaticJsonBuffer<JSON_BUFSIZE> jsonBuffer;
   Serial.println("m");
+//  Serial.println(length);
+//  Serial.println(bytes);
+
+  JsonObject& root = jsonBuffer.parseObject(bytes);
+  if (!root.success()) {
+    Serial.println("bad json");
+    return;
+  }
+
+  if (strcmp(root["devid"], g_devid) != 0) {
+    Serial.println("bad devid");
+    return;
+  }
+
+  if (strcmp(root["cmd"], "plug_set") == 0) {
+    uint8_t st = root["status"];
+    plug_set(st);
+  }
 }
 
 void extMessageReceived(EXTED_CMD cmd, int status, String payload, unsigned int length) {


const char *g_appkey = "56a0a88c4407a3cd028ac2fe";
const char *g_topic = "office";
const char *g_devid = "plug";

#define BUFSIZE 128

uint8_t mac[] = {0xb0, 0x5a, 0xda, 0x3a, 0x2e, 0x7e};



bool setup_with_appkey_and_devid(const char *appkey, const char *devid) {
  uint8_t buf[BUFSIZE];

  if (appkey == NULL) return false;

