// Definition für DHT -----------------
#define DHTPIN 2 // what pin we're connected to
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#include "DHT.h"
// Definition für Ethernet Shield und Plotly -----------------
#include <Ethernet.h>
#include <SPI.h>
#include "plotly_streaming_ethernet.h"
// Setup DHT ----------------------------------
DHT dht(DHTPIN, DHTTYPE);
// Setup Plotly -------------------------
// Sign up to plotly here: https://plot.ly
// View your API key and streamtokens here: https://plot.ly/settings
#define nTraces 2
// View your tokens here: https://plot.ly/settings
// Supply as many tokens as data traces
// e.g. if you want to ploty A0 and A1 vs time, supply two tokens
char *tokens[nTraces] = {"xxxxtokenxxxxx", "xxxxtokenxxxxx"};
// arguments: username, api key, streaming token, filename
plotly graph("xxxxxusernamexxxxxx", "xxxxxAPIkeyxxxxxx", tokens, "DHT", nTraces);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte my_ip[] = { 199, 168, 222, 18 }; // google will tell you: "public ip address"
void startEthernet(){
Serial.println("... Initializing ethernet");
if(Ethernet.begin(mac) == 0){
Serial.println("... Failed to configure Ethernet using DHCP");
// no point in carrying on, so do nothing forevermore:
// try to congifure using IP address instead of DHCP:
Ethernet.begin(mac, my_ip);
}
Serial.println("... Done initializing ethernet");
delay(1000);
}
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
startEthernet();
graph.fileopt="overwrite"; // See the "Usage" section in https://github.com/plotly/arduino-api for details
bool success;
success = graph.init();
if(!success){while(true){}}
graph.openStream();
}
unsigned long x;
int y;
void loop() {
// DHT auslesen --------------------------------------------- START
delay(2000);
// 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();
// Read temperature as Celsius
float t = dht.readTemperature();
// Read temperature as Fahrenheit
float f = dht.readTemperature(true);
float hi = dht.computeHeatIndex(f, h);
// DHT auslesen --------------------------------------------- ENDE
// PLOTLY schreiben ----------------------------------------- START
graph.plot(millis(), h, tokens[0]);
graph.plot(millis(), t, tokens[1]);
// PLOTLY schreiben ----------------------------------------- ENDE
}