DHT11 sensor code not working

Here is the code

#include <Bridge.h>
#include <YunServer.h>
#include <YunClient.h> 

#include "DHT.h"
#define DHTPIN 2     // what pin we're connected to

#define DHTTYPE DHT11   // DHT 11 

// Connect pin 1 (on the left) of the sensor to +3.3V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);
 
YunServer server;
 
void setup() {
  Bridge.begin();
  server.listenOnLocalhost();
  server.begin();
  
  dht.begin();
}
 
void loop() {
  YunClient client = server.accept();
  
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();
 
  if (client) {
    String command = client.readString();
    command.trim();
    if (isnan(t) || isnan(h)) {
      client.print("Failed to read from DHT");
      } 
    else {
      client.print("
Current temperature: ");
      client.print(t);
      client.print(" degrees C");
      client.print("
Current Humidity: ");
      client.print(h);
    }
    client.stop();
  }
  delay(50);
}

Here is the web HTML code

<!DOCTYPE html>
<html>
	<head>
	<script type="text/javascript" src="zepto.min.js"></script>
	  <script type="text/javascript">
	   	function refresh() {
		  	$('#content').load('/arduino/temperature');
	  	}
</script>

	</head>
	<body onload="setInterval(refresh, 2000);">
		<span id="content">Waiting for Arduino...</span>
	</body>
</html>

I do get “Waiting for Arduino…” when I browse to the url but the page never gives the temperature or Humidity.

I know that the sensor works becouse this sketch works in the serial monitor

// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
#include <Console.h>
#include "DHT.h"

#define DHTPIN 2     // what pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11 
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

DHT dht(DHTPIN, DHTTYPE);

void setup() {
  Bridge.begin();
  Console.begin(); 
  while (!Console){
    ; // wait for Console port to connect.
  }
  Console.println("You're connected to the Console!!!!");
  Console.println("DHTxx test!");
  
  dht.begin();
}

void loop() {
  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h)) {
    Console.println("Failed to read from DHT");
  } else {
    Console.print("Humidity: "); 
    Console.print(h);
    Console.print(" %\t");
    Console.print("Temperature: "); 
    Console.print(t);
    Console.println(" *C");
    delay(5000); // Poll every 50ms
  }
  
}

Any idea what I could have wrong? Thanks

WOW…
The issue was don’t use “internet explorer 11.0.2”
use CHROME

chrisnet:
WOW…
The issue was don’t use “internet explorer 11.0.2”
use CHROME

:fearful: :fearful: :fearful: Internet Exploder?

Well, I am sure that Firefox and Opera work fine as well… :wink:

Ralf