Web Server/Combining Sketch Question

Greetings All,

I am using and Arduino Uno, Arduino Shield, and two DS18B20 temperature sensors. Originally my goal was to have a single sensor’s output displayed on a simple web page which using examples and some guidance from this forum was able to achieve. But the environment where I intend to monitor the temperature actually has two cooling zones. So I would like to incorporate two sensor reading into the webpage. As it turns out getting two temperature values is much different code than I was originally using. But with an example sketch from: http://arduino-info.wikispaces.com/Brick-Temperature-DS18B20#multibus, I was able to get both sensor values via serial output. Unfortunately I am having problems displaying the temperatures from this sketch on the web server. The sketch below generates the following compiling errors:

sketch_may26a.ino: In function ‘void loop()’:
sketch_may26a:126: error: ‘Temperature’ was not declared in this scope

I thought Temperature was a function as part of the DallasTemperature.h library. Any help would be greatly appreciated.

#include <OneWire.h> 
#include <SPI.h>
#include <Ethernet.h>
#include <DallasTemperature.h>

//DS18S20 Signal pin on digital 2 Primary Side Hut Temperature Sensor
//*-----( Declare Constants and Pin Numbers )-----*/
#define ONE_WIRE_BUS_PIN 2

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = { 
  0x00, 0x16, 0x1B6, 0x82, 0xF9, 0x09 }; // MAC addressed copied from VHO10 SEM B1-GigE3 Port. Port is non-used and assigned to the Video Network
IPAddress ip(192,168,1,107); // Test IP address for default home routers.

// Initialize the Ethernet server library
// with the IP address and port you want to use 
// (port 80 is default for HTTP):
EthernetServer server(80);

/*-----( Declare objects )-----*/
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS_PIN);

// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);

/*-----( Declare Variables )-----*/
// 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 Probe01 = { 0x28, 0xDA, 0x6E, 0x5F, 0x04, 0x00, 0x00, 0x7A }; 
DeviceAddress Probe02 = { 0x28, 0xF7, 0x76, 0x5F, 0x04, 0x00, 0x00, 0xC4 };

void setup(void) {
  Serial.begin(9600);
   // start the Ethernet connection and the server:
   Serial.print("Initializing Temperature Control Library Version ");
   Serial.println(DALLASTEMPLIBVERSION);
  Ethernet.begin(mac, ip);
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
   // Initialize the Temperature measurement library
  sensors.begin();
  
  // set the resolution to 10 bit (Can be 9 to 12 bits .. lower is faster)
  sensors.setResolution(Probe01, 10);
  sensors.setResolution(Probe02, 10);
  
}

