From 85197adaf7c1c7a993fee6b237f9d4d3d8b95104 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 1 Jan 2022 19:50:52 +0100 Subject: [PATCH] Updated to new MQTT server and fixed a couple of bugs --- aircon/daemon/Makefile | 33 ++++++++++++----------- aircon/daemon/burrow-aircond.c | 4 ++- auto/burrow-auto | 2 +- bsb/daemon/Makefile | 48 ++++++++++++++-------------------- power/daemon/Makefile | 33 ++++++++++++----------- power/daemon/burrow-powerd.c | 6 +++-- ssr/host/Makefile | 33 +++++++++++------------ ssr/host/ssr-control.c | 3 +-- 8 files changed, 75 insertions(+), 87 deletions(-) diff --git a/aircon/daemon/Makefile b/aircon/daemon/Makefile index b7651ad..2cf8c02 100644 --- a/aircon/daemon/Makefile +++ b/aircon/daemon/Makefile @@ -1,23 +1,22 @@ -TOPDIR=/root/turris - -include $(TOPDIR)/rules.mk -include $(TOPDIR)/include/package.mk - -PC := PATH=$(STAGING_DIR_HOST)/bin:$(PATH) PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) PKG_CONFIG_LIBDIR=$(PKG_CONFIG_PATH) STAGING_PREFIX=$(STAGING_DIR)/usr $(PKG_CONFIG) -MB_CFLAGS := $(shell $(PC) --cflags libmodbus) -MB_LDFLAGS := $(shell $(PC) --libs libmodbus) +PC=pkg-config UCW_CFLAGS := $(shell $(PC) --cflags libucw) -UCW_LDFLAGS := $(shell $(PC) --libs libucw) +UCW_LIBS := $(shell $(PC) --libs libucw) +MODBUS_CFLAGS := $(shell $(PC) --cflags libmodbus) +MODBUS_LIBS := $(shell $(PC) --libs libmodbus) +MOSQUITTO_CFLAGS := $(shell $(PC) --cflags libmosquitto) +MOSQUITTO_LIBS := $(shell $(PC) --libs libmosquitto) -export PATH=$(TARGET_PATH_PKG) -CC=$(TARGET_CC_NOCACHE) -LD=$(TARGET_LD_NOCACHE) -CFLAGS=$(TARGET_CFLAGS) $(MB_CFLAGS) $(UCW_CFLAGS) -std=gnu99 -LDFLAGS=$(TARGET_LDFLAGS) $(MB_LDFLAGS) $(UCW_LDFLAGS) -lmosquitto +CFLAGS=-O2 -Wall -Wextra -Wno-sign-compare -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes $(UCW_CFLAGS) $(MODBUS_CFLAGS) $(MOSQUITTO_CFLAGS) +LDLIBS=$(UCW_LIBS) $(MODBUS_LIBS) $(MOSQUITTO_LIBS) -all: burrow-aircond upload +all: burrow-aircond burrow-aircond: burrow-aircond.c -upload: - rsync -av burrow-aircond micac:/root/burrow/ +install: burrow-aircond + install burrow-aircond /usr/local/sbin/ + +clean: + rm -f *.o burrow-aircond + +.PHONY: all install clean diff --git a/aircon/daemon/burrow-aircond.c b/aircon/daemon/burrow-aircond.c index d33ba6c..7db3864 100644 --- a/aircon/daemon/burrow-aircond.c +++ b/aircon/daemon/burrow-aircond.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -57,7 +58,7 @@ static void mqtt_publish(const char *topic, const char *fmt, ...) va_end(args); } -static void mqtt_log_callback(struct mosquitto *mosq UNUSED, void *obj UNUSED, int level, const char *message) +static void mqtt_log_callback(struct mosquitto *mosq UNUSED, void *obj UNUSED, int level UNUSED, const char *message UNUSED) { // msg(L_INFO, "MQTT(%d): %s", level, message); } @@ -149,6 +150,7 @@ static bool mb_connect(void) } mb_is_open = true; + return true; } /*** Main loop ***/ diff --git a/auto/burrow-auto b/auto/burrow-auto index 2adea5a..4770718 100755 --- a/auto/burrow-auto +++ b/auto/burrow-auto @@ -214,7 +214,7 @@ mq = mqtt.Client() mq.on_connect = on_connect mq.on_message = on_message mq.will_set("status/auto", "dead", retain=True) -mq.connect("127.0.0.1") +mq.connect("burrow-mqtt") mq.publish("status/auto", "ok", retain=True) mq.loop_start() diff --git a/bsb/daemon/Makefile b/bsb/daemon/Makefile index b602b51..1aeefbf 100644 --- a/bsb/daemon/Makefile +++ b/bsb/daemon/Makefile @@ -1,36 +1,26 @@ -BUILD_FOR_TURRIS=1 - -ifdef BUILD_FOR_TURRIS - -TOPDIR=/root/turris - -include $(TOPDIR)/rules.mk -include $(TOPDIR)/include/package.mk - -PC := PATH=$(STAGING_DIR_HOST)/bin:$(PATH) PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) PKG_CONFIG_LIBDIR=$(PKG_CONFIG_PATH) STAGING_PREFIX=$(STAGING_DIR)/usr $(PKG_CONFIG) - -export PATH=$(TARGET_PATH_PKG) -CC=$(TARGET_CC_NOCACHE) -LD=$(TARGET_LD_NOCACHE) - -else +PC=pkg-config +UCW_CFLAGS := $(shell $(PC) --cflags libucw) +UCW_LIBS := $(shell $(PC) --libs libucw) +USB_CFLAGS := $(shell $(PC) --cflags libusb-1.0) +USB_LIBS := $(shell $(PC) --libs libusb-1.0) +MOSQUITTO_CFLAGS := $(shell $(PC) --cflags libmosquitto) +MOSQUITTO_LIBS := $(shell $(PC) --libs libmosquitto) -PC := PKG_CONFIG_PATH=/home/mj/tmp/bsb/root/lib/pkgconfig pkg-config +CFLAGS=-O2 -Wall -Wextra -Wno-sign-compare -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes $(UCW_CFLAGS) $(USB_CFLAGS) $(MOSQUITTO_CFLAGS) +LDLIBS=$(UCW_LIBS) $(USB_LIBS) $(MOSQUITTO_LIBS) -endif +all: burrow-bsbd bsb-monitor -USB_CFLAGS := $(shell $(PC) --cflags libusb-1.0) -USB_LDFLAGS := $(shell $(PC) --libs libusb-1.0) -UCW_CFLAGS := $(shell $(PC) --cflags libucw) -UCW_LDFLAGS := $(shell $(PC) --libs libucw) +burrow-bsbd: burrow-bsbd.o +bsb-monitor: bsb-monitor.o -CFLAGS=$(USB_CFLAGS) $(UCW_CFLAGS) -std=gnu1x -O2 -Wall -Wextra -Wno-parentheses -LDFLAGS=$(USB_LDFLAGS) $(UCW_LDFLAGS) -lmosquitto +burrow-bsbd.o: burrow-bsbd.c ../firmware/interface.h +bsb-monitor.o: bsb-monitor.c ../firmware/interface.h -all: burrow-bsbd bsb-monitor +install: burrow-bsbd + install burrow-bsbd /usr/local/sbin/ -# burrow-bsbd: burrow-bsbd.c ../firmware/interface.h -# bsb-monitor: bsb-monitor.c ../firmware/interface.h +clean: + rm -f *.o burrow-bsbd bsb-monitor -upload: - rsync -av burrow-bsbd bsb-monitor micac:/root/burrow/ +.PHONY: all install clean diff --git a/power/daemon/Makefile b/power/daemon/Makefile index b779cc9..caa0e16 100644 --- a/power/daemon/Makefile +++ b/power/daemon/Makefile @@ -1,23 +1,22 @@ -TOPDIR=/root/turris - -include $(TOPDIR)/rules.mk -include $(TOPDIR)/include/package.mk - -PC := PATH=$(STAGING_DIR_HOST)/bin:$(PATH) PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) PKG_CONFIG_LIBDIR=$(PKG_CONFIG_PATH) STAGING_PREFIX=$(STAGING_DIR)/usr $(PKG_CONFIG) -MB_CFLAGS := $(shell $(PC) --cflags libmodbus) -MB_LDFLAGS := $(shell $(PC) --libs libmodbus) +PC=pkg-config UCW_CFLAGS := $(shell $(PC) --cflags libucw) -UCW_LDFLAGS := $(shell $(PC) --libs libucw) +UCW_LIBS := $(shell $(PC) --libs libucw) +MODBUS_CFLAGS := $(shell $(PC) --cflags libmodbus) +MODBUS_LIBS := $(shell $(PC) --libs libmodbus) +MOSQUITTO_CFLAGS := $(shell $(PC) --cflags libmosquitto) +MOSQUITTO_LIBS := $(shell $(PC) --libs libmosquitto) -export PATH=$(TARGET_PATH_PKG) -CC=$(TARGET_CC_NOCACHE) -LD=$(TARGET_LD_NOCACHE) -CFLAGS=$(TARGET_CFLAGS) $(MB_CFLAGS) $(UCW_CFLAGS) -std=gnu99 -LDFLAGS=$(TARGET_LDFLAGS) $(MB_LDFLAGS) $(UCW_LDFLAGS) -lmosquitto +CFLAGS=-O2 -Wall -Wextra -Wno-sign-compare -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes $(UCW_CFLAGS) $(MODBUS_CFLAGS) $(MOSQUITTO_CFLAGS) +LDLIBS=$(UCW_LIBS) $(MODBUS_LIBS) $(MOSQUITTO_LIBS) -all: burrow-powerd upload +all: burrow-powerd burrow-powerd: burrow-powerd.c -upload: - rsync -av burrow-powerd micac:/root/burrow/ +install: burrow-powerd + install burrow-powerd /usr/local/sbin/ + +clean: + rm -f *.o burrow-powerd + +.PHONY: all clean install diff --git a/power/daemon/burrow-powerd.c b/power/daemon/burrow-powerd.c index 0238218..ad34efb 100644 --- a/power/daemon/burrow-powerd.c +++ b/power/daemon/burrow-powerd.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -56,7 +57,7 @@ static void mqtt_publish(const char *topic, const char *fmt, ...) va_end(args); } -static void mqtt_log_callback(struct mosquitto *mosq UNUSED, void *obj UNUSED, int level, const char *message) +static void mqtt_log_callback(struct mosquitto *mosq UNUSED, void *obj UNUSED, int level UNUSED, const char *message UNUSED) { // msg(L_INFO, "MQTT(%d): %s", level, message); } @@ -139,13 +140,14 @@ static bool mb_connect(void) } mb_is_open = true; + return true; } /*** Main loop ***/ static u16 mb_regs[22]; -s32 get_s32(uint i) +static s32 get_s32(uint i) { if (mb_regs[i+1] < 0x8000) return (mb_regs[i+1] << 16) | mb_regs[i]; diff --git a/ssr/host/Makefile b/ssr/host/Makefile index 57d9081..f2a0e59 100644 --- a/ssr/host/Makefile +++ b/ssr/host/Makefile @@ -1,26 +1,23 @@ -TOPDIR=/root/turris - -include $(TOPDIR)/rules.mk -include $(TOPDIR)/include/package.mk - -PC := PATH=$(STAGING_DIR_HOST)/bin:$(PATH) PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) PKG_CONFIG_LIBDIR=$(PKG_CONFIG_PATH) STAGING_PREFIX=$(STAGING_DIR)/usr $(PKG_CONFIG) -USB_CFLAGS := $(shell $(PC) --cflags libusb-1.0) -USB_LDFLAGS := $(shell $(PC) --libs libusb-1.0) +PC=pkg-config UCW_CFLAGS := $(shell $(PC) --cflags libucw) -UCW_LDFLAGS := $(shell $(PC) --libs libucw) +UCW_LIBS := $(shell $(PC) --libs libucw) +USB_CFLAGS := $(shell $(PC) --cflags libusb-1.0) +USB_LIBS := $(shell $(PC) --libs libusb-1.0) +MOSQUITTO_CFLAGS := $(shell $(PC) --cflags libmosquitto) +MOSQUITTO_LIBS := $(shell $(PC) --libs libmosquitto) -export PATH=$(TARGET_PATH_PKG) -CC=$(TARGET_CC_NOCACHE) -LD=$(TARGET_LD_NOCACHE) -CFLAGS=$(TARGET_CFLAGS) $(USB_CFLAGS) $(UCW_CFLAGS) -std=gnu99 -LDFLAGS=$(TARGET_LDFLAGS) $(USB_LDFLAGS) $(UCW_LDFLAGS) -lmosquitto +CFLAGS=-O2 -Wall -Wextra -Wno-sign-compare -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes $(UCW_CFLAGS) $(USB_CFLAGS) $(MOSQUITTO_CFLAGS) +LDLIBS=$(UCW_LIBS) $(USB_LIBS) $(MOSQUITTO_LIBS) -all: ssr-control burrow-ssrd upload +all: ssr-control burrow-ssrd ssr-control: ssr-control.c burrow-ssrd: burrow-ssrd.c -upload: - rsync -av ssr-control burrow-ssrd micac:burrow/ +install: burrow-ssrd + install burrow-ssrd /usr/local/sbin/ + +clean: + rm -f *.o burrow-ssrd ssr-control -.PHONY: upload +.PHONY: all upload clean diff --git a/ssr/host/ssr-control.c b/ssr/host/ssr-control.c index cd3e082..c13c085 100644 --- a/ssr/host/ssr-control.c +++ b/ssr/host/ssr-control.c @@ -20,7 +20,7 @@ struct libusb_context *usb_ctxt; struct libusb_device_handle *devh; -void open_device(void) +static void open_device(void) { int err; libusb_device **devlist; @@ -107,7 +107,6 @@ int main(int argc, char **argv) int err; if (err = libusb_init(&usb_ctxt)) die("Cannot initialize libusb: error %d", err); - libusb_set_debug(usb_ctxt, 3); open_device(); if (get_temp) { -- 2.39.2