aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKarel Kočí <cynerd@email.cz>2018-11-10 23:36:11 +0100
committerKarel Kočí <cynerd@email.cz>2018-11-12 19:34:52 +0100
commitbbcb8d635f4c83a0a7f27bd6d3e554781780d27e (patch)
treec7340360e0518360b51e8848281348ecc5758583
parentcf452f0c431ba73719e0f3a356c78a43f74bf5ac (diff)
downloadbigclown-leds-bbcb8d635f4c83a0a7f27bd6d3e554781780d27e.tar.gz
bigclown-leds-bbcb8d635f4c83a0a7f27bd6d3e554781780d27e.tar.bz2
bigclown-leds-bbcb8d635f4c83a0a7f27bd6d3e554781780d27e.zip
Add ability to mirror messages from thermostat to power-controller
-rwxr-xr-xbigclown-leds28
-rwxr-xr-xbigclown-leds.init21
-rw-r--r--control/application.c11
3 files changed, 57 insertions, 3 deletions
diff --git a/bigclown-leds b/bigclown-leds
new file mode 100755
index 0000000..2871d52
--- /dev/null
+++ b/bigclown-leds
@@ -0,0 +1,28 @@
+#!/usr/bin/env python3
+import paho.mqtt.client as mqtt
+
+
+def on_connect(client, userdata, rc):
+ print("Connected with result code "+str(rc))
+ client.subscribe("node/lcd-thermostat:0/led/#")
+
+
+# The callback for when a PUBLISH message is received from the server.
+def on_message(client, userdata, msg):
+ topic = msg.topic[26:]
+ client.publish(
+ 'node/power-controller:0/led-strip/-/' + topic,
+ payload=msg.payload)
+
+
+def main():
+ client = mqtt.Client()
+ client.on_connect = on_connect
+ client.on_message = on_message
+
+ client.connect("127.0.0.1", 1883, 60)
+ client.loop_forever()
+
+
+if __name__ == '__main__':
+ main()
diff --git a/bigclown-leds.init b/bigclown-leds.init
new file mode 100755
index 0000000..fa56a36
--- /dev/null
+++ b/bigclown-leds.init
@@ -0,0 +1,21 @@
+#!/bin/sh /etc/rc.common
+
+START=99
+STOP=1
+
+USE_PROCD=1
+
+PROG=/usr/bin/bigclown-leds
+
+start_service() {
+ procd_open_instance
+ procd_set_param respawn ${respawn_threshold:-3600} ${respawn_timeout:-5} ${respawn_retry:-5}
+ procd_set_param command "$PROG"
+ procd_set_param stdout 1
+ procd_set_param stderr 1
+ procd_close_instance
+}
+
+stop_service() {
+ service_stop "$PROG"
+}
diff --git a/control/application.c b/control/application.c
index c14f5b1..ce14bf2 100644
--- a/control/application.c
+++ b/control/application.c
@@ -51,21 +51,26 @@ void tmp112_event_handler(bc_tmp112_t *self, bc_tmp112_event_t event, void *even
bc_scheduler_plan_now(APPLICATION_TASK_ID);
}
-void on_lcd_button_click(void) {
+int brightness = 0;
+
+void set_brightness() {
+ bc_radio_pub_int("led/brightness/set", &brightness);
}
void lcd_button_left_event_handler(bc_button_t *self, bc_button_event_t event, void *event_param) {
if (event != BC_BUTTON_EVENT_CLICK)
return;
bc_led_pulse(&led_lcd_blue, 30);
- on_lcd_button_click();
+ brightness = 100;
+ set_brightness();
}
void lcd_button_right_event_handler(bc_button_t *self, bc_button_event_t event, void *event_param) {
if (event != BC_BUTTON_EVENT_CLICK)
return;
bc_led_pulse(&led_lcd_red, 30);
- on_lcd_button_click();
+ brightness = 0;
+ set_brightness();
}
void battery_event_handler(bc_module_battery_event_t event, void *event_param) {