   }
 }
 
+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) {


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

  if (appkey == NULL) return false;


    char *p = (char *)buf + 3;
    if (len == strlen(p)) {
      Serial.println(p);
      StaticJsonBuffer<JSON_BUFSIZE> jsonBuffer;
      JsonObject& root = jsonBuffer.parseObject(p);
      if (root.success()) {
        strcpy(username, root["u"]);
