From bbcb8d635f4c83a0a7f27bd6d3e554781780d27e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Sat, 10 Nov 2018 23:36:11 +0100 Subject: Add ability to mirror messages from thermostat to power-controller --- bigclown-leds | 28 ++++++++++++++++++++++++++++ bigclown-leds.init | 21 +++++++++++++++++++++ control/application.c | 11 ++++++++--- 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100755 bigclown-leds create mode 100755 bigclown-leds.init 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) { -- cgit v1.2.3