#include <Ethernet.h>
#include <Server.h>
#include <SPI.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#include <DHT.h>
#define DHTPIN 3 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192,168,100, 150 };
Server server(80);
// anturin data-jalka
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
int anturit = sensors.getDeviceCount();
// LDR
const int ldrPin = A0;
int ldr = 0;
// SETUP ---------------------------------------------
void setup() {
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(9600);
sensors.begin(); //1-wire
/*
// DEBUG
//parasite?
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
// monta anturia löydetään
Serial.print(sensors.getDeviceCount(), DEC);
// DEBUG
*/
dht.begin();
delay(1000);
}
//SETUP -----------------------------------------------
void loop() {
ldr = analogRead(ldrPin);
int h = dht.readHumidity();
int t = dht.readTemperature();
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
sensors.requestTemperatures(); // Send the command to get temperatures
delay(750);
float anturi1 = sensors.getTempCByIndex(0);
float anturi2 = sensors.getTempCByIndex(1);
// print to usb
Serial.print(anturi1);
Serial.print("\n");
Serial.print(anturi2);
Serial.print("\n");
Serial.print(ldr);
Serial.print("\n");
//dht
Serial.print(h);
Serial.print("\n");
Serial.print(t);
Serial.print("\n");
//----------- ETHERNET ---------------------------
Client client = server.available();
if (client) {
// an http request ends with a blank line
boolean currentLineIsBlank = true;
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the http request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard http response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<TITLE>Arduino webbaservero!</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.print("anturitietoja!");
client.println("<br />");
client.print(anturi1);
client.print("c ");
client.print(anturi2);
client.print("c");
client.println("<br />");
client.println("<br />");
client.println("<br />");
client.print("kosteus: ");
client.print(h);
client.print("%");
client.print(" lampotila: ");
client.print(t);
client.print("c");
client.println("<br />");
client.println("<br />");
client.print("valoisuus 1-1000: ");
client.print(ldr);
client.println("<br />");
client.println("<br />");
client.println("<br />");
client.println("<img src='http://heller.huono.org/servduino.jpg'>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
}
//vika
}