Hi guys, as a total newbie to Arduino I am working on my first project. I have two DS18B20 temperature sensors and Ethernet shield ENC28J60 hooked up to an Arduino UNO R3. I believe that there are no problems with physical connection. However, I am struggling with the coding.
I just need to set up a simple webserver which will display the temperature from these two sensors and probably refresh itself somehow.
All I could produce so far is this "webserver example" mixed up with "DS18B20 temperatures to Serial monitor example"(maybe these are completely useless, I dont know :~). I will really really appreciate any help. ![]()
I am using OneWire library and the EtherCard library, which is the only one working with ENC28J60.
Here's the code. It compiles with no errors but it's not working the way I want.
#include <OneWire.h>
#include <DallasTemperature.h>
#include <EtherCard.h>
#define ONE_WIRE_BUS 6
#define STATIC 1 // set to 1 to disable DHCP (adjust myip/gwip values below)
#if STATIC
// ethernet interface ip address
static byte myip[] = { 192,168,2,200 };
// gateway ip address
static byte gwip[] = { 192,168,2,1 };
#endif
// ethernet mac address - must be unique on your network
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
byte Ethernet::buffer[500]; // tcp/ip send and receive buffer
char page[] PROGMEM =
"HTTP/1.0 503 Service Unavailable\r\n"
"Content-Type: text/html\r\n"
"Retry-After: 600\r\n"
"\r\n"
"<html>"
"<head><title>"
"Temperature Webserver"
"</title></head>"
"<body>"
"TEMPERATURE TEMPERATURE"
"</body>"
"</html>"
;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer = { 0x28, 0x96, 0xC2, 0xBC, 0x04, 0x00, 0x00, 0xA1 };
DeviceAddress outsideThermometer = { 0x28, 0xA5, 0x0E, 0xBD, 0x04, 0x00, 0x00, 0x99 };
void setup(void)
{
// temperature will show in serial monitor
Serial.begin(57600);
Serial.println("\n[Webserver]");
// start of library
sensors.begin();
// resolution set to 10 bit
sensors.setResolution(insideThermometer, 10);
sensors.setResolution(outsideThermometer, 10);
if (ether.begin(sizeof Ethernet::buffer, mymac) == 0)
Serial.println( "Failed to access Ethernet controller");
#if STATIC
ether.staticSetup(myip, gwip);
#else
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
#endif
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
Serial.print("Error, sensor is not responding");
} else {
Serial.print("C: ");
Serial.print(tempC);
}
}
void loop(void)
{
\
// wait for an incoming TCP packet, but ignore its contents
if (ether.packetLoop(ether.packetReceive())) {
memcpy_P(ether.tcpOffset(), page, sizeof page);
ether.httpServerReply(sizeof page - 1);
delay(2000);
Serial.print("Requesting temperature...\n\r");
sensors.requestTemperatures();
Serial.print("Temperature sensor 1: ");
printTemperature(insideThermometer);
Serial.print("\n\r");
Serial.print("Temperature sensor 2: ");
printTemperature(outsideThermometer);
Serial.print("\n\r");
}
}


