chcel by som spravit take jednoduche home automation, okrem zaluzii, co mi nijak nevychadza smartovo, iba jednoducho, ze rele sa zopne a pojdu hore a vypne a pojdu dole, na zaluziach je koncovy spinac ale nan sa uz neviem pripojit a inak asi neviem zistit polohu zaluzie (ci su hore, ci otvorene, lebo zatvorene) takze jedine asi casovo (kratke zopnutie pre krok a dlhe pre uplne otvorenie alebo zatvorenie)
problem je, ze chcem vyuzit aj ovladanie klimi cez IR a ovladat cez webserver. A kedze klima vysiela z dialkoveho vsetko nastavenie jednym kodom, tak musim na kazdu funkciu tzn potrebujem pre kazdy stupen °C musi odoslat aj komplet s nastavenim ventilatora aj ci ma ohrievat alebo chladit (viac netreba)
myslim si, ze problem bude v pamati arduina a najlepsie by bolo vyuzit SD kartu, kde vzdy pri vyvolani adresy napr.: /ip/?chladenie_22_auto odosle kod z sd karty bud bude kazdy prikaz v samostatnom subore alebo jeden dlhy text a tam bude vyhladavat, asi najrozumnejsie je vytvorit subory presne typu:
(rezim_stupne_ventilator)
chladenie_17_auto
chladenie_18_auto
..
chladenie_30_auto
potom:
chladenie_17_low
..
chladenie_30_low
potom:
ohrievanie_17_auto
..
ohrievanie_30_auto
je to mozne takto spravit?
momentlne vyuzivam tento kod (su tam aj nejake skusobne prikazy ked som chcel vyuzit aj LCD avsak neni to mozne lebo IR potrebuje PIN 3 a pri zapojeni LCD je tento pin vyuzity a s inym mi LEDka nevysielala nic):
Kód: Vybrat vše
/* *** *** ***
Mega - ok 18.758/253.952 - 2.090/8.192
Leonardo - ok 21.498/28.672 - 2.059/2.560
UNO - no ok 18.800/32.256 - 2.090/2.048
*** *** *** */
#include <String.h>
#include <SPI.h>
#include <Ethernet.h>
#include "IRremote.h"
#include <DHT.h>
#include <LiquidCrystal.h>
/*
controllare un condizionatore via web
con sensori di temperatura e umidità
ARDUINO UNO - limitato
Mega o Leonardo
ETHERNET SHIELD
DHT22, IR led
*/
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // mac address
byte ip[] = { 192, 168, 82, 135 }; // ip arduino internet in
byte gateway[] = { 192, 168, 82, 1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
IRsend irsend;
int khz = 38; //NB Change this default value as neccessary to the correct modulation frequency
// define some values used by the panel and buttons
int lcd_key = 0;
int adc_key_in = 0;
#define btnRIGHT 0
#define btnUP 1
#define btnDOWN 2
#define btnLEFT 3
#define btnSELECT 4
#define btnNONE 5
// read the buttons
int read_LCD_buttons()
{
adc_key_in = analogRead(0); // read the value from the sensor
// my buttons when read are centered at these valies: 0, 144, 329, 504, 741
// we add approx 50 to those values and check to see if we are close
// For V1.0 comment the other threshold and use the one below:
if (adc_key_in < 50) return btnRIGHT;
if (adc_key_in < 195) return btnUP;
if (adc_key_in < 380) return btnDOWN;
if (adc_key_in < 555) return btnLEFT;
if (adc_key_in < 790) return btnSELECT;
return btnNONE; // when all others fail, return this...
}
// ON HEAT
unsigned dry[] = {
4560, 4416, 624, 1632, 628, 1632, 624, 1632, 628, 508, 620, 508, 620, 508, 620, 508, 620, 508, 620, 1636, 624, 1636, 624, 1632, 628, 504, 624, 504, 624, 504, 624, 504, 624, 508, 624, 504, 624, 1632, 624, 504, 624, 504, 628, 504, 624, 504, 624, 504, 624, 504, 624, 1632, 628, 508, 648, 1608, 620, 1636, 624, 1636, 620, 1636, 624, 1636, 652, 1604, 624, 45964, 4560, 4416, 648, 1608, 624, 1632, 628, 1636, 620, 508, 620, 508, 624, 508, 648, 480, 620, 508, 620, 1636, 628, 1628, 652, 1608, 624, 504, 628, 504, 648, 480, 648, 480, 624, 504, 624, 504, 628, 1628, 628, 504, 624, 504, 624, 504, 624, 508, 624, 504, 652, 476, 652, 1608, 620, 508, 624, 1632, 628, 1632, 624, 1632, 628, 1628, 652, 1608, 624, 1632, 628,
};
// OFF - AC
unsigned OFF[] = {
4536, 4444, 620, 1640, 620, 1640, 616, 1640, 624, 528, 600, 532, 596, 536, 592, 536, 592, 536, 592, 1636, 624, 1636, 620, 1636, 624, 532, 596, 532, 596, 536, 592, 540, 588, 536, 596, 532, 596, 1636, 620, 536, 596, 536, 592, 532, 596, 536, 596, 532, 596, 536, 592, 1636, 620, 536, 592, 1636, 624, 1636, 620, 1624, 636, 1636, 620, 1640, 616, 1640, 620,
};
// ON cool 23°C FAN-auto - AC
unsigned COOL[] = {
4536, 4444, 624, 1636, 620, 1636, 624, 1636, 620, 536, 596, 532, 596, 536, 592, 536, 592, 536, 592, 1636, 624, 1636, 620, 1636, 624, 532, 596, 536, 592, 536, 592, 536, 592, 536, 596, 532, 596, 1640, 616, 536, 592, 536, 596, 532, 596, 536, 592, 536, 592, 536, 592, 1640, 620, 536, 596, 1636, 620, 1636, 624, 1636, 620, 1636, 620, 1640, 616, 1640, 620
};
#define DHTPIN 22 // PIN data of DHT22
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE);
int irPin = 3; // pin IR led
String readString; //string
boolean COOLON = false; // flag status Cooling
boolean DRYON = false; // flag status Drying
boolean textOff = false;
int lcdState = 1;
unsigned long previousMillis = 0; // will store last time LED was updated
// constants won't change:
const long interval = 7000;
void setup() {
Ethernet.begin(mac, ip, gateway, subnet);
dht.begin();
pinMode(irPin, OUTPUT);
Serial.begin(115200);
lcd.begin(16, 2); // start the library
lcd.setCursor(0,0);
// lcd.print("Push the buttons"); // print a simple message
}
/*
if (DRYON) {
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Ohrev");
lcd.setCursor(0,1);
lcd.print("je zapnuty");
}
else if (COOLON) {
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Klima");
lcd.setCursor(0,1);
lcd.print("je zapnuta");
}
else {
lcd.begin(16, 2);
lcd.setCursor(0,0);
lcd.print("Teplota: ");
lcd.print(t);
lcd.print(" C");
lcd.setCursor(0,1);
lcd.print("Vhkost: ");
lcd.print(h);
lcd.print(" %");
}
}*/
void loop() {
float t = dht.readTemperature(); // Value of Temp
float h = dht.readHumidity(); // Value of Humidity
// show temp and hum
/*
*/
lcd.setCursor(0,0);
lcd.print("Teplota: ");
lcd.print(t);
lcd.print(" C");
lcd.setCursor(0,1);
lcd.print("Vhkost: ");
lcd.print(h);
lcd.print(" %");
/*inizio client*/
EthernetClient client = server.available();
if (client) {
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
readString.concat(c); //memorizzo ogni carattere della stringa
//if HTTP request has ended
if (c == '\n' && currentLineIsBlank) {
Serial.print(readString);
if (readString.indexOf("L=0") > 0) {
if (COOLON || DRYON) { // if is ON, switch it OFF
//Serial.println("AC -> OFF");
irsend.sendRaw(OFF, sizeof(OFF) / sizeof(int), khz);
COOLON = false;
DRYON = false;
}
}
else if (readString.indexOf("L=1") > 0) { // lettura del valore se il AC si deve accendere
if (!DRYON) { //se non è acceso
//Serial.println("Dry ON");
irsend.sendRaw(dry, sizeof(dry) / sizeof(int), khz);
DRYON = true;
COOLON = false;
}
}
else if (readString.indexOf("L=2") > 0) {
if (!COOLON) { //se è acceso
//Serial.println("Cool ON");
irsend.sendRaw(COOL, sizeof(COOL) / sizeof(int), khz);
COOLON = true;
DRYON = false;
}
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (DRYON) {
}
else if (COOLON) {
}
else {
}
}
// COSTRUZIONE PAGINA HTML
client.println("HTTP/1.1 200 OK.....");
client.println("Content-Type: text/html");
client.println();
// inizializzo pagina (da togliere se uso ajax)
client.print("<html><head><title>MoniCris AC</title><meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' ></head><body>");
//iniza il body
client.println("<div style='width:960px; height:1136px;'>"); //risoluzione per nokia 5800 640x360, iPhone4 960x640 pixel, iPhone5 1136x640
client.println("<h1>Home STATUS</h1><hr />");
//Scrive sul browser il valore del termistore
client.println("<p>TEMPERATURE = ");
client.print(t);
client.println(" *C <br /></p>");
//Scrive sul browser il valore della fotoresistenza
client.println("<p>HUMIDITY = ");
client.print(h);
client.println(" % <br /></p>");
// link per aggiornare pagina e valori
client.print("<h2>Refresh: <a href=''>CHECK</a></h2><hr />");
client.println("<h1>AC CONTROL</h1>");
//scrivo il AC status
client.print("<font size='5'>Status: ");
if (DRYON) {
client.println("<span style='color:green; font-weight:bold;'>DRY</span></font>");
}
else if (COOLON) {
client.println("<span style='color:green; font-weight:bold;'>COOL</span></font>");
}
else {
client.println("<span style='color:grey; font-weight:bold;'>OFF</span></font>");
}
client.print("<h2><a href='/?L=1'> DRY </a> | <a href='/?L=0'> OFF </a> | <a href='/?L=2'> COOL </a></h2>");
//semnătura ;)
client.println("<hr />");
client.print("<h4>MoniCris Home Project 2015</h4>");
client.println("<hr />");
// chiudo il div
client.println("</div>");
// chiudo pagina da togliere se uso ajax
client.println("</body></html>");
// pulisco la stringa per la successiva lettura
readString = "";
//fermo il client
client.stop();
} //if c == /n
} // if client available
} // while client connesso
} // FINE if client
} // fine loop