lcsc/jlcpcb order changes

This commit is contained in:
2020-11-29 05:04:46 +01:00
18 changed files with 12243 additions and 12367 deletions

1
esp32/.gitignore vendored
View File

@@ -4,3 +4,4 @@
.vscode/launch.json
.vscode/ipch
doc/
custom_platformio.ini

View File

@@ -0,0 +1,17 @@
[env:esp32doit-devkit-v1]
platform = espressif32
board = esp32doit-devkit-v1
framework = arduino
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
board_build.partitions = defaultWithSmallerSpiffs.csv
extra_configs = custom_platformio.ini
; the latest development brankitchen-lightch (convention V3.0.x)
lib_deps = ArduinoJson@6.16.1
https://github.com/homieiot/homie-esp8266.git#v3.0
OneWire
DallasTemperature
; add additional parameter, like the upload port
upload_port=/dev/ttyUSB1

View File

@@ -89,10 +89,6 @@
#define SOLAR_CHARGE_MIN_VOLTAGE 7 /**< Sun is rising (morning detected) */
#define SOLAR_CHARGE_MAX_VOLTAGE 9 /**< Sun is shining (noon) */
#define HC_SR04 /**< Ultrasonic distance sensor to measure water level */
#define SENSOR_SR04_ECHO 17 /**< GPIO 17 - Echo */
#define SENSOR_SR04_TRIG 23 /**< GPIO 23 - Trigger */
#define MAX_CONFIG_SETTING_ITEMS 50 /**< Parameter, that can be configured in Homie */
#define PANIK_MODE_DEEPSLEEP (60 * 60 * 5U) /**< 5 hours in usecond */

View File

@@ -15,10 +15,12 @@ framework = arduino
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
board_build.partitions = defaultWithSmallerSpiffs.csv
upload_port=/dev/ttyUSB1
; the latest development brankitchen-lightch (convention V3.0.x)
lib_deps = ArduinoJson@6.16.1
https://github.com/homieiot/homie-esp8266.git#v3.0
OneWire
DallasTemperature
[platformio]
extra_configs = custom_platformio.ini

View File

@@ -55,10 +55,8 @@ int wakeUpReason = WAKEUP_REASON_UNDEFINED;
bool volatile mode3Active = false; /**< Controller must not sleep */
bool volatile mDeepsleep = false;
int plantSensor1 = 0;
int mWaterGone = -1; /**< Amount of centimeter, where no water is seen */
int readCounter = 0;
bool mConfigured = false;
@@ -117,6 +115,30 @@ long getLastMoisture(int plantId)
}
}
long getDistance(){
unsigned int distance;
byte startByte, h_data, l_data, sum = 0;
byte buf[3];
startByte = (byte)Serial.read();
if(startByte == 255){
Serial.readBytes(buf, 3);
h_data = buf[0];
l_data = buf[1];
sum = buf[2];
distance = (h_data<<8) + l_data;
if(((startByte + h_data + l_data)&0xFF) != sum){
return -1;
}
else{
return distance;
}
} else {
return -2;
}
}
void readSystemSensors()
{
for (int i=0; i < 5; i++) {
@@ -205,7 +227,7 @@ void mode2MQTT()
if (lastPumpRunning != -1)
{
long waterDiff = mWaterGone - lastWaterValue;
long waterDiff = waterRawSensor.getAverage() - lastWaterValue;
//TODO attribute used water in ml to plantid
}
for (int i = 0; i < MAX_PLANTS; i++)
@@ -228,9 +250,9 @@ void mode2MQTT()
mPlants[i].setProperty("moist").send(String(pct));
mPlants[i].setProperty("moistraw").send(String(raw));
}
sensorWater.setProperty("remaining").send(String(waterLevelMax.get() - mWaterGone));
Serial << "W : " << mWaterGone << " cm (" << String(waterLevelMax.get() - mWaterGone) << "%)" << endl;
lastWaterValue = mWaterGone;
sensorWater.setProperty("remaining").send(String(waterLevelMax.get() - waterRawSensor.getAverage()));
Serial << "W : " << waterRawSensor.getAverage() << " cm (" << String(waterLevelMax.get() - waterRawSensor.getAverage()) << "%)" << endl;
lastWaterValue = waterRawSensor.getAverage();
sensorLipo.setProperty("percent").send(String(100 * lipoRawSensor.getAverage() / 4095));
sensorLipo.setProperty("volt").send(String(getBatteryVoltage()));
@@ -389,7 +411,8 @@ bool readSensors()
delay(200);
/* Required to read the temperature once */
for (int i = 0; i < 5; i++)
int readAgain = 5;
while (readAgain > 0)
{
int sensors = dallas.readAllTemperatures(pFloat, 2);
if (sensors > 0)
@@ -402,6 +425,19 @@ bool readSensors()
Serial << "t2: " << String(temp[1]) << endl;
temp2.add(temp[1]);
}
if ((temp1.getAverage() - rtcLastTemp1 > TEMPERATURE_DELTA_TRIGGER_IN_C) ||
(rtcLastTemp1 - temp1.getAverage() > TEMPERATURE_DELTA_TRIGGER_IN_C)) {
leaveMode1 = true;
}
if ((temp2.getAverage() - rtcLastTemp2 > TEMPERATURE_DELTA_TRIGGER_IN_C) ||
(rtcLastTemp2 - temp2.getAverage() > TEMPERATURE_DELTA_TRIGGER_IN_C)) {
leaveMode1 = true;
}
if(!leaveMode1){
readAgain = 0;
}
readAgain--;
delay(50);
}
@@ -429,13 +465,15 @@ bool readSensors()
rtcLastSolarVoltage = getSolarVoltage();
/* Use the Ultrasonic sensor to measure waterLevel */
digitalWrite(SENSOR_SR04_TRIG, LOW);
delayMicroseconds(2);
digitalWrite(SENSOR_SR04_TRIG, HIGH);
delayMicroseconds(10);
digitalWrite(SENSOR_SR04_TRIG, LOW);
float duration = pulseIn(SENSOR_SR04_ECHO, HIGH);
waterRawSensor.add((duration * .343) / 2);
for (int i = 0; i < 5; i++)
{
while(!Serial.available()){}
unsigned int distance = getDistance();
if(distance > 0){
waterRawSensor.add(distance);
}
}
Serial << "Distance sensor " << waterRawSensor.getAverage() << " cm" << endl;
/* deactivate the sensors */
digitalWrite(OUTPUT_SENSOR, LOW);
return leaveMode1;
@@ -717,7 +755,7 @@ void mode2()
*/
void setup()
{
Serial.begin(115200);
Serial.begin(9600);
Serial.setTimeout(1000); // Set timeout of 1 second
Serial << endl
<< endl;
@@ -807,4 +845,4 @@ void loop()
}
}
/** @}*/
/** @}*/