Add the dry sensor
This commit is contained in:
parent
786fedc74f
commit
4c09dcbb24
@ -42,6 +42,7 @@
|
||||
#include "debug_sketch.h"
|
||||
#include "BMP180.h"
|
||||
#include "sensor_DHT.h"
|
||||
#include "dry_sensor.h"
|
||||
#include "MQTT.h"
|
||||
#include "Adafruit_MQTT.h"
|
||||
#include "Adafruit_MQTT_Client.h"
|
||||
@ -58,6 +59,7 @@ extern "C" {
|
||||
|
||||
double temp, pressure;
|
||||
float dhtTemp, dhtHumidity;
|
||||
int dryness;
|
||||
uint8_t mode;
|
||||
const char *hostName = "";
|
||||
|
||||
@ -234,6 +236,9 @@ void setup() {
|
||||
if (!DHTSetup(CONFIG_DHT_PIN)){
|
||||
SKETCH_DEBUG_PRINTLN("DHT init success");
|
||||
}
|
||||
if (!DrySetup(CONFIG_DRY_POWER_PIN)){
|
||||
SKETCH_DEBUG_PRINTLN("DRY init success");
|
||||
}
|
||||
WebSetupServer(mode);
|
||||
}
|
||||
#ifdef CONFIG_ENABLE_POWER_SAVE
|
||||
@ -266,6 +271,11 @@ void loop() {
|
||||
SKETCH_DEBUG_PRINTLN(dhtHumidity);
|
||||
MqttDhtPublish(dhtTemp, dhtHumidity);
|
||||
}
|
||||
if (!DryGetMeasure(dryness)){
|
||||
SKETCH_DEBUG_PRINT("Current dryness ");
|
||||
SKETCH_DEBUG_PRINT((dryness*100)/1024);
|
||||
SKETCH_DEBUG_PRINTLN("%");
|
||||
}
|
||||
nbCycle = 0;
|
||||
}
|
||||
}
|
||||
|
@ -25,12 +25,16 @@
|
||||
#define CONFIG_BMP180_SCL 0
|
||||
#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"
|
||||
#elif !defined(CONFIG_ENABLE_DHT)
|
||||
#define CONFIG_DHT_PIN 0
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_DRY_POWER_PIN
|
||||
#define CONFIG_DRY_POWER_PIN -1
|
||||
#endif
|
||||
|
||||
#ifndef CONFIG_SSID_NAME
|
||||
#define CONFIG_SSID_NAME "ESPConfigurator"
|
||||
#endif
|
||||
|
@ -15,6 +15,10 @@
|
||||
#define CONFIG_ENABLE_DHT
|
||||
#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)
|
||||
//#define CONFIG_ENABLE_POWER_SAVE
|
||||
|
||||
@ -40,7 +44,6 @@
|
||||
// Should have less value than MAXSUBSCRIPTIONS
|
||||
#define CONFIG_MQTT_CONTROLLED_GPIO {2,13}
|
||||
|
||||
|
||||
// EEPROM SIZE
|
||||
// Max is 4096, but this amount will be allocated in RAM for reading its content
|
||||
//#CONFIG_EEPROM_SIZE 256
|
||||
|
11
WifiControlSensor/dry_sensor.h
Normal file
11
WifiControlSensor/dry_sensor.h
Normal 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
|
24
WifiControlSensor/dry_sensor.ino
Normal file
24
WifiControlSensor/dry_sensor.ino
Normal 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
|
Loading…
Reference in New Issue
Block a user