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