Last active
December 10, 2015 00:49
-
-
Save amites/4354349 to your computer and use it in GitHub Desktop.
Combined 2 example scripts with a bit of scripting to publish sensor data from 2 DHT11 sensors to a remote web-server using a GET request webClient_dht -- doesn't work with error code in comments below
webClient -- works to post to web-server using a GET request
DHTtester1 -- works to read sensor data and concatenate floats to a string and retur…
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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; | |
void setup() { | |
Serial.begin(9600); | |
Serial.println("DHTxx test!"); | |
dht.begin(); | |
dht2.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 h1 = dht.readHumidity(); | |
float t1 = dht.readTemperature(); | |
float h2 = dht2.readHumidity(); | |
float t2 = dht2.readTemperature(); | |
dtostrf(h1,5, 2, buff_h1); | |
h1_string = String(buff_h1); | |
dtostrf(t1,5, 2, buff_t1); | |
t1_string = String(buff_t1); | |
// check if returns are valid, if they are NaN (not a number) | |
// then something went wrong! | |
if (isnan(t1) || isnan(h1)) { | |
Serial.println("Failed to read from DHT"); | |
} else { | |
dht_string = "h1=" + h1_string + "&t1=" + t1_string; | |
Serial.println(dht_string); | |
// Serial.print("Humidity: "); | |
// Serial.print(h); | |
// Serial.print(" %\t"); | |
// Serial.print("Temperature: "); | |
// Serial.print(t); | |
// Serial.println(" *C"); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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]"); | |
if (ether.begin(sizeof Ethernet::buffer, mymac, 10) == 0) | |
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; | |
Serial.println(); | |
Serial.print("<<< REQ "); | |
ether.browseUrl(PSTR("/arduino/logger1.php?pwd=secret"), "", website, my_callback); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// webClient_dht.ino: In function ‘void loop()’: | |
// webClient_dht:112: error: no matching function for call to ‘EtherCard::browseUrl(char*, String&, char [12], void (&)(byte, word, word))’ | |
// /home/USER/sketchbook/libraries/EtherCard/EtherCard.h:152: note: candidates are: static void EtherCard::browseUrl(prog_char*, const char*, prog_char*, void (*)(uint8_t, uint16_t, uint16_t)) | |
// 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; | |
// 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(); | |
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; | |
// float h2 = dht2.readHumidity(); | |
// float t2 = dht2.readTemperature(); | |
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); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
description formatting is completely lost -- related arduino forum post:: http://arduino.cc/forum/index.php/topic,138548.0.html