Uživatelské nástroje

Nástroje pro tento web


zarizeni:esp8266

Rozdíly

Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.

Odkaz na výstup diff

Následující verzeObě strany příští revize
zarizeni:esp8266 [2016/05/30 10:01] – vytvořeno multitrickerzarizeni: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 ahoj a GUID nastavené na mojemereni. +// by mikrom (http://www.mikrom.cz) 
-// http://ahoj.tmep.cz/?GUID=25.6+// http://wiki.tmep.cz/doku.php?id=zarizeni:esp8266 
 +// If you send only temperature url will be: http://ahoj.tmep.cz/?mojemereni=25.6 (domain is "ahoj" and guid is "mojemereni" 
 +// If you send also humidity url will be: http://ahoj.tmep.cz/?mojemereni=25.6&humV=60 
 +// Another nice example with bulding HTTP GET request is here: https://github.com/SensorsIot/ESP8266-Longterm-Sensor-Hourly/blob/master/Sparkfun.ino
  
 +// Include WiFi stuff
 #include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
  
-#define WLAN_SSID "SSID" // WiFi SSID +// Include Temperature stuff for DS18B20 
-#define WLAN_PASS "HESLO" // WiFi password +#include <OneWire.h> 
-#define SERVER    "ahoj.tmep.cz" // domena.tmep.cz +#include <DallasTemperature.h> 
-#define GUID      "mojemereni" // GUID+ 
 +// Define settings 
 +#define WLAN_SSID    "---wifi ssid---     // WiFi SSID 
 +#define WLAN_PASS    "---wifi password--- // WiFi password 
 +#define HOST         "---domain---.tmep.cz" // domena.tmep.cz 
 +#define GUID         "---guid---          // mojemereni 
 +#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 "sensors" 
 +OneWire oneWire(ONE_WIRE_BUS);       // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs) 
 +DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. 
 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("Connecting to "); Serial.println(WLAN_SSID);   Serial.print("Connecting to "); Serial.println(WLAN_SSID);
   WiFi.begin(WLAN_SSID, WLAN_PASS);   WiFi.begin(WLAN_SSID, WLAN_PASS);
Řádek 38: Řádek 53:
   Serial.println("WiFi connected");   Serial.println("WiFi connected");
   Serial.print("IP address: "); Serial.println(WiFi.localIP());   Serial.print("IP address: "); Serial.println(WiFi.localIP());
 +
 +  // Initialize the DallasTemperature DS18B20 class (not strictly necessary with the client class, but good practice).
 +  sensors.begin(); 
  
   Serial.println("Ready for LOOP!");   Serial.println("Ready for LOOP!");
Řádek 43: Řádek 61:
  
 void loop() { void loop() {
-  Serial.println("Connecting...");+  // Send the command to get temperaturesrequest to all devices on the bus 
 +  sensors.requestTemperatures(); 
 + 
 +  // Read temperature in "tempvariable 
 +  float temp = sensors.getTempCByIndex(0);
      
-  if (client.connect(SERVER, 80)) {+  // Connect to the HOST and send data via GET method   
 +  if (client.connect(HOST, 80)) {
     Serial.println("Connected");     Serial.println("Connected");
- + 
-    int rndm = random(10, 30); +
-    +
     // Make a HTTP request.     // Make a HTTP request.
     client.print("GET /?");     client.print("GET /?");
-    client.print(String(GUID)); // guid+    client.print(GUID); // guid: "mojemereni"
     client.print("=");     client.print("=");
-    client.print(rndm); // value+    client.print(temp); // temperature value 
 +    //client.print("&humV="); 
 +    //client.print(60); // humidity value
     client.println(" HTTP/1.1");     client.println(" HTTP/1.1");
-    client.print("Host:"); client.println(SERVER);+    client.print("Host:"); client.println(HOST);
     client.println("Connection: close");     client.println("Connection: close");
-    client.println(); +    client.println();    
-     +
-    // Just for debugging. GET /?mojemereni=20 +
-    Serial.print(SERVER); Serial.print(" "); +
-    Serial.print("GET /?"); +
-    Serial.print(String(GUID)); +
-    Serial.print("="); +
-    Serial.print(rndm); +
-    Serial.println(" HTTP/1.1"); +
-    Serial.print("Host:"); Serial.println(SERVER); +
-    Serial.println("Connection: close"); +
-    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("Connection failed");     Serial.println("Connection failed");
   }   }
  
-  delay(60000);+  // Wait for DELAY, default 1 minute 
 +  delay(DELAY);
 } }
 </file> </file>