Added logging functionality
This commit is contained in:
@ -5,7 +5,7 @@ framework = arduino
|
|||||||
upload_speed=921600
|
upload_speed=921600
|
||||||
|
|
||||||
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY -DVERSION=${sysenv.DRONE_SEMVER}
|
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY -DVERSION=${sysenv.DRONE_SEMVER}
|
||||||
lib_deps = https://github.com/homieiot/homie-esp8266.git#develop, DHT sensor library for ESPx
|
lib_deps = https://github.com/homieiot/homie-esp8266.git#develop, DHT sensor library for ESPx, HomieLoggerNode
|
||||||
|
|
||||||
[env:nodemcu]
|
[env:nodemcu]
|
||||||
board = nodemcu
|
board = nodemcu
|
||||||
|
19
src/main.cpp
19
src/main.cpp
@ -1,6 +1,10 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#include <Homie.h>
|
#include <Homie.h>
|
||||||
|
|
||||||
|
#include <LoggerNode.h>
|
||||||
|
LoggerNode LN;
|
||||||
|
|
||||||
#include "DHTesp.h"
|
#include "DHTesp.h"
|
||||||
DHTesp dht;
|
DHTesp dht;
|
||||||
|
|
||||||
@ -24,12 +28,11 @@ bool powerStateHandler(const HomieRange& range, const String& value)
|
|||||||
if(value == "on")
|
if(value == "on")
|
||||||
{
|
{
|
||||||
OUTPUT_SET(true);
|
OUTPUT_SET(true);
|
||||||
Homie.getLogger() << "Power is on" << endl;
|
LN.logf(__PRETTY_FUNCTION__, LoggerNode::INFO, "Power ON");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
OUTPUT_SET(false);
|
OUTPUT_SET(false); LN.logf(__PRETTY_FUNCTION__, LoggerNode::INFO, "Power OFF");
|
||||||
Homie.getLogger() << "Power is off" << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -45,7 +48,7 @@ bool powerTimerHandler(const HomieRange& range, const String& value)
|
|||||||
next_timer_update = millis() + 60*1000;
|
next_timer_update = millis() + 60*1000;
|
||||||
powerNode.setProperty("timer").send(String(settimer));
|
powerNode.setProperty("timer").send(String(settimer));
|
||||||
powerNode.setProperty("state").send("on");
|
powerNode.setProperty("state").send("on");
|
||||||
Homie.getLogger() << "Power is on for " << settimer << "minutes" << endl;
|
LN.logf(__PRETTY_FUNCTION__, LoggerNode::INFO, "Power on for %d minutes", settimer);
|
||||||
OUTPUT_SET(true);
|
OUTPUT_SET(true);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -91,8 +94,7 @@ void loopHandleTemperature()
|
|||||||
{
|
{
|
||||||
float humidity = dht.getHumidity();
|
float humidity = dht.getHumidity();
|
||||||
float temperature = dht.getTemperature();
|
float temperature = dht.getTemperature();
|
||||||
|
LN.logf(__PRETTY_FUNCTION__, LoggerNode::DEBUG, "Temperature: %f C Humidity: %f", temperature, humidity);
|
||||||
Homie.getLogger() << "Temperature: " << temperature << "°C " << humidity << "% Humidty" << endl;
|
|
||||||
temperatureNode.setProperty("temperature").send(String(temperature));
|
temperatureNode.setProperty("temperature").send(String(temperature));
|
||||||
temperatureNode.setProperty("humidity").send(String(humidity));
|
temperatureNode.setProperty("humidity").send(String(humidity));
|
||||||
lastTemperatureSent = millis();
|
lastTemperatureSent = millis();
|
||||||
@ -107,10 +109,11 @@ void loopHandler()
|
|||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(CONFIG_SERIAL_BAUDRATE);
|
|
||||||
|
|
||||||
Homie_setFirmware("deskcontrol", VERSION);
|
Homie_setFirmware("deskcontrol", VERSION);
|
||||||
|
Homie.setLoggingPrinter(&Serial);
|
||||||
|
Serial.begin(CONFIG_SERIAL_BAUDRATE);
|
||||||
|
|
||||||
Homie.disableResetTrigger();
|
Homie.disableResetTrigger();
|
||||||
|
|
||||||
//Power
|
//Power
|
||||||
|
Reference in New Issue
Block a user