Compare commits
22 Commits
c00d2afb27
...
v0.4.6
Author | SHA1 | Date | |
---|---|---|---|
cee415446a | |||
91a29db8ed | |||
7a37df2fff | |||
b5498b7173 | |||
0287456f1e | |||
019592f1ad | |||
c1c07a4003 | |||
|
cf380443a7 | ||
|
b8e68bed7c | ||
8387a0610b | |||
764b18e539 | |||
e5a64c13ed | |||
338c90fb8e | |||
85c57daf91 | |||
5cb5300d15 | |||
d5ffd87f90 | |||
0cff4d019a | |||
10b337d43f | |||
d19bd16561 | |||
36ce6f976b | |||
a4c2d49fb0 | |||
bad20a7f58 |
12
.drone.yml
12
.drone.yml
@ -6,6 +6,7 @@ steps:
|
||||
image: python:3
|
||||
commands:
|
||||
- pip install platformio
|
||||
- pio check
|
||||
- pio run
|
||||
- name: upload
|
||||
image: python:3
|
||||
@ -16,10 +17,17 @@ steps:
|
||||
- name: release
|
||||
image: plugins/gitea-release
|
||||
settings:
|
||||
api_key: a7f3afc9f77e721951e48b4af66d7565700b7a2e
|
||||
api_key:
|
||||
from_secret: DRONE_ACCESS_TOKEN
|
||||
base_url: https://code.jcktrue.dk
|
||||
files:
|
||||
- .pio/build/nodemcu/firmware.bin
|
||||
- .pio/build/nodemcu/firmware.elf
|
||||
checksum:
|
||||
- md5
|
||||
- sha1
|
||||
- sha256
|
||||
- sha512
|
||||
- adler32
|
||||
- crc32
|
||||
when:
|
||||
event: tag
|
||||
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -3,3 +3,4 @@
|
||||
.pio
|
||||
data/homie/config.json
|
||||
nbproject
|
||||
.vscode
|
||||
|
15
data/homie/config.example.json
Normal file
15
data/homie/config.example.json
Normal file
@ -0,0 +1,15 @@
|
||||
{
|
||||
"name": "deskcontrol",
|
||||
"wifi": {
|
||||
"ssid": "<SSID>",
|
||||
"password": "<PASS>"
|
||||
},
|
||||
"mqtt": {
|
||||
"host": "<Domain>",
|
||||
"port": 1883,
|
||||
"auth": false
|
||||
},
|
||||
"ota": {
|
||||
"enabled": true
|
||||
}
|
||||
}
|
15
include/config.h
Normal file
15
include/config.h
Normal file
@ -0,0 +1,15 @@
|
||||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#ifndef VERSION
|
||||
//SEMVER style version
|
||||
#define VERSION "0.4.5-Dev"
|
||||
#endif
|
||||
|
||||
#define CONFIG_SERIAL_BAUDRATE 115200
|
||||
|
||||
#define CONFIG_IO_RELAY D1
|
||||
#define CONFIG_IO_DHT11 D2
|
||||
|
||||
#define CONFIG_TEMPERATURE_SEND_INTERVAL 60
|
||||
#endif
|
@ -1,27 +1,12 @@
|
||||
#
|
||||
# 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:nodemcu]
|
||||
[env]
|
||||
platform = espressif8266
|
||||
framework = arduino
|
||||
board = nodemcu
|
||||
|
||||
upload_speed=921600
|
||||
|
||||
build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
|
||||
lib_deps = https://github.com/homieiot/homie-esp8266.git#develop-v3, Syslog
|
||||
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
|
||||
|
||||
[env:nodemcu]
|
||||
board = nodemcu
|
||||
|
||||
|
117
src/main.cpp
117
src/main.cpp
@ -1,24 +1,33 @@
|
||||
#include <Homie.h>
|
||||
#include <Syslog.h>
|
||||
#include <WiFiUdp.h>
|
||||
WiFiUDP udpClient;
|
||||
Syslog syslog(udpClient, SYSLOG_PROTO_IETF);
|
||||
#include "config.h"
|
||||
|
||||
const int PIN_RELAY = D1;
|
||||
#define OUTPUT_SET(x) digitalWrite(PIN_RELAY, x ? LOW : HIGH);
|
||||
#include <Homie.h>
|
||||
#include "DHTesp.h"
|
||||
DHTesp dht;
|
||||
|
||||
|
||||
#define OUTPUT_SET(x) digitalWrite(CONFIG_IO_RELAY, x ? LOW : HIGH)
|
||||
unsigned int timer = 0;
|
||||
unsigned int next_timer_update = 0;
|
||||
HomieNode powerNode("power", "Power", "switch");
|
||||
HomieNode temperatureNode("temperature", "Temperature", "temperature");
|
||||
|
||||
bool powerStateHandler(const HomieRange& range, const String& value) {
|
||||
if (value != "on" && value != "off") return false;
|
||||
bool powerStateHandler(const HomieRange& range, const String& value)
|
||||
{
|
||||
if (value != "on" && value != "off")
|
||||
{
|
||||
return false;
|
||||
}
|
||||
powerNode.setProperty("state").send(value);
|
||||
powerNode.setProperty("timer").send("0");
|
||||
timer = 0;
|
||||
if(value == "on") {
|
||||
|
||||
if(value == "on")
|
||||
{
|
||||
OUTPUT_SET(true);
|
||||
Homie.getLogger() << "Power is on" << endl;
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
OUTPUT_SET(false);
|
||||
Homie.getLogger() << "Power is off" << endl;
|
||||
}
|
||||
@ -26,7 +35,8 @@ bool powerStateHandler(const HomieRange& range, const String& value) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool powerTimerHandler(const HomieRange& range, const String& value) {
|
||||
bool powerTimerHandler(const HomieRange& range, const String& value)
|
||||
{
|
||||
int settimer = value.toInt();
|
||||
if(settimer == 0 || settimer > 120)
|
||||
return false;
|
||||
@ -41,80 +51,83 @@ bool powerTimerHandler(const HomieRange& range, const String& value) {
|
||||
}
|
||||
|
||||
|
||||
void setupHandler() {
|
||||
pinMode(PIN_RELAY, OUTPUT);
|
||||
void setupHandler()
|
||||
{
|
||||
|
||||
pinMode(CONFIG_IO_RELAY, OUTPUT);
|
||||
OUTPUT_SET(false);
|
||||
powerNode.setProperty("state").send("off");
|
||||
powerNode.setProperty("timer").send("0");
|
||||
|
||||
dht.setup(CONFIG_IO_DHT11, DHTesp::DHT11); // Connect DHT sensor to GPIO 17
|
||||
}
|
||||
|
||||
void loopHandler() {
|
||||
void loopHandleTimer()
|
||||
{
|
||||
if(timer)
|
||||
{
|
||||
if(timer < millis())
|
||||
{
|
||||
{ //Timer has expired. (Ignore the wraparound...)
|
||||
timer = 0;
|
||||
OUTPUT_SET(false);
|
||||
powerNode.setProperty("timer").send("0");
|
||||
powerNode.setProperty("state").send("off");
|
||||
}
|
||||
if(millis() > next_timer_update) {
|
||||
|
||||
if(next_timer_update && millis() > next_timer_update)
|
||||
{
|
||||
next_timer_update = millis() + 60*1000;
|
||||
unsigned int time_remaining = timer - millis();
|
||||
unsigned int min_left = time_remaining / (60*1000);
|
||||
powerNode.setProperty("timer").send(String(min_left));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void onHomieEvent(const HomieEvent& event) {
|
||||
switch(event.type) {
|
||||
case HomieEventType::OTA_FAILED:
|
||||
syslog.log(LOG_INFO, "OTA failed");
|
||||
// Do whatever you want when OTA is failed
|
||||
break;
|
||||
case HomieEventType::OTA_SUCCESSFUL:
|
||||
syslog.log(LOG_INFO, "OTA completed");
|
||||
break;
|
||||
case HomieEventType::WIFI_CONNECTED:
|
||||
// Do whatever you want when Wi-Fi is connected in normal mode
|
||||
syslog.deviceHostname(Homie.getConfiguration().name);
|
||||
syslog.appName("deskcontrol");
|
||||
syslog.defaultPriority(LOG_ERR);
|
||||
syslog.log(LOG_INFO, "WiFi Connected, software version: 1.0");
|
||||
break;
|
||||
case HomieEventType::MQTT_READY:
|
||||
syslog.log(LOG_INFO, "MQTT connected");
|
||||
break;
|
||||
case HomieEventType::MQTT_DISCONNECTED:
|
||||
syslog.log(LOG_INFO, "MQTT disconnected");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
void loopHandleTemperature()
|
||||
{
|
||||
static unsigned long lastTemperatureSent = 0;
|
||||
if (millis() - lastTemperatureSent >= CONFIG_TEMPERATURE_SEND_INTERVAL * 1000UL || lastTemperatureSent == 0)
|
||||
{
|
||||
float humidity = dht.getHumidity();
|
||||
float temperature = dht.getTemperature();
|
||||
|
||||
Homie.getLogger() << "Temperature: " << temperature << "°C " << humidity << "% Humidty" << endl;
|
||||
temperatureNode.setProperty("temperature").send(String(temperature));
|
||||
temperatureNode.setProperty("humidity").send(String(humidity));
|
||||
lastTemperatureSent = millis();
|
||||
}
|
||||
}
|
||||
|
||||
void setup() {
|
||||
syslog.server("192.168.1.100", 514);
|
||||
void loopHandler()
|
||||
{
|
||||
loopHandleTimer();
|
||||
loopHandleTemperature();
|
||||
}
|
||||
|
||||
Serial.begin(115200);
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(CONFIG_SERIAL_BAUDRATE);
|
||||
|
||||
Serial << endl << endl;
|
||||
Serial << "Firmware 0.0.1" << endl;
|
||||
Serial << endl << endl;
|
||||
Homie_setFirmware("deskcontrol", VERSION);
|
||||
|
||||
Homie_setFirmware("deskcontrol", "1.0.0");
|
||||
Homie_setBrand("FuryFire");
|
||||
Homie.disableResetTrigger();
|
||||
|
||||
//Power
|
||||
powerNode.advertise("state").settable(powerStateHandler);
|
||||
powerNode.advertise("timer").settable(powerTimerHandler);
|
||||
|
||||
//Temperature
|
||||
temperatureNode.advertise("humidity");
|
||||
temperatureNode.advertise("temperature");
|
||||
|
||||
Homie.setSetupFunction(setupHandler);
|
||||
Homie.onEvent(onHomieEvent); // before Homie.setup()
|
||||
Homie.setLoopFunction(loopHandler);
|
||||
|
||||
Homie.setup();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
void loop()
|
||||
{
|
||||
Homie.loop();
|
||||
}
|
||||
|
Reference in New Issue
Block a user