     }
   }
 
-  Serial.println("e2");
+  Serial.println("es");
   return false;
 }
 
 void set_alias(const char *alias) {
-  client.publish(",yali", alias);
-}
-
-void connect_yunba() {
-  Serial.println("rc..");
-  while (!client.connect(client_id, username, password)) {
-    init_network();
-    Serial.println(".");
+  mqtt_client->publish(",yali", alias);
+}
+
+void mqtt_connect() {
+  Serial.println("cn.."); // connecting
+  while (!mqtt_client->connect(client_id, username, password)) {
+    Serial.println("..");
     delay(1000);
   }
 
-//  client.subscribe(g_topic);
+  Serial.println("co"); // connect ok
+
+//  mqtt_client->subscribe(g_topic);
   set_alias(g_devid);
 }
 
 void check_connect() {
   if (millis() - g_last_check_ms > 2000) {
-    boolean st = client.connected();
+    boolean st = mqtt_client->connected();
 //    Serial.println(st);
     if (st != g_net_status) {
-      Serial.print("cst:");
+      Serial.print("cs:");
       g_net_status = st;
       Serial.println(g_net_status);
     }
 
     if (!st) {
-      connect_yunba();
+      mqtt_client->disconnect();
+      delete(mqtt_client);
+      init_network();
     }
     g_last_check_ms = millis();
   }

  data += String("\"}");

  Serial.println(data);
  client.publish(g_topic, data.c_str());
}

void messageReceived(String topic, String payload, char *bytes, unsigned int length) {


void init_ethernet() {
//  IPAddress ip(192,168,2,183);
//  Ethernet.begin(mac, ip);

  Serial.println("ie.."); // init ethernet
  while (!Ethernet.begin(mac)) {
    Serial.println("..");
    delay(1000);
  }

