Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
yaming116 committed Sep 3, 2018
1 parent 8fcbb17 commit 4f4122e
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ long lastScheduleTime5000 = millis();
int count = 0;
const char *user = (&C.mqtt.user)->c_str();
const char *pass = (&C.mqtt.pass)->c_str();
const char *host = (&C.mqtt.host)->c_str();
String mqttHost = "";

WiFiClient espClient;
PubSubClient client(espClient);
Expand Down Expand Up @@ -182,6 +182,8 @@ void setup()
.init();

uint16_t port = (uint16_t)C.mqtt.port;
const char *host = (&C.mqtt.host)->c_str();
mqttHost = String(host);
Serial.println(host);
Serial.println(port);
Serial.println(user);
Expand Down Expand Up @@ -211,12 +213,14 @@ boolean reconnect()
client.subscribe(node_temperature_set_topic);
client.subscribe(node_mode_set_topic);

client.publish(node_toast, (String(node_heart_topic) + ','
+ String(node_study_topic) + ','
+ String(node_fan_set_topic) + ','
+ String(node_swing_set_topic) + ','
+ String(node_temperature_set_topic) + ','
+ String(node_mode_set_topic)).c_str());
client.publish(node_toast, node_heart_topic);

Serial.println(node_study_topic);
Serial.println(node_fan_set_topic);
Serial.println(node_swing_set_topic);
Serial.println(node_temperature_set_topic);
Serial.println(node_mode_set_topic);

}
delay(100);
return client.connected();
Expand Down Expand Up @@ -366,6 +370,7 @@ boolean downLoadFile(int index_id)
http.writeToStream(filestream);
SERIAL_DEBUG.printf("download %s ok\n", filename.c_str());
flag = true;
client.publish(node_toast, "download is ok");
}
else
{
Expand All @@ -379,6 +384,8 @@ boolean downLoadFile(int index_id)
return flag;
}
bool netRestart = false;
const long lastUnConnectTime = millis();
const long min_5 = 1000 * 60 * 5;
void loop()
{

Expand All @@ -392,11 +399,19 @@ void loop()
}
else
{

delay(500);
if (netRestart)
{
ESP.restart();
return;
}
delay(500);

if(millis() - lastUnConnectTime > min_5) {
ESP.restart();
return;
}

Serial.println("Wifi is not connect");
}
}
Expand Down Expand Up @@ -451,7 +466,7 @@ void callback(char *topic, byte *payload, unsigned int length)
root["wifi_ssid"] = &C.wifi.ssid;
root["wifi_user"] = &C.wifi.password;

root["mtqq_ip"] = host;
root["mtqq_ip"] = mqttHost;
root["mtqq_user"] = user;
root["mtqq_pass"] = pass;

Expand Down

0 comments on commit 4f4122e

Please sign in to comment.