Hi guys
I am newbie at arduino. I am working with Arduino Uno (EtherTen) and SHT15 (temperature and humidity sensor).I'm communicating between SHT15 sensor and Arduino EtherTen via serial port.
I wanted to post my sensed values on to webserver. Below is the code I used..
I have inserted serial print cmd to debug...it is reading the temp n humidity values and print on the serial monitor (all though it doesnt change everytime i run it, it is the same values)but bigger problem is that it doesnt print them on web browser.Please help me find the mistake in the code and fix it. Not able to find the mistake ..plzz help!!!Thank you
P.s I did change the IP n mac address.
#include <SHT1x.h>
#include <SPI.h>
#include <Ethernet.h>
#define dataPin 10
#define clockPin 11
// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
//IPAddress ip(192,168,1, 177);
byte mac[] = { 0xC2, 0x42, 0xFF, 0xB4, 0x56, 0xE7 };
IPAddress ip(192, 168, 2, 137)
// Initialize the Ethernet server library
// with the IP address and port you want to use
// (port 80 is default for HTTP):
SHT1x sht1x(dataPin, clockPin);
EthernetServer server(80);
void setup()
{
// start the Ethernet connection and the server:
Ethernet.begin(mac, ip);
server.begin();
Serial.begin(9600);
Serial.println("Starting up1");
}
void loop()
{
float temp_c;
int tempc;
// float temp_f
float humidity;
int humidity1;
// listen for incoming clients
EthernetClient 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();
Serial.println("Starting up");
temp_c = sht1x.readTemperatureC();
tempc = temp_c;
humidity = sht1x.readHumidity();
humidity1 = humidity;
Serial.println(temp_c);
Serial.println(humidity);
Serial.println(tempc);
Serial.println(humidity1);
client.print ("Temperature:");
client.print (temp_c);
client.print ("degrees Celsius");
client.print ("humidity");
client.print (humidity);
client.println ("%");
Serial.flush();
Serial.println("test2");
break;
Serial.println("test3");
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
Serial.println("test5");
}
else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
Serial.println("test4");
}
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
Serial.println("test6");
client.stop();
}
}