developing with mini, using non unified dht

This commit is contained in:
Torsten Ruger 2021-06-23 11:49:22 +03:00
parent f74b5fed6b
commit 5c0fe475eb
2 changed files with 28 additions and 56 deletions

View File

@ -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
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.

View File

@ -16,76 +16,38 @@
#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)
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
// Set delay between sensor readings based on sensor details.
uint32_t delayMS = 3000 ;
const char* ssid = "fan_XXX";
void setup() {
Serial.begin(115200);
ota_setup(ssid);
Serial.println(WiFi.softAPIP());
// Initialize device.
dht.begin();
Serial.println(F("DHTxx Unified Sensor Example"));
// Print temperature sensor details.
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;
dht_in.begin();
dht_out.begin();
Serial.println(F("DHT set up"));
}
void loop() {
ArduinoOTA.handle();
Serial.println(WiFi.softAPIP());
// Delay between measurements.
delay(delayMS);
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
}
else {
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
}
}
Serial.print(F("Temperature inside: "));
Serial.print(dht_in.readTemperature());
Serial.println(F("°C"));
Serial.print(F("Temperature outside: "));
Serial.print(dht_out.readTemperature());
Serial.println("°C");
}