Go Down

Topic: Trying to post the values sensed from the sensor(SHT15) on to a Webserver (Read 982 times) previous topic - next topic

Spandy19

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();
   
  }
}

Spandy19

figured the prob...:P
I was using pin 10..which also used by the EtherTen as SS ethernet controller..silly me ..

robtillaart


if you post code, please use the # button. It provides tags to put around the code to make it more readable. You can modify your post to try it !

How do you like the SHT15?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Spandy19


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.

Code: [Select]


#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();
 
 }
}

Spandy19

Oh kul..thanks Robtillaart..yah I like SHT15..It is giving me prtty accurate results.
Have you used SHT15 ??

robtillaart


No I have some experience with a DHT22,  - http://arduino.cc/playground/Main/DHTLib - Although it is a bit slow I like it quite well.

and more recently I helped to develop a library for cozir,  - http://arduino.cc/forum/index.php?topic=91467.0 - This sensor is on my wishlist but I cannot justify it (yet ;)

For temperature only my favorite is the ds18B20 - http://www.milesburton.com/Dallas_Temperature_Control_Library - you can have multiple of them on a bus system extending the number of sensors one arduino can handle!

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Spandy19

Cozir looks good. The graphing system is it inbuilt (I like the way it has been displayed)??
I want to do something like that with my sensor too (btw SHT15 is cheap and works quite well). Graph the history ; time on the x-axis and temp, humidity on to the y-axis and display on a web server. At the moment my web server displays current temp,humidity.

robtillaart


No, not builtin,  the graphing system was built in C# with the help of some graphing library . You can ask if he posts the code for it. A C# express compiler can be free downloaded from microsoft. (google for the link).
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Go Up