zarizeni:esp8266
Rozdíly
Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.
Následující verzeObě strany příští revize | |||
zarizeni:esp8266 [2016/05/30 10:01] – vytvořeno multitricker | zarizeni:esp8266 [2016/05/30 10:07] – multitricker | ||
---|---|---|---|
Řádek 8: | Řádek 8: | ||
Nezapomeňte na začátku kódu nastavit své správné proměnné (SSID vlastní wifi, heslo k wifi síti, správnou adresu serveru a GUID vyplněné v administraci na tmep.cz). | Nezapomeňte na začátku kódu nastavit své správné proměnné (SSID vlastní wifi, heslo k wifi síti, správnou adresu serveru a GUID vyplněné v administraci na tmep.cz). | ||
- | <file c priklad> | + | <file c tmep.ino> |
- | // Kod pro tmep.cz, autor mikrom.cz | + | // Simple sketch for sending data to the TMEP.cz |
- | // Pokud máte např. v administraci zadané čidlo s doménou | + | // by mikrom (http:// |
- | // http:// | + | // http://wiki.tmep.cz/ |
+ | // If you send only temperature url will be: http://ahoj.tmep.cz/?mojemereni=25.6 (domain is " | ||
+ | // If you send also humidity url will be: http:// | ||
+ | // Another nice example with bulding HTTP GET request is here: https:// | ||
+ | // Include WiFi stuff | ||
#include < | #include < | ||
- | #define WLAN_SSID "SSID" // WiFi SSID | + | // Include Temperature stuff for DS18B20 |
- | #define WLAN_PASS "HESLO" // WiFi password | + | #include < |
- | # | + | #include < |
- | #define GUID "mojemereni" // GUID | + | |
+ | // Define settings | ||
+ | #define WLAN_SSID | ||
+ | #define WLAN_PASS | ||
+ | # | ||
+ | #define GUID | ||
+ | #define DELAY 60000 // How often send data to the server. Default is 60000ms = 1 minute | ||
+ | #define ONE_WIRE_BUS 5 // Pin where is DS18B20 connected | ||
// Use WiFiClient class to create TCP connections | // Use WiFiClient class to create TCP connections | ||
WiFiClient client; | WiFiClient client; | ||
- | | + | |
+ | // Create Temperature object " | ||
+ | OneWire oneWire(ONE_WIRE_BUS); | ||
+ | DallasTemperature sensors(& | ||
void setup() { | void setup() { | ||
// Start serial | // Start serial | ||
Řádek 29: | Řádek 44: | ||
Serial.println(); | Serial.println(); | ||
- | // Connect to WiFi | + | // Connect to the WiFi |
Serial.print(" | Serial.print(" | ||
WiFi.begin(WLAN_SSID, | WiFi.begin(WLAN_SSID, | ||
Řádek 38: | Řádek 53: | ||
Serial.println(" | Serial.println(" | ||
Serial.print(" | Serial.print(" | ||
+ | |||
+ | // Initialize the DallasTemperature DS18B20 class (not strictly necessary with the client class, but good practice). | ||
+ | sensors.begin(); | ||
Serial.println(" | Serial.println(" | ||
Řádek 43: | Řádek 61: | ||
void loop() { | void loop() { | ||
- | | + | |
+ | sensors.requestTemperatures(); | ||
+ | |||
+ | // Read temperature in "temp" | ||
+ | float temp = sensors.getTempCByIndex(0); | ||
| | ||
- | if (client.connect(SERVER, 80)) { | + | |
+ | | ||
Serial.println(" | Serial.println(" | ||
- | + | ||
- | int rndm = random(10, 30); | + | |
- | | + | |
// Make a HTTP request. | // Make a HTTP request. | ||
client.print(" | client.print(" | ||
- | client.print(String(GUID)); // guid | + | client.print(GUID); |
client.print(" | client.print(" | ||
- | client.print(rndm); // value | + | client.print(temp); // temperature value |
+ | // | ||
+ | // | ||
client.println(" | client.println(" | ||
- | client.print(" | + | client.print(" |
client.println(" | client.println(" | ||
- | client.println(); | + | client.println(); |
- | + | ||
- | // Just for debugging. GET /? | + | |
- | Serial.print(SERVER); | + | |
- | Serial.print(" | + | |
- | Serial.print(String(GUID)); | + | |
- | Serial.print(" | + | |
- | Serial.print(rndm); | + | |
- | Serial.println(" | + | |
- | Serial.print(" | + | |
- | Serial.println(" | + | |
- | Serial.println(); | + | |
- | + | ||
} else { | } else { | ||
- | // if you didn't get a connection to the server: | + | // If you didn't get a connection to the server: |
Serial.println(" | Serial.println(" | ||
} | } | ||
- | delay(60000); | + | |
+ | | ||
} | } | ||
</ | </ |