Go Down

Topic: blackwidow with temp sensor sht11 ??? (Read 2465 times) previous topic - next topic

thanosgen

hi i found this code for the classic over serial print with usb for my sensor SHT11(the same SHT15).
Code: [Select]
//Read temperature and humidity values from an SHT1x-series (SHT10,
//SHT11, SHT15) sensor.
#include <SHT1x.h>
// Specify data and clock connections and instantiate SHT1x object
#define dataPin  10
#define clockPin 11
SHT1x sht1x(dataPin, clockPin);

void setup()
{
  Serial.begin(38400); // Open serial connection to report values to host
  Serial.println("Starting up");
}

void loop()
{
 float temp_c;
 float temp_f;
 float humidity;

 // Read values from the sensor
 temp_c = sht1x.readTemperatureC();
 temp_f = sht1x.readTemperatureF();
 humidity = sht1x.readHumidity();

 // Print the values to the serial port
 Serial.print("Temperature: ");
 Serial.print(temp_c, DEC);
 Serial.print("C / ");
 Serial.print(temp_f, DEC);
 Serial.print("F. Humidity: ");
 Serial.print(humidity);
 Serial.println("%");

 delay(2000);
}


and i do this wifi with this code but it doesn't work.   why?????????
Code: [Select]
#include <WiServer.h>
#include <string.h>
#include <SHT1x.h>
#define WIRELESS_MODE_INFRA   1
#define WIRELESS_MODE_ADHOC   2
//#define watpin 12
#define dataPin  10
#define clockPin 11
#define funPin 5
//Wireless configuration parameters
unsigned char local_ip[] = { 192,168,1,5};   // IP address of WiShield
unsigned char gateway_ip[] = { 192,168,1,254};   // router or gateway IP address
unsigned char subnet_mask[] = { 255,255,255,0};   // subnet mask for the local network
const prog_char ssid[] PROGMEM = { "all"};      // max 32 bytes
unsigned char security_type = 0;   // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
const prog_char security_passphrase[] PROGMEM = { "12345678"};   // max 64 characters
prog_uchar wep_keys[] PROGMEM = {
 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,   // Key 0
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // Key 1
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,   // Key 2
 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00   // Key 3
};
unsigned char wireless_mode = WIRELESS_MODE_ADHOC;
unsigned char ssid_len;
unsigned char security_passphrase_len;
// End of wireless configuration parameters
SHT1x sht1x(dataPin, clockPin);
int tempC;
int humidity;

boolean sendMyPage(char* URL) {
      if (strcmp(URL, "/") == 0) {
          // Use print and println functions to write out the page
          WiServer.print("<html>");
          WiServer.print("<body><p><div align=center><b>TEMP :<hr /></b></p></body>");
          WiServer.print("</html>");
          WiServer.print(tempC, DEC);
          WiServer.println("</value> %</data>");
          WiServer.print("<data id=\"5\">\n<value>");
          return true;
            }
            // URL not found
         return false;
      }
void setup()
{
  Serial.begin(9600);
  WiServer.init(sendMyPage);
}
void loop()
{
 WiServer.server_task();
 tempC = sht1x.readTemperatureC();
 humidity = sht1x.readHumidity();
 delay(10);  
}




PaulS

Quote
but it doesn't work.   why?????????


How are we supposed to know?

What doesn't work? What do you expect to happen? What does happen? What is the difference between what you want and what you get?
The art of getting good answers lies in asking good questions.

thanosgen

#2
Jul 22, 2010, 01:48 pm Last Edit: Jul 22, 2010, 01:48 pm by thanosgen Reason: 1
i m sorry.well.if i put the code for the wifi when i connect to this in my web browser i cannot see anything.the browser has a problem.If i put another sensor works well.why?


can you tell me if you know what do this code in my wifi session?

Code: [Select]
   WiServer.print(tempC, DEC);
          WiServer.println("</value> %</data>");
          WiServer.print("<data id=\"5\">\n<value>");

PaulS

Quote
if i put the code for the wifi when i connect to this in my web browser i cannot see anything.the browser has a problem.


What kind of problem?

Quote
If i put another sensor works well.why?

Because you are reading the sensor correctly?

Without the wifi shield, are you able to read, and print to the serial monitor, good data from the temp sensor?

Quote
can you tell me if you know what do this code in my wifi session?

The first line sends the tempC value to the WiServer class, as a number (not as a string representation of a number). The 2nd and third lines close out some open tags in the html document and add some data to the page that is to be displayed in the browser.

Though, why you are trying to display the temperature followed by a % sign escapes me. As does the use of the DEC argument. Allowing the conversion of tempC to a string seems more reasonable to me.
The art of getting good answers lies in asking good questions.

thanosgen

1. my browser sed me an error 101.bad connection and i see only this message.

2.in serial print via usb my sendor sht11 works fine.when i told the blackwidow to read the temperature and sent it in html value makes something wrong and i cannot see anything in my browser.only an error 101.bad connection.

[glow]why?[/glow]

3.i copy these 3 lines from another project and i didn't change the % balue.now i write     ^C.



bsbrum

Hey - I am not only new here, but am new to the Arduino, and as added insult, I do not yet have my BlackWidow.

With all those disclaimers, I did see some things that I think need tweaking on your HTML and output...

This line:
          WiServer.print("<body><p><div align=center><b>TEMP :<hr /></b></p></body>");

contains a close body tag. That's bad if you want *anything* else to be displayed on the web page. It needs to be the last thing you send, or the browser has a body that only contains your TEMP: text, and then a bunch of malformed HTML.

Combined with this sequence:
          WiServer.println("</value> %</data>");
          WiServer.print("<data id=\"5\">\n<value>");

I think you should switch the use of println and print, making the println the LAST thing you do in terms of sending content to the browser, so it's throwing a newline at the end.

I don't know that the last bit really matters, but that </body> tag needs to be the LAST tag you send, for sure.

Good luck ... I hope to be following along with this exercise soon, when my backordered BlackWidow arrives.  :)

Go Up