Combining Sketches

I’m new to both coding and the Arduino. My project is to create a simple, single sensor (DS18B20) web thermometer using an Arduino Uno and Arduino Ethernet Shield. I found two sample sketches that I have been able to modify and get to work independently. The first retrieves the temperature from the DS18B20 in C. I added an equation to convert to F, although there is probably an easier way to achieve this. The second sketch displays the inputs for Analog pins 1-5. While I do not have any inputs on these pins, the web server is working properly.

So my goal is to combine the two sketches, and change the webpage output from the Analog pins to the calculated F temperature. Unfortunately I am getting some errors and am stumped. Below are the errors:

sketch_2_may19a.ino: In function ‘void loop()’:
sketch_2_may19a:39: error: ‘getTemp’ was not declared in this scope
sketch_2_may19a:69: error: ‘TemperatureSum’ was not declared in this scope

Again the sketches worked independently so I’m guessing it must be the way I have combed them. Below is the “uncompleted” sketch. I have been making small changes at a time, so this is not the final version:

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

int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 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, 0xB5, 0x82, 0xF9, 0x09 };
IPAddress ip(192,168,1,107);

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

//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2

void setup(void) {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}

// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.print("server is at ");
Serial.println(Ethernet.localIP());
}

void loop() {
float temperature = getTemp() * 1.8 + 32;
Serial.println(temperature);

delay(100); //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("");
client.println("");
// output the value of each analog input pin
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
int sensorReading = analogRead(analogChannel);
client.print(“Hut Temperature Is “);
client.print(TemperatureSum);
client.print(” is “);
client.print(sensorReading);
client.println(”
“);
}
client.println(””);
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”);
}

}

sketch_2_may19a:39: error: 'getTemp' was not declared in this scope sketch_2_may19a:69: error: 'TemperatureSum' was not declared in this scope

I can't see anything with those names in the code you posted.

Hey thanks for the reply. 'getTemp' is in the line followint 'void loop(){' and 'TemperatureSum' is futher down in the 'client.println' section. As I stated earlier both sketches work well independtly but the combination of two has been troublesome. From the research I have done on this site and other, I'm wonder if the Onewire.h library is not loading properly. I thought 'getTemp' was included within that library.

Any help would be appreciated and thank you again for taking the time to look and respond to my post. :)

 float temperature = getTemp() * 1.8 + 32;

Maybe you deleted "getTemp" when you combined the sketches. Try putting it back.

Thanks AWOL you were right on track. While ' float temperature = getTem() * 1.8 +32;' was in the sketch, it was not in 'void loop' where it belongs. With just a little more tweaking my first version should be complete.

thanks again for your help! 8)

i am currently writing this simple code to check the temp sensor

#include <OneWire.h>

int DS18S20_Pin = 2; //DS18S20 Signal pin on digital 2

//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 2

void setup(void) {
 Serial.begin(9600);
}

void loop(void) 
{
 float temperature = getTemp();
 Serial.println(temperature);
 
 delay(100); //just here to slow down the output so it is easier to read
 
}

I m getting “sketch_feb27a:14: error: ‘getTemp’ was not declared in this scope”
can someone tell me why?

Because you haven't declared anything called "getTemp"