9 Commits

Author SHA1 Message Date
Jens Christian True
847dda81be Update to Homie V3
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2019-08-13 11:56:59 +02:00
Jens Christian True
dc91211889 Prototype of timer implementation
All checks were successful
continuous-integration/drone/push Build is passing
2019-07-19 09:04:14 +02:00
58bcd731fc Compile error
All checks were successful
continuous-integration/drone/push Build is passing
2019-07-16 13:22:46 +02:00
6efa5bd0b8 Compile error
Some checks failed
continuous-integration/drone/push Build is failing
2019-07-16 13:19:51 +02:00
2a3bbc3628 Empty timer handler. Cleaned up code
Some checks failed
continuous-integration/drone/push Build is failing
2019-07-16 12:56:05 +02:00
Jens Christian True
e322b5ddcd Feature fork
Some checks reported errors
continuous-integration/drone/push Build was killed
2019-07-15 15:19:15 +02:00
795043a639 Only upload on new release
All checks were successful
continuous-integration/drone/tag Build is passing
continuous-integration/drone/push Build is passing
2019-07-11 09:22:33 +02:00
b0a485d578 Fixed release upload
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/tag Build is failing
2019-07-11 09:15:13 +02:00
3d4399c33d Updated to PIOv4
Some checks failed
continuous-integration/drone/push Build is failing
2019-07-11 09:12:45 +02:00
5 changed files with 68 additions and 62 deletions

View File

@ -11,13 +11,15 @@ steps:
image: python:3 image: python:3
commands: commands:
- make otaupload - make otaupload
when:
event: tag
- name: release - name: release
image: plugins/gitea-release image: plugins/gitea-release
settings: settings:
api_key: a7f3afc9f77e721951e48b4af66d7565700b7a2e api_key: a7f3afc9f77e721951e48b4af66d7565700b7a2e
base_url: https://code.jcktrue.dk base_url: https://code.jcktrue.dk
files: files:
- .pioenvs/nodemcu/firmware.bin - .pio/build/nodemcu/firmware.bin
- .pioenvs/nodemcu/firmware.elf - .pio/build/nodemcu/firmware.elf
when: when:
event: tag event: tag

1
.gitignore vendored
View File

@ -1,4 +1,5 @@
.pioenvs .pioenvs
.piolibdeps .piolibdeps
.pio
data/homie/config.json data/homie/config.json
nbproject nbproject

View File

@ -2,5 +2,5 @@ build:
pio run pio run
otaupload: otaupload:
pip install -r .pio/libdeps/Homie/scripts/ota_updater/requirements.txt pip install -r .pio/libdeps/nodemcu/Homie/scripts/ota_updater/requirements.txt
python .pio/libdeps/Homie/scripts/ota_updater/ota_updater.py -l mqtt.jcktrue.dk -i 18fe34f2f987 .pio/build/nodemcu/firmware.bin python .pio/libdeps/nodemcu/Homie/scripts/ota_updater/ota_updater.py -l mqtt.jcktrue.dk -i 18fe34f2f987 .pio/build/nodemcu/firmware.bin

View File

@ -24,4 +24,4 @@ board = nodemcu
upload_speed=921600 upload_speed=921600
build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
lib_deps = https://github.com/homieiot/homie-esp8266.git#develop, Syslog lib_deps = https://github.com/homieiot/homie-esp8266.git#develop-v3, Syslog

View File

@ -5,55 +5,76 @@ WiFiUDP udpClient;
Syslog syslog(udpClient, SYSLOG_PROTO_IETF); Syslog syslog(udpClient, SYSLOG_PROTO_IETF);
const int PIN_RELAY = D1; const int PIN_RELAY = D1;
int timer = 0; #define OUTPUT_SET(x) digitalWrite(PIN_RELAY, x ? LOW : HIGH);
HomieNode powerNode("power", "switch"); unsigned int timer = 0;
unsigned int next_timer_update = 0;
HomieNode powerNode("power", "Power", "switch");
bool powerOnHandler(const HomieRange& range, const String& value) {
if (value != "true" && value != "false") return false;
bool on = (value == "true");
digitalWrite(PIN_RELAY, on ? LOW : HIGH);
powerNode.setProperty("on").send(value);
Homie.getLogger() << "Power is " << (on ? "on" : "off") << endl;
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") {
OUTPUT_SET(true);
Homie.getLogger() << "Power is on" << endl;
} else {
OUTPUT_SET(false);
Homie.getLogger() << "Power is off" << endl;
}
return true; return true;
} }
bool powerTimerHandler(const HomieRange& range, const String& value) {
int settimer = value.toInt();
if(settimer == 0 || settimer > 120)
return false;
timer = millis() + (settimer * 1000 * 60);
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;
OUTPUT_SET(true);
return true;
}
void setupHandler() { void setupHandler() {
pinMode(PIN_RELAY, OUTPUT); pinMode(PIN_RELAY, OUTPUT);
digitalWrite(PIN_RELAY, HIGH); OUTPUT_SET(false);
powerNode.setProperty("state").send("off");
powerNode.setProperty("timer").send("0");
}
powerNode.setProperty("on").send("false"); void loopHandler() {
if(timer)
{
if(timer < millis())
{
timer = 0;
OUTPUT_SET(false);
powerNode.setProperty("timer").send("0");
}
if(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) { void onHomieEvent(const HomieEvent& event) {
switch(event.type) { switch(event.type) {
case HomieEventType::STANDALONE_MODE:
// Do whatever you want when standalone mode is started
break;
case HomieEventType::CONFIGURATION_MODE:
// Do whatever you want when configuration mode is started
break;
case HomieEventType::NORMAL_MODE:
// Do whatever you want when normal mode is started
break;
case HomieEventType::OTA_STARTED:
// Do whatever you want when OTA is started
break;
case HomieEventType::OTA_PROGRESS:
// Do whatever you want when OTA is in progress
// You can use event.sizeDone and event.sizeTotal
break;
case HomieEventType::OTA_FAILED: case HomieEventType::OTA_FAILED:
syslog.log(LOG_INFO, "OTA failed");
// Do whatever you want when OTA is failed // Do whatever you want when OTA is failed
break; break;
case HomieEventType::OTA_SUCCESSFUL: case HomieEventType::OTA_SUCCESSFUL:
// Do whatever you want when OTA is successful syslog.log(LOG_INFO, "OTA completed");
break;
case HomieEventType::ABOUT_TO_RESET:
// Do whatever you want when the device is about to reset
break; break;
case HomieEventType::WIFI_CONNECTED: case HomieEventType::WIFI_CONNECTED:
// Do whatever you want when Wi-Fi is connected in normal mode // Do whatever you want when Wi-Fi is connected in normal mode
@ -61,39 +82,20 @@ void onHomieEvent(const HomieEvent& event) {
syslog.appName("deskcontrol"); syslog.appName("deskcontrol");
syslog.defaultPriority(LOG_ERR); syslog.defaultPriority(LOG_ERR);
syslog.log(LOG_INFO, "WiFi Connected, software version: 1.0"); syslog.log(LOG_INFO, "WiFi Connected, software version: 1.0");
// You can use event.ip, event.gateway, event.mask
break;
case HomieEventType::WIFI_DISCONNECTED:
// Do whatever you want when Wi-Fi is disconnected in normal mode
// You can use event.wifiReason
break; break;
case HomieEventType::MQTT_READY: case HomieEventType::MQTT_READY:
// Do whatever you want when MQTT is connected in normal mode
syslog.log(LOG_INFO, "MQTT connected"); syslog.log(LOG_INFO, "MQTT connected");
break; break;
case HomieEventType::MQTT_DISCONNECTED: case HomieEventType::MQTT_DISCONNECTED:
// Do whatever you want when MQTT is disconnected in normal mode
syslog.log(LOG_INFO, "MQTT disconnected"); syslog.log(LOG_INFO, "MQTT disconnected");
// You can use event.mqttReason
break; break;
case HomieEventType::MQTT_PACKET_ACKNOWLEDGED: default:
// Do whatever you want when an MQTT packet with QoS > 0 is acknowledged by the broker
// You can use event.packetId
break;
case HomieEventType::READY_TO_SLEEP:
// After you've called `prepareToSleep()`, the event is triggered when MQTT is disconnected
break;
case HomieEventType::SENDING_STATISTICS:
// Do whatever you want when statistics are sent in normal mode
break; break;
} }
} }
void setup() { void setup() {
syslog.server("192.168.1.100", 514); syslog.server("192.168.1.100", 514);
Serial.begin(115200); Serial.begin(115200);
@ -104,10 +106,11 @@ void setup() {
Homie_setFirmware("deskcontrol", "1.0.0"); Homie_setFirmware("deskcontrol", "1.0.0");
Homie_setBrand("FuryFire"); Homie_setBrand("FuryFire");
powerNode.advertise("on").settable(powerOnHandler); powerNode.advertise("state").settable(powerStateHandler);
powerNode.advertise("timer").settable(powerTimerHandler);
Homie.setSetupFunction(setupHandler); Homie.setSetupFunction(setupHandler);
Homie.onEvent(onHomieEvent); // before Homie.setup() Homie.onEvent(onHomieEvent); // before Homie.setup()
Homie.setLoopFunction(loopHandler);
Homie.setup(); Homie.setup();
} }