Skip to content

Commit

Permalink
práce off-line
Browse files Browse the repository at this point in the history
  • Loading branch information
ma-ta committed Jul 24, 2021
1 parent ba88e85 commit 182f7a2
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
1 change: 1 addition & 0 deletions telethermo/nastaveni.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const String JEDNOTKY = "°C"; // pouze popis pro uživatele (nezmění použit
// časový odstup mezi úkony
const int CETNOST_MERENI = (1000) * 9; // [ms] jak často měřit teplotu
const int CETNOST_UPLOAD = (1000) * 60; // [ms] jak často nahrávat na ThingSpeak
#define WIFI_VYCKEJ 20000 // [ms] doba čekání na Wi-Fi připojení po spuštění
// výchozí teplota (není-li k dispozici aktuální hodnota)
const float TEPLOTA_NULL = -999.0;
// baud rate sériové linky
Expand Down
60 changes: 37 additions & 23 deletions telethermo/telethermo.ino
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
float teplota_0 = TEPLOTA_NULL;
float teplota_1 = TEPLOTA_NULL;
String ipString = NAZEV_PRODUKTU;
bool status_online = false;

// Funkce displeje
#include "displej.h"
Expand All @@ -15,22 +16,34 @@ IPAddress ip;

void setup() {
Serial.begin(SERIAL_BAUD);
delay(1000);
delay(2000);
Serial.println("Zapnuto\n");

inicializaceDispleje();
ui.update();

WiFi.mode(WIFI_STA);
WiFi.begin(WIFI_NAZEV, WIFI_HESLO);
Serial.print("Pripojuji se k Wi-Fi: " + String(WIFI_NAZEV));
// Wait for connection

// Čekání na Wi-Fi připojení
unsigned long cas = millis();
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
if (millis() > cas + WIFI_VYCKEJ) {
Serial.println("\nNepodarilo se pripojit - pracuji OFF-LINE!");
break;
}
}

if (WiFi.status() == WL_CONNECTED) {
status_online = true;
Serial.print("\nIP adresa: ");
ip = WiFi.localIP();
Serial.println(ip);
inicializaceServeru();
}
Serial.print("\nIP adresa: ");
ip = WiFi.localIP();
Serial.println(ip);

inicializaceServeru();

sensors.begin();
delay(750);
Expand All @@ -43,8 +56,6 @@ void setup() {

Serial.println("\n" + THERMO_0 + ": " + String(teplota_0, 1) + " " + JEDNOTKY);
Serial.println(THERMO_1 + ": " + String(teplota_1, 1) + " " + JEDNOTKY);

inicializaceDispleje();

}

Expand All @@ -67,21 +78,24 @@ void loop() {
Serial.println(THERMO_1 + ": " + String(teplota_1, 1) + " " + JEDNOTKY);
}

if ((millis() % CETNOST_UPLOAD) < 100) {
thingSpeakUpload();
}
if (status_online) {

ip = WiFi.localIP();
ipString = \
String(ip[0]) + "." \
+ String(ip[1]) + "." \
+ String(ip[2]) + "." \
+ String(ip[3]);

mdns.update();
server.handleClient();

delay(remainingTimeBudget);
if ((millis() % CETNOST_UPLOAD) < 100) {
thingSpeakUpload();
}

ip = WiFi.localIP();
ipString = \
String(ip[0]) + "." \
+ String(ip[1]) + "." \
+ String(ip[2]) + "." \
+ String(ip[3]);

mdns.update();
server.handleClient();

delay(remainingTimeBudget);
}
}

}

0 comments on commit 182f7a2

Please sign in to comment.