zarizeni:esp8266
Toto je starší verze dokumentu!
ESP8266
Příklad jak naprogramovat ESP8266 v Arduino IDE od mikroma
.
Web autora příkladu: http://mikrom.cz/
Kontakt na autora: mikrom@mikrom.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).
- tmep.ino
// Simple sketch for sending data to the TMEP.cz // by mikrom (http://www.mikrom.cz) // 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 Temperature stuff for DS18B20 #include <OneWire.h> #include <DallasTemperature.h> // 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 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() { // Start serial Serial.begin(115200); delay(10); Serial.println(); // Connect to the WiFi Serial.print("Connecting to "); Serial.println(WLAN_SSID); WiFi.begin(WLAN_SSID, WLAN_PASS); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("WiFi connected"); 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!"); } void loop() { // Send the command to get temperatures. request to all devices on the bus sensors.requestTemperatures(); // Read temperature in "temp" variable float temp = sensors.getTempCByIndex(0); // Connect to the HOST and send data via GET method if (client.connect(HOST, 80)) { Serial.println("Connected"); // Make a HTTP request. client.print("GET /?"); client.print(GUID); // guid: "mojemereni" client.print("="); client.print(temp); // temperature value //client.print("&humV="); //client.print(60); // humidity value client.println(" HTTP/1.1"); client.print("Host:"); client.println(HOST); client.println("Connection: close"); client.println(); } else { // If you didn't get a connection to the server: Serial.println("Connection failed"); } // Wait for DELAY, default 1 minute delay(DELAY); }