Merge branch 'master' of https://github.com/0110/PlantCtrl
# Conflicts: # board/PlantCtrlESP32.kicad_pcb
This commit is contained in:
commit
b5031124f4
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -71,8 +71,8 @@
|
|||||||
#define BUTTON GPIO_NUM_0 /**< GPIO 0 - Fix button of NodeMCU */
|
#define BUTTON GPIO_NUM_0 /**< GPIO 0 - Fix button of NodeMCU */
|
||||||
#define CUSTOM1_PIN3 GPIO_NUM_2 /**< GPIO 2 - Custom GPIO controlling a MOSFET, connected to GND */
|
#define CUSTOM1_PIN3 GPIO_NUM_2 /**< GPIO 2 - Custom GPIO controlling a MOSFET, connected to GND */
|
||||||
#define CUSTOM1_PIN2 GPIO_NUM_12 /**< GPIO 4 - custom GPIO directly connected to GPIO header */
|
#define CUSTOM1_PIN2 GPIO_NUM_12 /**< GPIO 4 - custom GPIO directly connected to GPIO header */
|
||||||
#define I2C1_PIN2 GPIO_NUM_34 /**< GPIO 34 - I2C */
|
#define I2C1_SDA GPIO_NUM_34 /**< GPIO 34 - I2C */
|
||||||
#define I2C1_PIN3 GPIO_NUM_35 /**< GPIO 35 - I2C */
|
#define I2C1_SCL GPIO_NUM_35 /**< GPIO 35 - I2C */
|
||||||
/* @} */
|
/* @} */
|
||||||
|
|
||||||
/** \addtogroup Configuration
|
/** \addtogroup Configuration
|
||||||
|
@ -19,6 +19,7 @@ board_build.partitions = defaultWithSmallerSpiffs.csv
|
|||||||
lib_deps = ArduinoJson@6.16.1
|
lib_deps = ArduinoJson@6.16.1
|
||||||
OneWire
|
OneWire
|
||||||
DallasTemperature
|
DallasTemperature
|
||||||
|
pololu/VL53L0X
|
||||||
https://github.com/homieiot/homie-esp8266.git#develop
|
https://github.com/homieiot/homie-esp8266.git#develop
|
||||||
|
|
||||||
[platformio]
|
[platformio]
|
||||||
|
@ -28,6 +28,8 @@
|
|||||||
#include "DS2438.h"
|
#include "DS2438.h"
|
||||||
#include "soc/soc.h"
|
#include "soc/soc.h"
|
||||||
#include "soc/rtc_cntl_reg.h"
|
#include "soc/rtc_cntl_reg.h"
|
||||||
|
#include <Wire.h>
|
||||||
|
#include <VL53L0X.h>
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* DEFINES
|
* DEFINES
|
||||||
@ -82,6 +84,7 @@ unsigned long setupFinishedTimestamp;
|
|||||||
OneWire oneWire(SENSOR_ONEWIRE);
|
OneWire oneWire(SENSOR_ONEWIRE);
|
||||||
DallasTemperature sensors(&oneWire);
|
DallasTemperature sensors(&oneWire);
|
||||||
DS2438 battery(&oneWire, 0.0333333f, AMOUNT_SENOR_QUERYS);
|
DS2438 battery(&oneWire, 0.0333333f, AMOUNT_SENOR_QUERYS);
|
||||||
|
VL53L0X tankSensor;
|
||||||
|
|
||||||
Plant mPlants[MAX_PLANTS] = {
|
Plant mPlants[MAX_PLANTS] = {
|
||||||
Plant(SENSOR_PLANT0, OUTPUT_PUMP0, 0, &plant0, &mSetting0),
|
Plant(SENSOR_PLANT0, OUTPUT_PUMP0, 0, &plant0, &mSetting0),
|
||||||
@ -211,7 +214,8 @@ void readOneWireSensors(bool withMQTT)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!valid){
|
if (!valid)
|
||||||
|
{
|
||||||
//wrong family or crc errors on each retry
|
//wrong family or crc errors on each retry
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -230,7 +234,7 @@ void readOneWireSensors(bool withMQTT)
|
|||||||
if (valid)
|
if (valid)
|
||||||
{
|
{
|
||||||
Serial << "DS18S20 Temperatur " << String(buf) << " : " << temp << " °C " << endl;
|
Serial << "DS18S20 Temperatur " << String(buf) << " : " << temp << " °C " << endl;
|
||||||
if (strcmp(lipoSensorAddr.get(),buf) == 0)
|
if (strcmp(lipoSensorAddr.get(), buf) == 0)
|
||||||
{
|
{
|
||||||
if (withMQTT)
|
if (withMQTT)
|
||||||
{
|
{
|
||||||
@ -238,7 +242,7 @@ void readOneWireSensors(bool withMQTT)
|
|||||||
}
|
}
|
||||||
Serial << "Lipo Temperatur " << temp << " °C " << endl;
|
Serial << "Lipo Temperatur " << temp << " °C " << endl;
|
||||||
}
|
}
|
||||||
if (strcmp(waterSensorAddr.get(),buf) == 0)
|
if (strcmp(waterSensorAddr.get(), buf) == 0)
|
||||||
{
|
{
|
||||||
if (withMQTT)
|
if (withMQTT)
|
||||||
{
|
{
|
||||||
@ -281,33 +285,44 @@ void readPowerSwitchedSensors()
|
|||||||
delay(2);
|
delay(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Read the distance and give the temperature sensors some time */
|
Wire.setPins(SENSOR_TANK_TRG, SENSOR_TANK_ECHO);
|
||||||
|
Wire.begin();
|
||||||
|
tankSensor.setTimeout(500);
|
||||||
|
long start = millis();
|
||||||
|
bool distanceReady = false;
|
||||||
|
while (start + 500 > millis())
|
||||||
{
|
{
|
||||||
for (int i = 0; i < AMOUNT_SENOR_QUERYS; i++)
|
if (tankSensor.init())
|
||||||
{
|
{
|
||||||
unsigned long duration = 0;
|
distanceReady = true;
|
||||||
|
break;
|
||||||
digitalWrite(SENSOR_TANK_TRG, HIGH);
|
|
||||||
delayMicroseconds(20);
|
|
||||||
cli();
|
|
||||||
digitalWrite(SENSOR_TANK_TRG, LOW);
|
|
||||||
//10ms is > 2m tank depth
|
|
||||||
duration = pulseIn(SENSOR_TANK_ECHO, HIGH, 10);
|
|
||||||
sei();
|
|
||||||
|
|
||||||
int mmDis = duration * 0.3432 / 2;
|
|
||||||
if (mmDis > MAX_TANK_DEPTH)
|
|
||||||
{
|
|
||||||
waterRawSensor.add(0);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
waterRawSensor.add(mmDis);
|
delay(20);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (distanceReady)
|
||||||
|
{
|
||||||
|
tankSensor.setSignalRateLimit(0.1);
|
||||||
|
// increase laser pulse periods (defaults are 14 and 10 PCLKs)
|
||||||
|
tankSensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
|
||||||
|
tankSensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
|
||||||
|
tankSensor.setMeasurementTimingBudget(200000);
|
||||||
|
|
||||||
Serial << "Distance sensor " << waterRawSensor.getAverage() << " cm" << endl;
|
for (int readCnt = 0; readCnt < 5; readCnt++)
|
||||||
|
{
|
||||||
|
if(!tankSensor.timeoutOccurred()){
|
||||||
|
waterRawSensor.add(tankSensor.readRangeSingleMillimeters());
|
||||||
|
}
|
||||||
|
delay(10);
|
||||||
|
}
|
||||||
|
Serial << "Distance sensor " << waterRawSensor.getMedian() << " mm" << endl;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Serial.println("Failed to detect and initialize distance sensor!");
|
||||||
|
}
|
||||||
|
|
||||||
/* deactivate the sensors */
|
/* deactivate the sensors */
|
||||||
digitalWrite(OUTPUT_ENABLE_SENSOR, LOW);
|
digitalWrite(OUTPUT_ENABLE_SENSOR, LOW);
|
||||||
@ -612,8 +627,7 @@ void setup()
|
|||||||
// Set default values
|
// Set default values
|
||||||
|
|
||||||
//in seconds
|
//in seconds
|
||||||
deepSleepTime.setDefaultValue(600).setValidator([](long candidate)
|
deepSleepTime.setDefaultValue(600).setValidator([](long candidate) { return (candidate > 0) && (candidate < (60 * 60 * 2) /** 2h max sleep */); });
|
||||||
{ return (candidate > 0) && (candidate < (60 * 60 * 2) /** 2h max sleep */); });
|
|
||||||
deepSleepNightTime.setDefaultValue(600);
|
deepSleepNightTime.setDefaultValue(600);
|
||||||
wateringDeepSleep.setDefaultValue(5);
|
wateringDeepSleep.setDefaultValue(5);
|
||||||
ntpServer.setDefaultValue("pool.ntp.org");
|
ntpServer.setDefaultValue("pool.ntp.org");
|
||||||
@ -633,8 +647,6 @@ void setup()
|
|||||||
mConfigured = Homie.isConfigured();
|
mConfigured = Homie.isConfigured();
|
||||||
if (mConfigured)
|
if (mConfigured)
|
||||||
{
|
{
|
||||||
Serial << "Wifi mode set to " << WIFI_STA << endl;
|
|
||||||
WiFi.mode(WIFI_STA);
|
|
||||||
|
|
||||||
for (int i = 0; i < MAX_PLANTS; i++)
|
for (int i = 0; i < MAX_PLANTS; i++)
|
||||||
{
|
{
|
||||||
@ -675,10 +687,11 @@ void setup()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
readOneWireSensors(false);
|
readOneWireSensors(false);
|
||||||
|
//prevent BOD to be paranoid
|
||||||
|
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
|
||||||
digitalWrite(OUTPUT_ENABLE_PUMP, HIGH);
|
digitalWrite(OUTPUT_ENABLE_PUMP, HIGH);
|
||||||
delay(100);
|
delay(100);
|
||||||
Serial << "Wifi mode set to " << WIFI_AP_STA << endl;
|
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 1);
|
||||||
WiFi.mode(WIFI_AP_STA);
|
|
||||||
Serial.println("Initial Setup. Start Accesspoint...");
|
Serial.println("Initial Setup. Start Accesspoint...");
|
||||||
mDownloadMode = true;
|
mDownloadMode = true;
|
||||||
}
|
}
|
||||||
@ -796,6 +809,7 @@ void plantcontrol(bool withHomie)
|
|||||||
if (withHomie)
|
if (withHomie)
|
||||||
{
|
{
|
||||||
sensorWater.setProperty("remaining").send(String(waterLevelMax.get() - waterRawSensor.getAverage()));
|
sensorWater.setProperty("remaining").send(String(waterLevelMax.get() - waterRawSensor.getAverage()));
|
||||||
|
sensorWater.setProperty("distance").send(String(waterRawSensor.getAverage()));
|
||||||
sensorLipo.setProperty("percent").send(String(100 * batteryVoltage / VOLT_MAX_BATT));
|
sensorLipo.setProperty("percent").send(String(100 * batteryVoltage / VOLT_MAX_BATT));
|
||||||
sensorLipo.setProperty("volt").send(String(batteryVoltage));
|
sensorLipo.setProperty("volt").send(String(batteryVoltage));
|
||||||
sensorLipo.setProperty("current").send(String(battery.getCurrent()));
|
sensorLipo.setProperty("current").send(String(battery.getCurrent()));
|
||||||
|
Loading…
Reference in New Issue
Block a user