Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <dht.h>
- #include <SPI.h>
- #include <Ethernet.h>
- #include <IRremote.h>
- #define DHT22_PIN 2
- dht DHT;
- byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
- byte gateway[] = {192, 168, 1, 1 };
- byte subnet[] = {255, 255, 255, 0 };
- IPAddress ip(192, 168, 1, 220);
- float MAX_TEMP = 25.0;
- float MIN_TEMP = 22.0;
- int MAX_HUMID = 60;
- int MIN_HUMID = 40;
- int last_condey_status = 0;
- unsigned int TurnCondeyOff[68] = {2700,2600,750,700,700,700,700,700,750,700,750,700,750,650,750,700,700,700,750,700,750,650,750,700,700,700,750,700,700,700,700,700,750,700,700,700,750,650,750,700,750,700,700,700,750,650,750,700,700,700,750,650,750,700,750,700,750,700,700,2000,750,2000,750,1950,750,2000,750};
- unsigned int TurnCondeyMaxOn[68] = {2650,2650,750,2000,750,700,700,700,700,700,750,700,700,700,750,650,750,700,750,700,700,700,700,700,750,700,700,700,750,650,750,700,700,700,750,700,700,700,750,700,700,700,750,650,800,700,700,750,700,650,750,700,700,700,750,650,800,650,750,700,700,2000,750,1950,750,2000,750};
- unsigned int TurnCondeyWaterOn[68] = {2650,2650,750,2000,750,700,700,700,700,700,750,700,700,700,750,650,750,700,750,700,700,700,700,700,750,700,700,700,750,650,750,700,700,700,750,700,700,700,750,700,700,700,750,650,800,700,700,750,700,650,750,700,700,700,750,650,800,650,750,700,700,2000,750,1950,750,2000,750};
- unsigned int TurnCondeyAuto[68] = {2650,2650,750,2000,750,700,700,700,700,700,750,700,700,700,750,650,750,700,750,700,700,700,700,700,750,700,700,700,750,650,750,700,700,700,750,700,700,700,750,700,700,700,750,650,800,700,700,750,700,650,750,700,700,700,750,650,800,650,750,700,700,2000,750,1950,750,2000,750};
- IRsend irsend;
- int dht_status = 0;
- char serverName[] = "myserver.ru";
- byte server[] = {192, 168, 1, 5 };
- EthernetClient client;
- void setup()
- {
- Serial.begin(9600);
- Serial.print("LIBRARY VERSION: ");
- Serial.println(DHT_LIB_VERSION);
- delay(1000);
- Serial.println("Try to configure Ethernet using DHCP...");
- // start the Ethernet connection:
- if(Ethernet.begin(mac) == 0) {
- Serial.println("Failed to configure Ethernet using DHCP. Using manual config.");
- Ethernet.begin(mac, ip, gateway);
- }
- PrintIPtoSerial();
- }
- void loop()
- {
- Serial.println("status,\tHumidity (%),\tTemperature (C)");
- // READ DATA
- int chk = DHT.read22(DHT22_PIN);
- switch (chk)
- {
- case DHTLIB_OK:
- dht_status = 200;
- Serial.print("OK,\t");
- break;
- case DHTLIB_ERROR_CHECKSUM:
- dht_status = 501;
- Serial.print("Checksum error,\t");
- break;
- case DHTLIB_ERROR_TIMEOUT:
- dht_status = 504;
- Serial.print("Time out error,\t");
- break;
- default:
- dht_status = 500;
- Serial.print("Unknown error,\t");
- break;
- }
- // DISPLAY DATA
- Serial.print(DHT.humidity, 1);
- Serial.print(",\t");
- Serial.println(DHT.temperature, 1);
- SendDataToServer(dht_status, DHT.temperature, DHT.humidity);
- WorkWithCondey(DHT.temperature, DHT.humidity);
- Serial.println();
- delay(1000);
- }
- boolean SendDataToServer(int d_stat, float temp, int humidity) {
- if (client.connect(server, 80)) {
- char buf[80];
- int temp1 = (temp - (int)temp) * 100;
- int humidityl = (humidity - (int)humidity) * 100;
- Serial.println("Sending information to weather server");
- // Make a HTTP request:
- sprintf(buf, "GET /meteo.php?S=%d&T=%0d.%d&H=%0d.%d&CS=%d HTTP/1.1", (int)d_stat, (int)temp, abs(temp1), (int)humidity, abs(humidityl), last_condey_status);
- client.println(buf);
- client.println("Host: myserver.ru");
- client.println("Connection: close");
- client.println();
- client.stop();
- return true;
- }
- else {
- // if you didn't get a connection to the server:
- Serial.println("Connection to weather server failed");
- client.stop();
- return false;
- }
- }
- void WorkWithCondey(float temp, int humidity) {
- int status = 0;
- if(temp > MAX_TEMP) {
- status=1;
- }
- if(temp < MIN_TEMP) {
- status=0;
- }
- if(humidity > MAX_HUMID) {
- status = status+3;
- }
- if(humidity < MIN_HUMID) {
- status = status;
- }
- String condey_text_status = "";
- if(status != last_condey_status) {
- last_condey_status = status;
- if(status == 0) {
- irsend.sendRaw(TurnCondeyOff,68,38);
- }
- if(status == 1) {
- irsend.sendRaw(TurnCondeyMaxOn,68,38);
- }
- if(status == 3) {
- irsend.sendRaw(TurnCondeyWaterOn,68,38);
- }
- if(status == 4) {
- irsend.sendRaw(TurnCondeyAuto,68,38);
- }
- }
- Serial.print("Condition status: ");
- Serial.println(status);
- }
- void PrintIPtoSerial() {
- Serial.print("My Local IP address: ");
- Serial.println(Ethernet.localIP());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement