23 Commits

Author SHA1 Message Date
jct
cee415446a Branch name changed for homie
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2020-01-27 09:34:21 +00:00
jct
91a29db8ed Update '.drone.yml'
Some checks failed
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is failing
2019-11-29 10:08:21 +00:00
jct
7a37df2fff Merge branch 'refactoring' of jct/deskcontrol into master
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-11-29 09:59:32 +00:00
b5498b7173 Touchups
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2019-11-29 10:53:44 +01:00
0287456f1e Version numbers done via tags
All checks were successful
continuous-integration/drone/push Build is passing
2019-11-29 10:14:03 +01:00
019592f1ad Do not try to store vscode files in git
All checks were successful
continuous-integration/drone/push Build is passing
2019-11-28 10:19:30 +01:00
jct
c1c07a4003 Merge branch 'cleanup' of jct/deskcontrol into master
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-11-28 09:03:10 +00:00
True
cf380443a7 Temporary VS code files removed
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2019-11-28 09:56:43 +01:00
True
b8e68bed7c Streamlining configuration. Added static code analysis.
All checks were successful
continuous-integration/drone/push Build is passing
2019-11-28 09:50:54 +01:00
8387a0610b Updated version number
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-11-27 17:25:26 +01:00
jct
764b18e539 Moved temp sensor to seperate pin (#3)
Some checks reported errors
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build was killed
2019-11-27 09:19:23 +00:00
jct
e5a64c13ed Renamed drone secret
All checks were successful
continuous-integration/drone/push Build is passing
2019-10-25 08:09:41 +00:00
338c90fb8e Moved gitea key into drone secret
All checks were successful
continuous-integration/drone/push Build is passing
2019-10-08 15:35:21 +02:00
85c57daf91 Merge branch 'master' of https://code.jcktrue.dk/jct/deskcontrol
All checks were successful
continuous-integration/drone/push Build is passing
2019-10-08 14:24:23 +02:00
jct
5cb5300d15 Merge branch 'temp_sensor' of jct/deskcontrol into master
All checks were successful
continuous-integration/drone/push Build is passing
2019-09-22 17:52:02 +00:00
d5ffd87f90 Increased interval
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
2019-09-22 19:50:23 +02:00
0cff4d019a Added DHT11 sensoring
All checks were successful
continuous-integration/drone/push Build is passing
2019-09-22 16:34:06 +02:00
10b337d43f SPIFFS image
All checks were successful
continuous-integration/drone/push Build is passing
2019-09-22 13:15:47 +02:00
d19bd16561 Unneeded nodemcuv2 build
All checks were successful
continuous-integration/drone/push Build is passing
2019-09-22 13:11:21 +02:00
36ce6f976b Release version
All checks were successful
continuous-integration/drone/tag Build is passing
2019-09-03 15:47:04 +02:00
a4c2d49fb0 Sliming down and simplifying
All checks were successful
continuous-integration/drone/push Build is passing
2019-09-03 15:40:12 +02:00
bad20a7f58 Cleanup and removal of Syslog usage
All checks were successful
continuous-integration/drone/push Build is passing
2019-08-16 20:39:27 +02:00
jct
c00d2afb27 Merge branch 'homieV3' of jct/deskcontrol into master
All checks were successful
continuous-integration/drone/push Build is passing
2019-08-13 11:01:19 +00:00
6 changed files with 118 additions and 81 deletions

View File

@ -6,6 +6,7 @@ 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
@ -16,10 +17,17 @@ steps:
- name: release - name: release
image: plugins/gitea-release image: plugins/gitea-release
settings: settings:
api_key: a7f3afc9f77e721951e48b4af66d7565700b7a2e api_key:
from_secret: DRONE_ACCESS_TOKEN
base_url: https://code.jcktrue.dk base_url: https://code.jcktrue.dk
files: files:
- .pio/build/nodemcu/firmware.bin - .pio/build/nodemcu/firmware.bin
- .pio/build/nodemcu/firmware.elf checksum:
- md5
- sha1
- sha256
- sha512
- adler32
- crc32
when: when:
event: tag event: tag

1
.gitignore vendored
View File

@ -3,3 +3,4 @@
.pio .pio
data/homie/config.json data/homie/config.json
nbproject nbproject
.vscode

View 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
View 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

View File

@ -1,27 +1,12 @@
# [env]
# 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]
platform = espressif8266 platform = espressif8266
framework = arduino framework = arduino
board = nodemcu
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, Syslog lib_deps = https://github.com/homieiot/homie-esp8266.git#develop, DHT sensor library for ESPx
[env:nodemcu]
board = nodemcu

View File

@ -1,24 +1,33 @@
#include <Homie.h> #include "config.h"
#include <Syslog.h>
#include <WiFiUdp.h>
WiFiUDP udpClient;
Syslog syslog(udpClient, SYSLOG_PROTO_IETF);
const int PIN_RELAY = D1; #include <Homie.h>
#define OUTPUT_SET(x) digitalWrite(PIN_RELAY, x ? LOW : HIGH); #include "DHTesp.h"
DHTesp dht;
#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;
HomieNode powerNode("power", "Power", "switch"); HomieNode powerNode("power", "Power", "switch");
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; Homie.getLogger() << "Power is on" << endl;
} else { }
else
{
OUTPUT_SET(false); OUTPUT_SET(false);
Homie.getLogger() << "Power is off" << endl; Homie.getLogger() << "Power is off" << endl;
} }
@ -26,7 +35,8 @@ bool powerStateHandler(const HomieRange& range, const String& value) {
return true; return true;
} }
bool powerTimerHandler(const HomieRange& range, const String& value) { bool powerTimerHandler(const HomieRange& range, const String& value)
{
int settimer = value.toInt(); int settimer = value.toInt();
if(settimer == 0 || settimer > 120) if(settimer == 0 || settimer > 120)
return false; return false;
@ -41,80 +51,83 @@ bool powerTimerHandler(const HomieRange& range, const String& value) {
} }
void setupHandler() { void setupHandler()
pinMode(PIN_RELAY, OUTPUT); {
OUTPUT_SET(false);
powerNode.setProperty("state").send("off"); pinMode(CONFIG_IO_RELAY, OUTPUT);
powerNode.setProperty("timer").send("0"); 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)
{ {
if(timer < millis()) if(timer < millis())
{ { //Timer has expired. (Ignore the wraparound...)
timer = 0; timer = 0;
OUTPUT_SET(false); OUTPUT_SET(false);
powerNode.setProperty("timer").send("0"); powerNode.setProperty("timer").send("0");
powerNode.setProperty("state").send("off"); powerNode.setProperty("state").send("off");
} }
if(millis() > next_timer_update) {
if(next_timer_update && millis() > next_timer_update)
{
next_timer_update = millis() + 60*1000; next_timer_update = millis() + 60*1000;
unsigned int time_remaining = timer - millis(); unsigned int time_remaining = timer - millis();
unsigned int min_left = time_remaining / (60*1000); unsigned int min_left = time_remaining / (60*1000);
powerNode.setProperty("timer").send(String(min_left)); powerNode.setProperty("timer").send(String(min_left));
} }
} }
} }
void onHomieEvent(const HomieEvent& event) { void loopHandleTemperature()
switch(event.type) { {
case HomieEventType::OTA_FAILED: static unsigned long lastTemperatureSent = 0;
syslog.log(LOG_INFO, "OTA failed"); if (millis() - lastTemperatureSent >= CONFIG_TEMPERATURE_SEND_INTERVAL * 1000UL || lastTemperatureSent == 0)
// Do whatever you want when OTA is failed {
break; float humidity = dht.getHumidity();
case HomieEventType::OTA_SUCCESSFUL: float temperature = dht.getTemperature();
syslog.log(LOG_INFO, "OTA completed");
break; Homie.getLogger() << "Temperature: " << temperature << "°C " << humidity << "% Humidty" << endl;
case HomieEventType::WIFI_CONNECTED: temperatureNode.setProperty("temperature").send(String(temperature));
// Do whatever you want when Wi-Fi is connected in normal mode temperatureNode.setProperty("humidity").send(String(humidity));
syslog.deviceHostname(Homie.getConfiguration().name); lastTemperatureSent = millis();
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 setup() { void loopHandler()
syslog.server("192.168.1.100", 514); {
loopHandleTimer();
loopHandleTemperature();
}
Serial.begin(115200); void setup()
{
Serial.begin(CONFIG_SERIAL_BAUDRATE);
Serial << endl << endl; Homie_setFirmware("deskcontrol", VERSION);
Serial << "Firmware 0.0.1" << endl;
Serial << endl << endl;
Homie_setFirmware("deskcontrol", "1.0.0"); Homie.disableResetTrigger();
Homie_setBrand("FuryFire");
//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("temperature");
Homie.setSetupFunction(setupHandler); Homie.setSetupFunction(setupHandler);
Homie.onEvent(onHomieEvent); // before Homie.setup()
Homie.setLoopFunction(loopHandler); Homie.setLoopFunction(loopHandler);
Homie.setup(); Homie.setup();
} }
void loop() { void loop()
{
Homie.loop(); Homie.loop();
} }