Compare commits
10 Commits
c1c07a4003
...
v.0.5.1
Author | SHA1 | Date | |
---|---|---|---|
d0f3845dc5 | |||
e9e0c17a8a | |||
2966170165 | |||
6be0baf301 | |||
cee415446a | |||
91a29db8ed | |||
7a37df2fff | |||
b5498b7173 | |||
0287456f1e | |||
019592f1ad |
@ -6,7 +6,6 @@ steps:
|
|||||||
image: python:3
|
image: python:3
|
||||||
commands:
|
commands:
|
||||||
- pip install platformio
|
- pip install platformio
|
||||||
- pio check
|
|
||||||
- pio run
|
- pio run
|
||||||
- name: upload
|
- name: upload
|
||||||
image: python:3
|
image: python:3
|
||||||
@ -22,5 +21,12 @@ steps:
|
|||||||
base_url: https://code.jcktrue.dk
|
base_url: https://code.jcktrue.dk
|
||||||
files:
|
files:
|
||||||
- .pio/build/nodemcu/firmware.bin
|
- .pio/build/nodemcu/firmware.bin
|
||||||
|
checksum:
|
||||||
|
- md5
|
||||||
|
- sha1
|
||||||
|
- sha256
|
||||||
|
- sha512
|
||||||
|
- adler32
|
||||||
|
- crc32
|
||||||
when:
|
when:
|
||||||
event: tag
|
event: tag
|
||||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
|||||||
.pio
|
.pio
|
||||||
data/homie/config.json
|
data/homie/config.json
|
||||||
nbproject
|
nbproject
|
||||||
|
.vscode
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
#ifndef CONFIG_H
|
#ifndef CONFIG_H
|
||||||
|
|
||||||
#define CONFIG_H
|
#define CONFIG_H
|
||||||
|
|
||||||
|
#ifndef VERSION
|
||||||
|
//SEMVER style version
|
||||||
|
#define VERSION "0.4.5-Dev"
|
||||||
|
#endif
|
||||||
|
|
||||||
#define CONFIG_SERIAL_BAUDRATE 115200
|
#define CONFIG_SERIAL_BAUDRATE 115200
|
||||||
|
|
||||||
#define CONFIG_IO_RELAY D1
|
#define CONFIG_IO_RELAY D1
|
||||||
|
@ -1,30 +1,11 @@
|
|||||||
#
|
|
||||||
# Project Configuration File
|
|
||||||
#
|
|
||||||
# A detailed documentation with the EXAMPLES is located here:
|
|
||||||
# http://docs.platformio.org/en/latest/projectconf.html
|
|
||||||
#
|
|
||||||
|
|
||||||
# A sign `#` at the beginning of the line indicates a comment
|
|
||||||
# Comment lines are ignored.
|
|
||||||
|
|
||||||
# Simple and base environment
|
|
||||||
# [env:mybaseenv]
|
|
||||||
# platform = %INSTALLED_PLATFORM_NAME_HERE%
|
|
||||||
# framework =
|
|
||||||
# board =
|
|
||||||
#
|
|
||||||
# Automatic targets - enable auto-uploading
|
|
||||||
# targets = upload
|
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
framework = arduino
|
framework = arduino
|
||||||
|
|
||||||
upload_speed=921600
|
upload_speed=921600
|
||||||
|
|
||||||
build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
|
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY -DVERSION=${sysenv.DRONE_SEMVER}
|
||||||
lib_deps = https://github.com/homieiot/homie-esp8266.git#develop-v3, 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
|
||||||
|
41
src/main.cpp
41
src/main.cpp
@ -1,11 +1,14 @@
|
|||||||
#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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#define OUTPUT_SET(x) digitalWrite(CONFIG_IO_RELAY, x ? LOW : HIGH)
|
#define OUTPUT_SET(x) digitalWrite(CONFIG_IO_RELAY, x ? LOW : HIGH)
|
||||||
unsigned int timer = 0;
|
unsigned int timer = 0;
|
||||||
unsigned int next_timer_update = 0;
|
unsigned int next_timer_update = 0;
|
||||||
@ -14,19 +17,22 @@ HomieNode temperatureNode("temperature", "Temperature", "temperature");
|
|||||||
|
|
||||||
bool powerStateHandler(const HomieRange& range, const String& value)
|
bool powerStateHandler(const HomieRange& range, const String& value)
|
||||||
{
|
{
|
||||||
if (value != "on" && value != "off") return false;
|
if (value != "on" && value != "off")
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
powerNode.setProperty("state").send(value);
|
powerNode.setProperty("state").send(value);
|
||||||
powerNode.setProperty("timer").send("0");
|
powerNode.setProperty("timer").send("0");
|
||||||
timer = 0;
|
timer = 0;
|
||||||
|
|
||||||
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;
|
||||||
@ -42,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;
|
||||||
}
|
}
|
||||||
@ -50,6 +56,7 @@ bool powerTimerHandler(const HomieRange& range, const String& value)
|
|||||||
|
|
||||||
void setupHandler()
|
void setupHandler()
|
||||||
{
|
{
|
||||||
|
|
||||||
pinMode(CONFIG_IO_RELAY, OUTPUT);
|
pinMode(CONFIG_IO_RELAY, OUTPUT);
|
||||||
OUTPUT_SET(false);
|
OUTPUT_SET(false);
|
||||||
powerNode.setProperty("state").send("off");
|
powerNode.setProperty("state").send("off");
|
||||||
@ -58,7 +65,7 @@ void setupHandler()
|
|||||||
dht.setup(CONFIG_IO_DHT11, DHTesp::DHT11); // Connect DHT sensor to GPIO 17
|
dht.setup(CONFIG_IO_DHT11, DHTesp::DHT11); // Connect DHT sensor to GPIO 17
|
||||||
}
|
}
|
||||||
|
|
||||||
void loopHandler()
|
void loopHandleTimer()
|
||||||
{
|
{
|
||||||
if(timer)
|
if(timer)
|
||||||
{
|
{
|
||||||
@ -78,30 +85,42 @@ void loopHandler()
|
|||||||
powerNode.setProperty("timer").send(String(min_left));
|
powerNode.setProperty("timer").send(String(min_left));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loopHandleTemperature()
|
||||||
|
{
|
||||||
static unsigned long lastTemperatureSent = 0;
|
static unsigned long lastTemperatureSent = 0;
|
||||||
if (millis() - lastTemperatureSent >= CONFIG_TEMPERATURE_SEND_INTERVAL * 1000UL || lastTemperatureSent == 0)
|
if (millis() - lastTemperatureSent >= CONFIG_TEMPERATURE_SEND_INTERVAL * 1000UL || lastTemperatureSent == 0)
|
||||||
{
|
{
|
||||||
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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void loopHandler()
|
||||||
|
{
|
||||||
|
loopHandleTimer();
|
||||||
|
loopHandleTemperature();
|
||||||
|
}
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
Homie_setFirmware("deskcontrol", VERSION);
|
||||||
|
Homie.setLoggingPrinter(&Serial);
|
||||||
Serial.begin(CONFIG_SERIAL_BAUDRATE);
|
Serial.begin(CONFIG_SERIAL_BAUDRATE);
|
||||||
|
|
||||||
Homie_setFirmware("deskcontrol", "0.4.2");
|
|
||||||
|
|
||||||
Homie.disableResetTrigger();
|
Homie.disableResetTrigger();
|
||||||
|
|
||||||
|
//Power
|
||||||
powerNode.advertise("state").settable(powerStateHandler);
|
powerNode.advertise("state").settable(powerStateHandler);
|
||||||
powerNode.advertise("timer").settable(powerTimerHandler);
|
powerNode.advertise("timer").settable(powerTimerHandler);
|
||||||
|
|
||||||
|
//Temperature
|
||||||
temperatureNode.advertise("humidity");
|
temperatureNode.advertise("humidity");
|
||||||
temperatureNode.advertise("temperature");
|
temperatureNode.advertise("temperature");
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user