// ======================== ========== #include <SPI.h> #include <String.h> #include <Ethernet.h> #include "DHT.h" #include "Wire.h" #include "Adafruit_BMP085.h" // =============================================================== // ======================== ====================== byte mac[] = { 0xCA, 0xAF, 0x78, 0x1C, 0x13, 0x77 }; //mac - ethernet shielda byte ip[] = { 192, 168, 1, 33 }; // ip ethernet shielda byte subnet[] = { 255, 255, 255, 0 }; // EthernetServer server(80); // int ledPin = 4; // 4 Pin String readString = String(30); //string for fetching data from address boolean LEDON = false; // - // =============================================================== #define DHTPIN 3 // DHT22 const unsigned char OSS = 0; // Oversampling Setting // =============================================================== // ======================== DHT======================= //#define DHTTYPE DHT11 // DHT 11 #define DHTTYPE DHT22 // DHT 22 (AM2302) //#define DHTTYPE DHT21 // DHT 21 (AM2301) // ============================================================== DHT dht(DHTPIN, DHTTYPE); Adafruit_BMP085 bmp; // ===================================================== // ======================== . 4- ========== void setup(){ // Ethernet Ethernet.begin(mac, ip, subnet); // pin 4 pinMode(ledPin, OUTPUT); //enable serial datada print Serial.begin(9600); Serial.println("Port Test!"); // Serial.println("GO!");// dht.begin(); bmp.begin(); } // ============================================================== void loop(){ // ===================================================== float h = dht.readHumidity(); float t = dht.readTemperature(); float tdpa = bmp.readTemperature(); float Pa0 = (bmp.readPressure()); float Pa = (bmp.readPressure()/133.33);// ... float Pa2 = (bmp.readPressure()/3386.582);// ... if (isnan(t) || isnan(h)) { Serial.println("Failed to read from DHT"); } else { Serial.print("H=: "); Serial.print(h); Serial.print(" %\t"); Serial.print("Temp.=: "); Serial.print(t); Serial.println(" *C"); Serial.print("Temp.dat.BMP = "); Serial.print(tdpa); Serial.println(" *C"); Serial.print("Pressure = "); Serial.print(Pa); Serial.println(" mm."); Serial.print("Pressure = "); Serial.print(Pa2); Serial.println(" in Hg"); // ============================================================== // ============= ==================== EthernetClient client = server.available(); if (client) { while (client.connected()) { if (client.available()) { char c = client.read(); //read char by char HTTP request if (readString.length() < 30) { //store characters to string readString.concat( c); } //output chars to serial port Serial.print( c); //if HTTP request has ended if (c == '\n') { // ? //Level=1 - //Level=0 - if(readString.indexOf("Level=1") >=0) { // digitalWrite(ledPin, HIGH); // set the LED on LEDON = true; }else{ // digitalWrite(ledPin, LOW); // set the LED OFF LEDON = false; } // ============= HTML-========================== client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println(); client.println("<head> "); client.println("<meta http-equiv='Content-Type' content='text/html; charset=utf-8' /> "); client.println("<title> :: .Arduino:: V1.1</title>"); client.println("</head> "); client.println("<body"); client.println("<hr />"); client.println("<h1> ::.Arduino:: </h1>"); if (LEDON){ client.println("<form method=get name=LED><input type=radio name=Level value=1 CHECKED><input type=radio name=Level value=0><input type=submit value=OK></form>"); client.println("<font size='5′>LED-: "); client.println("<font size='5′>."); }else{ client.println("<form method=get name=LED><input type=radio name=Level value=1><input type=radio name=Level value=0 CHECKED><input type=submit value=OK></form>"); client.println("<font size='5′>LED-: "); client.println("<font size='5′>"); } //============== web-====================== client.println("<hr />");//===================================== client.println("T = "); // DHT 22 client.println(t); client.println(" *C"); client.println("<br> "); // . client.println(" = "); // DHT 22 client.println(h); client.println(" %\t"); client.println("<br> "); // . client.println("<hr />");//===================================== client.println(" = "); // BMP 085 client.println(Pa); client.println(" mm..."); client.println("<br> "); // . client.println("<hr />"); //===================================== client.println(" = "); // BMP 085 client.println(Pa2); client.println(" in Hg"); client.println("<br> "); // . client.println("<hr />"); //===================================== client.println("T = ");// BMP 085 client.println(tdpa); client.println(" *C"); client.println("<br> "); // . client.println("<hr />"); //===================================== //============================================================== client.println("</body></html>"); // //============== web-client=========================== readString=""; client.stop(); //============================================================== } } } } } }
Source: https://habr.com/ru/post/171525/
All Articles