public
Created

For an Arduino -- pulls sensor data from 2 DHT11's and uploads to a remote server using a GET call over an ethernet shield requires libraries from Adafruit for the DHT & EtherCard

  • Download Gist
webclient_dht.ino
Arduino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
// Example testing sketch for various DHT humidity/temperature sensors
// Written by ladyada, public domain
 
#include "DHT.h"
 
#define DHTPIN 2 // what pin we're connected to
#define DHTPIN2 3 // what pin we're connected to
 
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE2 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);
DHT dht2(DHTPIN2, DHTTYPE2);
 
char buff_h1[6];
char buff_t1[6];
char buff_h2[6];
char buff_t2[6];
 
String h1_string;
String t1_string;
String h2_string;
String t2_string;
String dht_string;
 
 
int timer = millis();
 
 
// Demo using DHCP and DNS to perform a web client request.
// 2011-06-08 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
 
/*
#include <EtherCard.h>
 
// ethernet interface mac address, must be unique on the LAN
static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };
 
byte Ethernet::buffer[700];
static uint32_t timer;
 
//char website[] PROGMEM = "www.google.com";
char website[] PROGMEM = "192.168.0.2";
 
// called when the client request is complete
static void my_callback (byte status, word off, word len) {
Serial.println(">>>");
Ethernet::buffer[off+300] = 0;
Serial.print((const char*) Ethernet::buffer + off);
Serial.println("...");
}
 
*/
 
void setup () {
Serial.begin(9600);
Serial.println("\n[webClient w/ DHT sensors]");
 
dht.begin();
dht2.begin();
Serial.println("DHT's initialized");
 
/*
if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0) // 3rd argument 10 added to match shield pi
Serial.println( "Failed to access Ethernet controller");
if (!ether.dhcpSetup())
Serial.println("DHCP failed");
 
ether.printIp("IP: ", ether.myip);
ether.printIp("GW: ", ether.gwip);
ether.printIp("DNS: ", ether.dnsip);
 
if (!ether.dnsLookup(website))
Serial.println("DNS failed");
ether.printIp("SRV: ", ether.hisip);
*/
}
 
void loop () {
// ether.packetLoop(ether.packetReceive());
if (millis() > timer) {
timer = millis() + 5000;
 
// Reading temperature or humidity takes about 250 milliseconds!
// Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
float h1 = dht.readHumidity();
float t1 = dht.readTemperature();
// float h1 = 36.00;
// float t1 = 18.00;
 
Serial.print("Sensor 1 temperature: ");
Serial.println(t1);
Serial.print("Sensor 1 Humidity: ");
Serial.println(h1);
 
float h2 = dht2.readHumidity();
float t2 = dht2.readTemperature();
 
Serial.print("Sensor 2 temperature: ");
Serial.println(t2);
Serial.print("Sensor 2 Humidity: ");
Serial.println(h2);
 
 
dtostrf(h1,5, 2, buff_h1);
h1_string = String(buff_h1);
dtostrf(t1,5, 2, buff_t1);
t1_string = String(buff_t1);
// dtostrf(h2,5, 2, buff_h2);
// h2_string = String(buff_h2);
// dtostrf(t2,5, 2, buff_t2);
// t2_string = String(buff_t2);
dht_string = "&h1=" + h1_string + "&t1=" + t1_string;
// + "&h2=" + h2_string + "&t2=" + t2_string;
// Serial.println();
// Serial.print("<<< REQ ");
// ether.browseUrl(PSTR("/arduino/logger1.php?pwd=secret"), dht_string, website, my_callback);
}
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.