improvements
This commit is contained in:
parent
2d8a30572b
commit
8ad568ea1b
@ -4,12 +4,25 @@
|
|||||||
|
|
||||||
#include <header.h>
|
#include <header.h>
|
||||||
|
|
||||||
|
const int numReadings = 20;
|
||||||
|
|
||||||
void setupCapacitiveSoilMoistureSensor() {
|
void setupCapacitiveSoilMoistureSensor() {
|
||||||
// pinMode(PIN_MS, INPUT);
|
// pinMode(PIN_MS, INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
int readCapacitiveSoilMoistureSensor()
|
int readCapacitiveSoilMoistureSensor()
|
||||||
{
|
{
|
||||||
int measurement = analogRead(PIN_MS);
|
int total = 0; // the running total
|
||||||
|
// read from the sensor:
|
||||||
|
for (int readIndex = 0; readIndex < numReadings; readIndex++)
|
||||||
|
{
|
||||||
|
total = total + analogRead(PIN_MS);
|
||||||
|
delay(2);
|
||||||
|
}
|
||||||
|
int measurement = total / numReadings;
|
||||||
|
Serial.print("soil moisture raw: ");
|
||||||
|
Serial.println(measurement);
|
||||||
|
// add the reading to the total:
|
||||||
|
//int measurement = analogRead(PIN_MS);
|
||||||
return map(measurement, VALUE_AIR, VALUE_WATER, 0, 100);
|
return map(measurement, VALUE_AIR, VALUE_WATER, 0, 100);
|
||||||
}
|
}
|
||||||
@ -26,8 +26,8 @@
|
|||||||
|
|
||||||
// MOISTURE SENSOR // A7
|
// MOISTURE SENSOR // A7
|
||||||
#define PIN_MS 35
|
#define PIN_MS 35
|
||||||
#define VALUE_WATER 275
|
#define VALUE_WATER 1650
|
||||||
#define VALUE_AIR 430
|
#define VALUE_AIR 3500
|
||||||
|
|
||||||
// Ventil
|
// Ventil
|
||||||
#define PIN_VENTIL 26
|
#define PIN_VENTIL 26
|
||||||
@ -41,8 +41,9 @@
|
|||||||
#define MQTT_HOST "mqtt.timovolkmann.de"
|
#define MQTT_HOST "mqtt.timovolkmann.de"
|
||||||
#define MQTT_PORT 1883
|
#define MQTT_PORT 1883
|
||||||
#define MQTT_DEVICE_ID "esp-timo"
|
#define MQTT_DEVICE_ID "esp-timo"
|
||||||
#define MQTT_TOPIC_BASE_SUBSCRIBE "smartgarden/commands"
|
#define MQTT_TOPIC_BASE_SUB "smartgarden/commands"
|
||||||
#define MQTT_TOPIC_BASE_PUBLISH "smartgarden/updates"
|
#define MQTT_TOPIC_BASE_PUB "smartgarden/updates"
|
||||||
|
#define MQTT_PATH_PUB MQTT_TOPIC_BASE_PUB "/" MQTT_DEVICE_ID "/"
|
||||||
|
|
||||||
// PUBLISH FREQUENCY (MS)
|
// PUBLISH FREQUENCY (MS)
|
||||||
#define FREQUENCY 3000
|
#define FREQUENCY 3000
|
||||||
|
|||||||
24
src/main.cpp
24
src/main.cpp
@ -3,11 +3,19 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <header.h>
|
#include <header.h>
|
||||||
|
#include <string>
|
||||||
|
//using namespace std;
|
||||||
|
|
||||||
|
#define MQTT_MOISTURE MQTT_PATH_PUB "moisture"
|
||||||
|
#define MQTT_TEMPERATURE MQTT_PATH_PUB "temperature"
|
||||||
|
#define MQTT_HUMIDITY MQTT_PATH_PUB "humidity"
|
||||||
|
#define MQTT_BRIGHTNESS MQTT_PATH_PUB "brightness"
|
||||||
|
|
||||||
unsigned long pingTimer = 0;
|
unsigned long pingTimer = 0;
|
||||||
char buffer[16];
|
char buffer[16];
|
||||||
|
|
||||||
void setup() {
|
void setup()
|
||||||
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
pingTimer = millis();
|
pingTimer = millis();
|
||||||
setupConnections();
|
setupConnections();
|
||||||
@ -19,32 +27,34 @@ void setup() {
|
|||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop()
|
||||||
if (millis() - pingTimer >= FREQUENCY) {
|
{
|
||||||
|
if (millis() - pingTimer >= FREQUENCY)
|
||||||
|
{
|
||||||
float lxValue = readLightSensorValue();
|
float lxValue = readLightSensorValue();
|
||||||
Serial.print("Light intensity: ");
|
Serial.print("Light intensity: ");
|
||||||
Serial.print(lxValue);
|
Serial.print(lxValue);
|
||||||
Serial.println(" lx");
|
Serial.println(" lx");
|
||||||
sprintf(buffer, "%f", lxValue);
|
sprintf(buffer, "%f", lxValue);
|
||||||
publishMessage("smartgarden/updates/esp-N2Ff4kaDgs45/brightness", buffer);
|
publishMessage(MQTT_BRIGHTNESS, buffer);
|
||||||
|
|
||||||
int mstValue = readCapacitiveSoilMoistureSensor();
|
int mstValue = readCapacitiveSoilMoistureSensor();
|
||||||
Serial.print("Soil moisture: ");
|
Serial.print("Soil moisture: ");
|
||||||
Serial.println(mstValue);
|
Serial.println(mstValue);
|
||||||
sprintf(buffer, "%i", mstValue);
|
sprintf(buffer, "%i", mstValue);
|
||||||
publishMessage("smartgarden/updates/esp-N2Ff4kaDgs45/moisture", buffer);
|
publishMessage(MQTT_MOISTURE, buffer);
|
||||||
|
|
||||||
float humidityValue = readHumidity();
|
float humidityValue = readHumidity();
|
||||||
Serial.print("Humidity: ");
|
Serial.print("Humidity: ");
|
||||||
Serial.println(humidityValue);
|
Serial.println(humidityValue);
|
||||||
sprintf(buffer, "%f", humidityValue);
|
sprintf(buffer, "%f", humidityValue);
|
||||||
publishMessage("smartgarden/updates/esp-N2Ff4kaDgs45/humidity", buffer);
|
publishMessage(MQTT_HUMIDITY, buffer);
|
||||||
|
|
||||||
float temperatureValue = readTemperature();
|
float temperatureValue = readTemperature();
|
||||||
Serial.print("Temperature: ");
|
Serial.print("Temperature: ");
|
||||||
Serial.println(temperatureValue);
|
Serial.println(temperatureValue);
|
||||||
sprintf(buffer, "%f", temperatureValue);
|
sprintf(buffer, "%f", temperatureValue);
|
||||||
publishMessage("smartgarden/updates/esp-N2Ff4kaDgs45/temperature", buffer);
|
publishMessage(MQTT_TEMPERATURE, buffer);
|
||||||
Serial.print("\n");
|
Serial.print("\n");
|
||||||
|
|
||||||
pingTimer = millis();
|
pingTimer = millis();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user