I've found this code googling around and it works well, my only problem is getting it to extract the temperatures values and display them on a web page
I've tried to pass a variable in the client println page insideTemperature, but all I get are errors
I've already inputted the correct sensor addresses
#include <SPI.h>
#include <Ethernet.h>
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 6on the Arduino
#define ONE_WIRE_BUS 6
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress insideThermometer = { 0x28, 0xFF, 0x9E, 0x9B, 0x67, 0x18, 0x01, 0x33 };//=28 97 CA 29 5 0 0 63
DeviceAddress outsideThermometer = { 0x28, 0xFF, 0xAA, 0xBE, 0x23, 0x16, 0x03, 0x96 };//28 85 F6 3F 5 0 0 C2
//DeviceAddress dogHouseThermometer = { 0x28, 0x59, 0xBE, 0xDF, 0x02, 0x00, 0x00, 0x9F };
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //physical mac address
byte ip[] = { 10,0,0,102 }; // ip in lan
byte gateway[] = { 10,0,0,1 }; // internet access via router
byte subnet[] = { 255, 255, 255, 0 }; //subnet mask
EthernetServer server(80); //server port
//////////////////////
void setup(){
//----------------------------------SetUp One Wire-------------------------------
// start serial port
Serial.begin(9600);
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(insideThermometer, 6);
sensors.setResolution(outsideThermometer, 6);
//sensors.setResolution(dogHouseThermometer, 10);
//----------------------------------Fin SetUp One Wire-------------------------------
//start Ethernet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
Serial.begin(9600);
Serial.println("server LED test 1.0"); // so I can keep track of what is loaded
}
void loop()
{
delay (1000);
Serial.print("Getting temperatures...\n\r");
//sensors.requestTemperatures(); // I have to remove this line to have my web page!
Serial.print("Inside temperature is: ");
printTemperature(insideThermometer);// I have to remove this line to have my web page!
Serial.print("\n\r");
Serial.print("Outside temperature is: ");
printTemperature(outsideThermometer);
Serial.print("\n\r");
//Serial.print("Dog House temperature is: ");
//printTemperature(dogHouseThermometer);
//Serial.print("\n\r\n\r");
{
boolean currentLineIsBlank;
// Create a client connection
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
char c = client.read();
//read char by char HTTP request
//if HTTP request has ended
if (c == '\n') {
client.println("HTTP/1.1 200 OK"); //send new page
client.println("Content-Type: text/html");
client.println();
client.println("<HTML>");
client.println("<HEAD>");
client.println("<meta name='apple-mobile-web-app-capable' content='yes' />");
client.println("<meta name='apple-mobile-web-app-status-bar-style' content='black-translucent' />");
client.println("<link rel='stylesheet' type='text/css' href='http://homeautocss.net84.net/a.css' />");
// Titre de la page Web
client.println("<TITLE>Arduino ATMega 2560</TITLE>");
client.println("</HEAD>");
client.println("<BODY>");
client.println("<H1>Arduino ATMega 2560</H1>");
client.println("<hr />");
client.println("
");
client.println();
//Envoi des données
client.println("
");client.println("
");
client.print("<b><h1><FONT COLOR=red>This is for test</FONT></h1>");
client.print("<i>");
client.println("
");
//stopping client
client.stop();
}
}
}
}
}
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error getting temperature");
} else {
Serial.print("C: ");
Serial.print(tempC);
// Serial.print(" F: ");
//Serial.print(DallasTemperature::toFahrenheit(tempC));
}
}
