zarizeni:wemos_d1_htu21d
no way to compare when less than two revisions
Rozdíly
Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.
| — | zarizeni:wemos_d1_htu21d [2020/10/30 12:56] (aktuální) – vytvořeno multitricker | ||
|---|---|---|---|
| Řádek 1: | Řádek 1: | ||
| + | ====== WeMos D1 + HTU21D ====== | ||
| + | Úpravu skriptu od mikroma pro WeMos D1 s čidlem HTU21D provedl Martin Čapek [[Martin_Capek@seznam.cz]] | ||
| + | |||
| + | <code c> | ||
| + | // Simple sketch for sending data to the TMEP.cz | ||
| + | // by mikrom (http:// | ||
| + | // http:// | ||
| + | // modify by Martin_Capek@seznam.cz | ||
| + | // If you send only temperature url will be: http:// | ||
| + | // If you send also humidity url will be: http:// | ||
| + | // but for humidity You will need HTU21D or Si7021 (not tested) sensor and code will need some modifications | ||
| + | // | ||
| + | // Not tested, but should work! :) | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | #include < | ||
| + | #include < | ||
| + | #include < | ||
| + | |||
| + | // Define settings | ||
| + | |||
| + | const char ssid[] | ||
| + | const char pass[] | ||
| + | const char domain[] | ||
| + | const char guid[] | ||
| + | const long sleep = 60000; | ||
| + | |||
| + | void setup() { | ||
| + | // Start serial | ||
| + | Wire.begin(); | ||
| + | Serial.begin(9600); | ||
| + | delay(10); | ||
| + | Serial.println(); | ||
| + | |||
| + | // Connect to the WiFi | ||
| + | Serial.print(" | ||
| + | WiFi.begin(ssid, | ||
| + | while (WiFi.status() != WL_CONNECTED) { | ||
| + | delay(500); | ||
| + | Serial.print(" | ||
| + | } | ||
| + | Serial.println(); | ||
| + | Serial.println(" | ||
| + | Serial.print(" | ||
| + | Serial.println(); | ||
| + | |||
| + | delay(10000); | ||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | // Reading temperature or humidity from HTU21D | ||
| + | float h = SHT2x.GetHumidity(); | ||
| + | // Read temperature as Celsius (the default) | ||
| + | float t = SHT2x.GetTemperature(); | ||
| + | |||
| + | // Check if any reads failed and exit early (to try again). | ||
| + | if (isnan(h) || isnan(t)) { | ||
| + | Serial.println(" | ||
| + | return; | ||
| + | } | ||
| + | |||
| + | // Connect to the HOST and send data via GET method | ||
| + | WiFiClient client; // Use WiFiClient class to create TCP connections | ||
| + | |||
| + | char host[50]; | ||
| + | strcpy(host, | ||
| + | strcat(host, | ||
| + | const int httpPort = 80; | ||
| + | |||
| + | Serial.print(" | ||
| + | if (!client.connect(host, | ||
| + | // If you didn't get a connection to the server | ||
| + | Serial.println(" | ||
| + | return; | ||
| + | } | ||
| + | Serial.println(" | ||
| + | |||
| + | // Make an url. We need: /? | ||
| + | String url = "/?"; | ||
| + | url += guid; | ||
| + | url += " | ||
| + | url += t; | ||
| + | url += "& | ||
| + | url += h; | ||
| + | Serial.print(" | ||
| + | |||
| + | // Make a HTTP GETrequest. | ||
| + | client.print(String(" | ||
| + | " | ||
| + | " | ||
| + | |||
| + | // Workaroud for timeout | ||
| + | unsigned long timeout = millis(); | ||
| + | while (client.available() == 0) { | ||
| + | if (millis() - timeout > 5000) { | ||
| + | Serial.println(">>> | ||
| + | client.stop(); | ||
| + | return; | ||
| + | } | ||
| + | } | ||
| + | |||
| + | Serial.println(); | ||
| + | |||
| + | // Wait for another round | ||
| + | delay(sleep); | ||
| + | } | ||
| + | </ | ||