Neviem čo robí v pôvodnom sketch funkcia return ak !client.connected, ktorá je tam bez parametra. Neviem, čo vracia, príde mi, že tam v kóde skončí, je to tak?
Kód: Vybrat vše
if (!client.connect(host, httpsPort)) {
return;
}
Ďalej mám otázku k samotnému requestu..
Vzorový kód obsahuje takúto štruktúru (example code):
Kód: Vybrat vše
WiFiClientSecure client;
if (!client.connect(host, httpsPort)) {
return;
}
if (client.verify(fingerprint, host)) {
}
else {
}
String url = "/system/values/vzdialenyrestart.txt";
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "User-Agent: NodeMCU\r\n" + "Connection: close\r\n\r\n");
.
.
.
.
Je dobré používať pre overenia pripojenia klienta niečo v štýle:
Kód: Vybrat vše
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
Kód: Vybrat vše
WiFiClientSecure client;
if (!client.connect(host, httpsPort)) {
Serial.println("Ovladanie termostatu - offline rezim");
sensors.requestTemperatures();
delay(500);
String teplota1 = String (sensors.getTempCByIndex(0));
float teplota1f = teplota1.toFloat();
if((referenciatermostat-teplota1f)>1){
digitalWrite(termostat, LOW);
}else if((referenciatermostat-teplota1f)<-1){
digitalWrite(termostat, HIGH);
}
}
if (client.verify(fingerprint, host)) {
}
else {
}
if (client.connect(host, httpsPort)) {
String url = "/rosko/system/values/termostat.txt";
client.print(String("GET ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "User-Agent: NodeMCU\r\n" + "Connection: close\r\n\r\n");