developing with mini, using non unified dht
This commit is contained in:
parent
f74b5fed6b
commit
5c0fe475eb
@ -33,3 +33,13 @@ The actual code i am trying to write will use the Basic to switch a Fan.
|
|||||||
I will add 2 DHT22 in a case like this https://www.thingiverse.com/thing:4852992
|
I will add 2 DHT22 in a case like this https://www.thingiverse.com/thing:4852992
|
||||||
|
|
||||||
The sketch will simply compare temeratures and switch the relay on/off
|
The sketch will simply compare temeratures and switch the relay on/off
|
||||||
|
|
||||||
|
### Development
|
||||||
|
|
||||||
|
Turns out the Sonoff Basic has very very little free pins. Maybe just one.
|
||||||
|
|
||||||
|
So to use it we will have to use rx/tx for the sensors, which does make Development
|
||||||
|
difficult (no Serial). So i will develop on a D1 Mini that is also a 8266.
|
||||||
|
|
||||||
|
OTA is already working and so once debugging is done it "should" just be upload.
|
||||||
|
But i'll make a backdoor to dump serial links to the web interface that i am planning anyway.
|
||||||
|
@ -16,76 +16,38 @@
|
|||||||
#include <DHT_U.h>
|
#include <DHT_U.h>
|
||||||
|
|
||||||
|
|
||||||
#define DHTPIN 2
|
// mini https://chewett.co.uk/blog/1066/pin-numbering-for-wemos-d1-mini-esp8266/
|
||||||
|
DHT dht_in(4, DHT11); // D2 on mini
|
||||||
|
DHT dht_out(5, DHT11); // D1 on mini
|
||||||
|
|
||||||
#define DHTTYPE DHT22 // DHT 22 (AM2302)
|
// Set delay between sensor readings based on sensor details.
|
||||||
|
uint32_t delayMS = 3000 ;
|
||||||
|
|
||||||
DHT_Unified dht(DHTPIN, DHTTYPE);
|
|
||||||
|
|
||||||
uint32_t delayMS;
|
|
||||||
|
|
||||||
const char* ssid = "fan_XXX";
|
const char* ssid = "fan_XXX";
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
ota_setup(ssid);
|
ota_setup(ssid);
|
||||||
|
Serial.println(WiFi.softAPIP());
|
||||||
|
|
||||||
|
|
||||||
// Initialize device.
|
// Initialize device.
|
||||||
dht.begin();
|
dht_in.begin();
|
||||||
Serial.println(F("DHTxx Unified Sensor Example"));
|
dht_out.begin();
|
||||||
// Print temperature sensor details.
|
Serial.println(F("DHT set up"));
|
||||||
sensor_t sensor;
|
|
||||||
dht.temperature().getSensor(&sensor);
|
|
||||||
Serial.println(F("------------------------------------"));
|
|
||||||
Serial.println(F("Temperature Sensor"));
|
|
||||||
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
|
|
||||||
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
|
|
||||||
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
|
|
||||||
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
|
|
||||||
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
|
|
||||||
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
|
|
||||||
Serial.println(F("------------------------------------"));
|
|
||||||
// Print humidity sensor details.
|
|
||||||
dht.humidity().getSensor(&sensor);
|
|
||||||
Serial.println(F("Humidity Sensor"));
|
|
||||||
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
|
|
||||||
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
|
|
||||||
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
|
|
||||||
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%"));
|
|
||||||
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%"));
|
|
||||||
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%"));
|
|
||||||
Serial.println(F("------------------------------------"));
|
|
||||||
// Set delay between sensor readings based on sensor details.
|
|
||||||
delayMS = sensor.min_delay / 1000;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
ArduinoOTA.handle();
|
ArduinoOTA.handle();
|
||||||
Serial.println(WiFi.softAPIP());
|
|
||||||
|
|
||||||
// Delay between measurements.
|
// Delay between measurements.
|
||||||
delay(delayMS);
|
delay(delayMS);
|
||||||
|
|
||||||
// Get temperature event and print its value.
|
// Get temperature event and print its value.
|
||||||
sensors_event_t event;
|
Serial.print(F("Temperature inside: "));
|
||||||
dht.temperature().getEvent(&event);
|
Serial.print(dht_in.readTemperature());
|
||||||
if (isnan(event.temperature)) {
|
|
||||||
Serial.println(F("Error reading temperature!"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Serial.print(F("Temperature: "));
|
|
||||||
Serial.print(event.temperature);
|
|
||||||
Serial.println(F("°C"));
|
Serial.println(F("°C"));
|
||||||
}
|
Serial.print(F("Temperature outside: "));
|
||||||
// Get humidity event and print its value.
|
Serial.print(dht_out.readTemperature());
|
||||||
dht.humidity().getEvent(&event);
|
Serial.println("°C");
|
||||||
if (isnan(event.relative_humidity)) {
|
|
||||||
Serial.println(F("Error reading humidity!"));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
Serial.print(F("Humidity: "));
|
|
||||||
Serial.print(event.relative_humidity);
|
|
||||||
Serial.println(F("%"));
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user