Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DHT Temperature & Humidity Sensor
- // Unified Sensor Library Example
- // Written by Tony DiCola for Adafruit Industries
- // Released under an MIT license.
- // Depends on the following Arduino libraries:
- // - Adafruit Unified Sensor Library: https://github.com/adafruit/Adafruit_Sensor
- // - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
- #include <Adafruit_Sensor.h>
- #include <DHT.h>
- #include <DHT_U.h>
- #define DHTPIN D2 // Pin which is connected to the DHT sensor.
- // Uncomment the type of sensor in use:
- //#define DHTTYPE DHT11 // DHT 11
- #define DHTTYPE DHT22 // DHT 22 (AM2302)
- //#define DHTTYPE DHT21 // DHT 21 (AM2301)
- // See guide for details on sensor wiring and usage:
- // https://learn.adafruit.com/dht/overview
- DHT_Unified dht(DHTPIN, DHTTYPE);
- uint32_t delayMS;
- #include <ESP8266WiFi.h>
- const char* ssid = "TLU";
- const char* password = "";
- const char* host = "web.zone.ee";
- const char* streamId = "....................";
- const char* privateKey = "....................";
- int value = 0;
- //float temp;
- void setup() {
- Serial.begin(115200);
- delay(10);
- // We start by connecting to a WiFi network
- // Serial.println();
- // Serial.println();
- Serial.print("Connecting to ");
- // Serial.println(ssid);
- WiFi.begin(ssid, password);
- while (WiFi.status() != WL_CONNECTED) {
- delay(500);
- Serial.print(".");
- }
- // Serial.println("");
- // Serial.println("WiFi connected");
- // Serial.println("IP address: ");
- Serial.println(WiFi.localIP());
- Serial.begin(9600);
- // Initialize device.
- dht.begin();
- Serial.println("DHTxx Unified Sensor Example");
- // Print temperature sensor details.
- sensor_t sensor;
- dht.temperature().getSensor(&sensor);
- Serial.println("------------------------------------");
- Serial.println("Temperature");
- Serial.print ("Sensor: "); Serial.println(sensor.name);
- Serial.print ("Driver Ver: "); Serial.println(sensor.version);
- Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
- Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println(" *C");
- Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println(" *C");
- Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println(" *C");
- Serial.println("------------------------------------");
- // Print humidity sensor details.
- dht.humidity().getSensor(&sensor);
- Serial.println("------------------------------------");
- Serial.println("Humidity");
- Serial.print ("Sensor: "); Serial.println(sensor.name);
- Serial.print ("Driver Ver: "); Serial.println(sensor.version);
- Serial.print ("Unique ID: "); Serial.println(sensor.sensor_id);
- Serial.print ("Max Value: "); Serial.print(sensor.max_value); Serial.println("%");
- Serial.print ("Min Value: "); Serial.print(sensor.min_value); Serial.println("%");
- Serial.print ("Resolution: "); Serial.print(sensor.resolution); Serial.println("%");
- Serial.println("------------------------------------");
- // Set delay between sensor readings based on sensor details.
- delayMS = sensor.min_delay / 1000;
- }
- void loop() {
- String tempToString;
- String humToString;
- // Delay between measurements.
- delay(delayMS);
- // Get temperature event and print its value.
- sensors_event_t event;
- dht.temperature().getEvent(&event);
- if (isnan(event.temperature)) {
- Serial.println("Error reading temperature!");
- }
- else {
- Serial.print("Temperature: ");
- tempToString = String(event.temperature, 2);
- Serial.print(event.temperature);
- Serial.println(" *C");
- }
- // Get humidity event and print its value.
- dht.humidity().getEvent(&event);
- if (isnan(event.relative_humidity)) {
- Serial.println("Error reading humidity!");
- }
- else {
- Serial.print("Humidity: ");
- humToString = String(event.relative_humidity, 2);
- Serial.print(event.relative_humidity);
- Serial.println("%");
- }
- //delay(5000);
- ++value;
- float temp = event.temperature;
- tempToString.replace('.', 'p');
- humToString.replace('.', 'p');
- // Serial.print("connecting to ");
- // Serial.println(host);
- // Use WiFiClient class to create TCP connections
- WiFiClient client;
- const int httpPort = 80;
- if (!client.connect(host, httpPort)) {
- Serial.println("connection failed");
- return;
- }
- // We now create a URI for the request
- String url = "http://web.zone.ee/asjadeinternet2017/katse.php?temp=" + tempToString + "&hum=" + humToString;
- // url += streamId;
- // url += "?private_key=";
- // url += privateKey;
- // url += "&value=";
- // url += value;
- Serial.print("Requesting URL: ");
- Serial.println(url);
- // This will send the request to the server
- client.print(String("GET ") + url + " HTTP/1.1\r\n" +
- "Host: " + host + "\r\n" +
- "Connection: close\r\n\r\n");
- unsigned long timeout = millis();
- while (client.available() == 0) {
- if (millis() - timeout > 5000) {
- Serial.println(">>> Client Timeout !");
- client.stop();
- return;
- }
- }
- // Read all the lines of the reply from server and print them to Serial
- while(client.available()){
- String line = client.readStringUntil('\r');
- //Serial.println(line);
- if(line.indexOf("+++") != -1) {
- Serial.println("andmed");
- // break;
- }
- Serial.print(line);
- }
- Serial.println();
- Serial.println("closing connection");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement