Add the dry sensor

This commit is contained in:
Mathieu Maret 2016-06-02 01:31:57 +02:00
parent 786fedc74f
commit 4c09dcbb24
5 changed files with 54 additions and 2 deletions

View File

@ -42,6 +42,7 @@
#include "debug_sketch.h" #include "debug_sketch.h"
#include "BMP180.h" #include "BMP180.h"
#include "sensor_DHT.h" #include "sensor_DHT.h"
#include "dry_sensor.h"
#include "MQTT.h" #include "MQTT.h"
#include "Adafruit_MQTT.h" #include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h" #include "Adafruit_MQTT_Client.h"
@ -58,6 +59,7 @@ extern "C" {
double temp, pressure; double temp, pressure;
float dhtTemp, dhtHumidity; float dhtTemp, dhtHumidity;
int dryness;
uint8_t mode; uint8_t mode;
const char *hostName = ""; const char *hostName = "";
@ -234,6 +236,9 @@ void setup() {
if (!DHTSetup(CONFIG_DHT_PIN)){ if (!DHTSetup(CONFIG_DHT_PIN)){
SKETCH_DEBUG_PRINTLN("DHT init success"); SKETCH_DEBUG_PRINTLN("DHT init success");
} }
if (!DrySetup(CONFIG_DRY_POWER_PIN)){
SKETCH_DEBUG_PRINTLN("DRY init success");
}
WebSetupServer(mode); WebSetupServer(mode);
} }
#ifdef CONFIG_ENABLE_POWER_SAVE #ifdef CONFIG_ENABLE_POWER_SAVE
@ -266,6 +271,11 @@ void loop() {
SKETCH_DEBUG_PRINTLN(dhtHumidity); SKETCH_DEBUG_PRINTLN(dhtHumidity);
MqttDhtPublish(dhtTemp, dhtHumidity); MqttDhtPublish(dhtTemp, dhtHumidity);
} }
if (!DryGetMeasure(dryness)){
SKETCH_DEBUG_PRINT("Current dryness ");
SKETCH_DEBUG_PRINT((dryness*100)/1024);
SKETCH_DEBUG_PRINTLN("%");
}
nbCycle = 0; nbCycle = 0;
} }
} }

View File

@ -25,12 +25,16 @@
#define CONFIG_BMP180_SCL 0 #define CONFIG_BMP180_SCL 0
#endif #endif
#if defined(CONFIG_ENABLE_DHT) && !defined(CONFIG_DHT_PIN) #if defined(CONFIG_ENABLE_DHT) && !defined(CONFIG_DHT_PIN)
#error "When enabling DHT, you should configure SDA pin" #error "When enabling DHT, you should configure SDA pin"
#elif !defined(CONFIG_ENABLE_DHT) #elif !defined(CONFIG_ENABLE_DHT)
#define CONFIG_DHT_PIN 0 #define CONFIG_DHT_PIN 0
#endif #endif
#ifndef CONFIG_DRY_POWER_PIN
#define CONFIG_DRY_POWER_PIN -1
#endif
#ifndef CONFIG_SSID_NAME #ifndef CONFIG_SSID_NAME
#define CONFIG_SSID_NAME "ESPConfigurator" #define CONFIG_SSID_NAME "ESPConfigurator"
#endif #endif

View File

@ -15,6 +15,10 @@
#define CONFIG_ENABLE_DHT #define CONFIG_ENABLE_DHT
#define CONFIG_DHT_PIN 5 #define CONFIG_DHT_PIN 5
//#define CONFIG_ENABLE_DRY_SENSOR
//If the dry sensor is powered by a GPIO, this GPIO could be defined here
//#define CONFIG_DRY_POWER_PIN 13
// Enable light sleep to save some power (http://bbs.espressif.com/viewtopic.php?f=6&t=133&p=485&hilit=sleep+modem#p485) // Enable light sleep to save some power (http://bbs.espressif.com/viewtopic.php?f=6&t=133&p=485&hilit=sleep+modem#p485)
//#define CONFIG_ENABLE_POWER_SAVE //#define CONFIG_ENABLE_POWER_SAVE
@ -40,7 +44,6 @@
// Should have less value than MAXSUBSCRIPTIONS // Should have less value than MAXSUBSCRIPTIONS
#define CONFIG_MQTT_CONTROLLED_GPIO {2,13} #define CONFIG_MQTT_CONTROLLED_GPIO {2,13}
// EEPROM SIZE // EEPROM SIZE
// Max is 4096, but this amount will be allocated in RAM for reading its content // Max is 4096, but this amount will be allocated in RAM for reading its content
//#CONFIG_EEPROM_SIZE 256 //#CONFIG_EEPROM_SIZE 256

View File

@ -0,0 +1,11 @@
#pragma once
#ifdef CONFIG_ENABLE_DRY_SENSOR
int DrySetup(int powerGPIO);
int DryGetMeasure(int &dry);
bool DryIsConnected(){return true;}
#else
int DrySetup(int powerGPIO){return 0;}
int DryGetMeasure(int){return -1;}
bool DryIsConnected(){return false;}
#endif

View File

@ -0,0 +1,24 @@
#ifdef CONFIG_ENABLE_DRY_SENSOR
#include "dry_sensor.h"
int dryGPIO;
int DrySetup(int powerGPIO){
dryGPIO = powerGPIO;
if(dryGPIO >= 0){
pinMode(dryGPIO, OUTPUT);
}
return 0;
}
int DryGetMeasure(int &dry){
if(dryGPIO >= 0){
digitalWrite(dryGPIO,1);
delay(50);
}
dry = analogRead(A0);
if(dryGPIO >= 0){
digitalWrite(dryGPIO,0);
}
return 0;
}
#endif