   Serial.println("wait data");
   while (!net_client.available()) {
     Serial.println(".");
-    delay(100);
+    delay(200);
   }
 
   memset(buf, 0, 256);

  Serial.println("get_ip_port");
  get_ip_port(url, ip, &port);
  Serial.println("mqtt begin");
  g_mqtt_client.begin("182.92.180.87", 1883, g_net_client);

  Serial.println("mqtt connect");
  while (!g_mqtt_client.connect(g_client_id, g_username, g_password)) {
    Serial.println(".");
    LGPRS.attachGPRS(g_gprs_apn, g_gprs_username, g_gprs_password);
  }

  Serial.println("yunba ok");

  g_status = STATUS_IDLE;
}

void update_gps() {
  if (millis() - g_last_get_gps_ms > 10000) {
    LGPS.getData(&g_gps_info);
    Serial.println("gps: " + String((char *)g_gps_info.GPGGA));
    g_last_get_gps_ms = millis();
    g_need_report = true;
  }
}

void handle_report() {
  if (!g_need_report) {
    return;
  }

  StaticJsonBuffer<JSON_BUF_SIZE> json_buf;
  JsonObject& root = json_buf.createObject();
  root["lock"] = is_locked();
  root["gps"] = (char *)g_gps_info.GPGGA;

  String json;
  root.printTo(json);

  Serial.println("publish: " + json);
  g_mqtt_client.publish(g_report_topic, json);
  g_need_report = false;
}

void unlock() {
  if (!is_locked()) {
    Serial.println("not locked now");
    return;
  }

  Serial.println("unlocking");
}

void handle_msg(String &msg) {
  StaticJsonBuffer<JSON_BUF_SIZE> json_buf;
  JsonObject& root = json_buf.parseObject(msg);
  if (!root.success()) {
    Serial.println("parse json failed");
    return;
  }

  String cmd = root["cmd"];
  if (cmd == "unlock") {
    unlock();
  }
}

/* messageReceived and extMessageReceived must be defined with no 'static', because MQTTClient use them */
void messageReceived(String topic, String payload, char *bytes, unsigned int length) {
  Serial.println("msg: " + topic + ", " + payload);
  handle_msg(payload);
}

void extMessageReceived(EXTED_CMD cmd, int status, String payload, unsigned int length) {
  //  Serial.println("ext msg: " + String(cmd) + ", " + payload);
}

void setup() {
