Nodemcu V.2 mit DHT22, BMP180 Sensoren verbinden und auf Cayenne Dashboarden
Nodemcu, DHT22, BMP180
-------Sketch---------
#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
#include "DHT.h"
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP085_U.h> // BMP180 SDA-D2 SCL-D1
#define DHTPIN 14 // DHT22 Datapin to D5-GPIO14
#define DHTTYPE DHT22
// WiFi network info.
char ssid[] = "";
char wifiPassword[] = "";
// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "";
char password[] = "";
char clientID[] = "";
unsigned long lastMillis = 0;
Adafruit_BMP085_Unified bmp = Adafruit_BMP085_Unified(10180);
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
dht.begin();
Wire.begin(5, 4); // SDA, SDL
if (!bmp.begin());
}
void loop() {
Cayenne.loop();
sensors_event_t event;
float humidity = dht.readHumidity();
float temp1 = dht.readTemperature();
float pressure;
bmp.getPressure(&pressure);
float temp2;
bmp.getTemperature(&temp2);
Cayenne.virtualWrite(1, temp1, TYPE_TEMPERATURE, UNIT_CELSIUS);
Cayenne.virtualWrite(2, temp2, TYPE_TEMPERATURE, UNIT_CELSIUS);
Cayenne.virtualWrite(3, temp1-temp2, TYPE_TEMPERATURE, UNIT_CELSIUS);
Cayenne.virtualWrite(4, pressure/100, TYPE_BAROMETRIC_PRESSURE, UNIT_PASCAL);
Cayenne.virtualWrite(5, humidity, TYPE_RELATIVE_HUMIDITY, UNIT_PERCENT);
}