Compare commits
11 Commits
b5498b7173
...
master
Author | SHA1 | Date | |
---|---|---|---|
0067a0b8a9 | |||
602ec3add6 | |||
be24ee7816 | |||
b927b1fdb9 | |||
d0f3845dc5 | |||
e9e0c17a8a | |||
2966170165 | |||
6be0baf301 | |||
cee415446a | |||
91a29db8ed | |||
7a37df2fff |
@ -6,7 +6,6 @@ steps:
|
||||
image: python:3
|
||||
commands:
|
||||
- pip install platformio
|
||||
- pio check
|
||||
- pio run
|
||||
- name: upload
|
||||
image: python:3
|
||||
@ -14,8 +13,6 @@ steps:
|
||||
- make otaupload
|
||||
when:
|
||||
event: tag
|
||||
branch:
|
||||
- master
|
||||
- name: release
|
||||
image: plugins/gitea-release
|
||||
settings:
|
||||
@ -33,5 +30,3 @@ steps:
|
||||
- crc32
|
||||
when:
|
||||
event: tag
|
||||
branch:
|
||||
- master
|
||||
|
4
.gitignore
vendored
4
.gitignore
vendored
@ -1,6 +1,4 @@
|
||||
.pioenvs
|
||||
.piolibdeps
|
||||
.pio
|
||||
data/homie/config.json
|
||||
nbproject
|
||||
.vscode
|
||||
output/doxygen
|
||||
|
3
Makefile
3
Makefile
@ -4,3 +4,6 @@ build:
|
||||
otaupload:
|
||||
pip install -r .pio/libdeps/nodemcu/Homie/scripts/ota_updater/requirements.txt
|
||||
python .pio/libdeps/nodemcu/Homie/scripts/ota_updater/ota_updater.py -l mqtt.jcktrue.dk -i 18fe34f2f987 .pio/build/nodemcu/firmware.bin
|
||||
|
||||
docs:
|
||||
doxygen .\.doxygen
|
||||
|
@ -1,15 +1,36 @@
|
||||
/**
|
||||
* \file
|
||||
* \class Config
|
||||
*/
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#ifndef VERSION
|
||||
//SEMVER style version
|
||||
/**
|
||||
* \brief Version string.
|
||||
* Update as needed. Formatted as SEMVER style string.
|
||||
* See https://semver.org/ for more information.
|
||||
*/
|
||||
#define VERSION "0.4.5-Dev"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Set the default Serial baudrate in bits/seconds
|
||||
*/
|
||||
#define CONFIG_SERIAL_BAUDRATE 115200
|
||||
|
||||
/**
|
||||
* Pin ID of the output relay
|
||||
*/
|
||||
#define CONFIG_IO_RELAY D1
|
||||
/**
|
||||
* Pin ID of the DHT11 temperature sensor
|
||||
*/
|
||||
#define CONFIG_IO_DHT11 D2
|
||||
|
||||
/**
|
||||
* Interval at which the tempreature is sent in seconds
|
||||
*/
|
||||
#define CONFIG_TEMPERATURE_SEND_INTERVAL 60
|
||||
#endif
|
0
output/FOR_GENERATED_FILES
Normal file
0
output/FOR_GENERATED_FILES
Normal file
@ -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-v3, 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
|
||||
|
73
src/main.cpp
73
src/main.cpp
@ -1,16 +1,38 @@
|
||||
/**
|
||||
* \brief Entry point
|
||||
*
|
||||
* Deskcontrol is a simple on/off timer switch inteded for use with an ATX PSU.
|
||||
* The theory of operation is turning on and off power by pulling the control line low/high while
|
||||
* running of the 5V standby line.
|
||||
*
|
||||
* Additional features include support for a DHT11 to log the temperature.
|
||||
* \file
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <Homie.h>
|
||||
|
||||
#include <LoggerNode.h>
|
||||
LoggerNode LN; ///<Instance of the LoggerNode library
|
||||
|
||||
#include "DHTesp.h"
|
||||
DHTesp dht;
|
||||
DHTesp dht; ///< Instance of the DHT temperature controller.
|
||||
|
||||
|
||||
#define OUTPUT_SET(x) digitalWrite(CONFIG_IO_RELAY, x ? LOW : HIGH)
|
||||
unsigned int timer = 0;
|
||||
unsigned int next_timer_update = 0;
|
||||
#define OUTPUT_SET(x) digitalWrite(CONFIG_IO_RELAY, x ? LOW : HIGH) ///< Macro for controlling the output state.
|
||||
unsigned int timer = 0; ///< Remaining time when counting down.
|
||||
unsigned int next_timer_update = 0; ///< Timer used to control when the timer value should be pushed to the server
|
||||
|
||||
HomieNode powerNode("power", "Power", "switch");
|
||||
HomieNode temperatureNode("temperature", "Temperature", "temperature");
|
||||
|
||||
/** Power state handler
|
||||
* Handles event on the power state MQTT node
|
||||
* \param[in] range Currently unused
|
||||
* \param[in] value New value of the power state. (Either "on" or off")
|
||||
* \return False if input is invalid. Otherwise true.
|
||||
*/
|
||||
bool powerStateHandler(const HomieRange& range, const String& value)
|
||||
{
|
||||
if (value != "on" && value != "off")
|
||||
@ -24,17 +46,23 @@ 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief powerTimer event handler.
|
||||
* Handler for events on the powerTimer node.
|
||||
* \param[in] range Currently unused.
|
||||
* \param[in] value New value for the timer in minutes. ASCII representation of an integer from 1 to 120.
|
||||
* \return False if input is invalid. Otherwise true.
|
||||
*/
|
||||
bool powerTimerHandler(const HomieRange& range, const String& value)
|
||||
{
|
||||
int settimer = value.toInt();
|
||||
@ -45,15 +73,16 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* setupHandler. Comply with Homie interface
|
||||
*/
|
||||
void setupHandler()
|
||||
{
|
||||
|
||||
pinMode(CONFIG_IO_RELAY, OUTPUT);
|
||||
OUTPUT_SET(false);
|
||||
powerNode.setProperty("state").send("off");
|
||||
@ -62,6 +91,9 @@ void setupHandler()
|
||||
dht.setup(CONFIG_IO_DHT11, DHTesp::DHT11); // Connect DHT sensor to GPIO 17
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle timer updates from the main event loop
|
||||
*/
|
||||
void loopHandleTimer()
|
||||
{
|
||||
if(timer)
|
||||
@ -84,6 +116,9 @@ void loopHandleTimer()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle periodic temperature measurements from the main event loop
|
||||
*/
|
||||
void loopHandleTemperature()
|
||||
{
|
||||
static unsigned long lastTemperatureSent = 0;
|
||||
@ -91,25 +126,34 @@ 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();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Main event loop. Part of the Homie API. This runs while the device is active and connected.
|
||||
*
|
||||
* \callgraph
|
||||
*/
|
||||
void loopHandler()
|
||||
{
|
||||
loopHandleTimer();
|
||||
loopHandleTemperature();
|
||||
}
|
||||
|
||||
/**
|
||||
* Arduino style setup() routine.
|
||||
* Configure the Homie framework by adding the two nodes "power" and "temperature"
|
||||
*/
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(CONFIG_SERIAL_BAUDRATE);
|
||||
|
||||
Homie_setFirmware("deskcontrol", VERSION);
|
||||
Homie.setLoggingPrinter(&Serial);
|
||||
Serial.begin(CONFIG_SERIAL_BAUDRATE);
|
||||
|
||||
Homie.disableResetTrigger();
|
||||
|
||||
@ -127,6 +171,9 @@ void setup()
|
||||
Homie.setup();
|
||||
}
|
||||
|
||||
/**
|
||||
* Arduino main loop. Forwarded to Homie framework
|
||||
*/
|
||||
void loop()
|
||||
{
|
||||
Homie.loop();
|
||||
|
Reference in New Issue
Block a user