void loop(void) {
  
  
  Serial.println();
  Serial.print("Number of Devices found on bus = ");  
  Serial.println(sensors.getDeviceCount());   
  Serial.print("Getting temperatures... ");  
  Serial.println();   
  
  // Command all devices on bus to read temperature  
  sensors.requestTemperatures();  
  
  Serial.print("Probe 01 temperature is:   ");
  printTemperature(Probe01);
  Serial.println();
 
  Serial.print("Probe 02 temperature is:   ");
  printTemperature(Probe02);
  Serial.println();
  
 
  delay(800); //just here to slow down the output so it is easier to read
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
      while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // 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("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 5");  // refresh the page automatically every 5 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<head>");
          client.println("<body bgcolor=""#00FFFF>"); //Changes background color
	  client.println("<title>Hut Temperature</title>");
          // output the value of each analog input pin
          for (int analogChannel = 0; analogChannel < 1; analogChannel++) {
            int sensorReading = analogRead(analogChannel);
            client.print("<center><Font SIZE=+5>Frontier Simulsat Hut Temperature Monitor");
            client.print("
"); // Adds blank lines
            client.print("
");
            client.print("<center><Font SIZE=+4>Primary Side Temperature is "); // Centers Text and changes font size
            client.print(Temperature)(Probe01);
            client.print("</center>");
            client.print("<center><Font SIZE=+4>Protect Side Temperature is ");
            //client.print(Temperature);
            client.print("
");
            client.print("<Font SIZE=+4>Average Hut Temperature is ");
            //client.print(ProbeAverage);
            client.print("
");
            client.print("
");
            client.print("
");
            client.print("
");
            client.print("
");
            client.print("
");
            client.print("
");
            client.print("
");
            client.print("
");
            client.print("<Font SIZE=+2>Uptime is");//Future Feature
            client.print("</center>");
            client.println("
");       
          }
          client.println("</html>");
          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();
    Serial.println("client disonnected");
  }
}

/*-----( Declare User-written Functions )-----*/
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));
   }
}// End printTemperature
//*********( THE END )***********

That stupid printTemperature() function rears it’s ugly head again. That function really should be called getPrintAndDiscardTemperature().

You need to separate the get part from the print part so that you can actually get the temperature to send to the client.

Hey Paul, Thanks for the quick reply. I apologize in advance for asking my next question. ( I did read another post of yours on this subject but am new to programming so it didn't completely resonate for me. I am new to the Arduino and programming, but I'm motivated and capable of learning.)

Is this what you are suggesting?

Serial.print("Probe 01 temperature is: "); getTemperature(Probe01); Serial.println();

and

client.print(Temperature(Probe01));

I tried a couple of variations but received several different errors. This particular code produced:

sketch_may26a.ino: In function 'void loop()': sketch_may26a:85: error: 'getTemperature' was not declared in this scope sketch_may26a:126: error: 'Temperature' was not declared in this scope

One final question can you recommend any books or other resources that provide a programming overview geared toward beginners. I purchased a C++ for Dummies book for my daughter's high school programming class, and thought it may help me. But wasn't sure how applicable that would be to the Arduino environment.

I suggest you write a function that [u]returns[/u] the temperature rather than prints it. IMO getTemperature() would be a reasonable name for that function.

Call that function, store the return value in a variable, do what you want with it afterwards whether that be printing into an HTTP response, printing to the serial port etc.

I suggest you write a function that returns the temperature rather than prints it. IMO getTemperature() would be a reasonable name for that function.

Call that function, store the return value in a variable, do what you want with it afterwards whether that be printing into an HTTP response, printing to the serial port etc.

Exactly the point I was trying to make.

Once you are able to obtain your temperatures, you may be able to modify the below test code to display them on a web page.

// zoomkat meta refresh server test code 4/12/13
// arduino IDE 1.0
// for W5100 ethernet shield
// the IP address will be dependent on your local network/router
// port 80 is default for HTTP, but can be changed as needed
// use IP address like http://192.168.1.102:84 in your brouser
// or http://zoomkat.no-ip.com:84 with dynamic IP service
// use the \ slash to escape the " in the html
// meta refresh set for 2 seconds

#include <SPI.h>
#include <Ethernet.h>
const int analogInPin0 = A0;
const int analogInPin1 = A1;
const int analogInPin2 = A2;
const int analogInPin3 = A3;
const int analogInPin4 = A4;
const int analogInPin5 = A5;


int x=0; //set refresh counter to 0
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,1,102); // ip in lan
EthernetServer server(84); //server is using port 84

void setup()
{
  // start the server
  Ethernet.begin(mac, ip);
  server.begin();
}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
     while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        // see if HTTP request has ended with blank line
        if (c == '\n') {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          
          //meta-refresh page every 2 seconds
          x=x+1; //page upload counter
          client.println("<HTML>");
          client.print("<HEAD>");
          client.print("<meta http-equiv='refresh' content='2'>"); //url='http://192.168.1.102:84/'
          client.print("<TITLE />Zoomkat's meta-refresh test 4-12-13</title>");
          client.print("</head>");
          client.println("<BODY>");
          client.print("Zoomkat's meta-refresh test 4-12-13");
          client.println("
");
                    
          client.print("page refresh number ");
          client.println(x); //current refresh count
          client.println("
");
          client.println("
");
          
          client.print("Zoomkat's arduino analog input values:");
          client.println("
");
          client.println("
");
          
          // output the value of each analog input pin
            client.print("analog input0 ");
            client.print(" is ");
            client.print(analogRead(analogInPin0));
            client.println("
");
            
            client.print("analog input1 ");
            client.print(" is ");
            client.print(analogRead(analogInPin1));
            client.println("
");
                        
            client.print("analog input2 ");
            client.print(" is ");
            client.print(analogRead(analogInPin2));
            client.println("
");
            
            client.print("analog input3 ");
            client.print(" is ");
            client.print(analogRead(analogInPin3));
            client.println("
");
                                    
            client.print("analog input4 ");
            client.print(" is ");
            client.print(analogRead(analogInPin4));
            client.println("
");
            
            client.print("analog input5 ");
            client.print(" is ");
            client.print(analogRead(analogInPin5));
            client.println("
");
                                    
           break;
          client.println("</BODY>");
          client.println("</HTML>");
         }
        }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
  }
}

Thanks for the replies.