Compare commits

...

2 Commits

Author SHA1 Message Date
7139cd1e5f Add openwrt makefile 2020-10-29 19:27:01 +01:00
27905dc590 Fix problem with start 2020-10-29 19:26:25 +01:00
3 changed files with 61 additions and 9 deletions

View File

@@ -1,4 +1,4 @@
VERSION = 0.0.7
VERSION = 0.0.11
# Global target; when 'make' is run without arguments, this is what it should do
all: bell-mqtt-recv
@@ -35,4 +35,4 @@ clean:
rm bell-mqtt-recv -f *.o
pack:
tar cvzf ../bell-rspro-$(VERSION).tar.gz $(DEPS) $(SRC) Makefile bell-rspro.init
tar cvzf ../bell-rspro-$(VERSION).tar.gz $(DEPS) $(SRC) Makefile Makefile.openwrt bell-rspro.init

54
Makefile.openwrt Normal file
View File

@@ -0,0 +1,54 @@
include $(TOPDIR)/rules.mk
# Name, version and release number
# The name and version of your package are used to define the variable to point to the build directory of your package: $(PKG_BUILD_DIR)
PKG_NAME:=bell-rspro
PKG_VERSION:=0.0.10
PKG_RELEASE:=1
# Source settings (i.e. where to find the source codes)
# This is a custom variable, used below
SOURCE_DIR:=/home/jaro/bell-rspro
include $(INCLUDE_DIR)/package.mk
# Package definition; instructs on how and where our package will appear in the overall configuration menu ('make menuconfig')
define Package/bell-rspro
SECTION:=net
CATEGORY:=Network
PKG_BUILD_DEPENDS:=mosquitto
TITLE:=bell-rspro
DEPENDS:=+libmosquitto-nossl
endef
# Package description; a more verbose description on what our package does
define Package/bell-rspro/description
App for home automation with MQTT for RS PRO and sending signal to GPIO port
endef
# Package preparation instructions; create the build directory and copy the source code.
# The last command is necessary to ensure our preparation instructions remain compatible with the patching system.
define Build/Prepare
mkdir -p $(PKG_BUILD_DIR)
cp $(SOURCE_DIR)/* $(PKG_BUILD_DIR)
$(Build/Patch)
endef
# Package build instructions; invoke the target-specific compiler to first compile the source file, and then to link the file into the final executable
define Build/Compile
$(MAKE) -C $(PKG_BUILD_DIR) \
CC="$(TARGET_CC)" \
LD="$(TARGET_LD)" \
CFLAGS="$(TARGET_CFLAGS)" \
LDFLAGS="$(TARGET_LDFLAGS) -lmosquitto" \
CROSS_COMPILE="$(REAL_GNU_TARGET_NAME)-"
endef
# Package install instructions; create a directory inside the package to hold our executable, and then copy the executable we built previously into the folder
define Package/bell-rspro/install
$(INSTALL_DIR) $(1)/usr/sbin
$(INSTALL_DIR) $(1)/etc/init.d
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bell-mqtt-recv $(1)/usr/sbin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/bell-rspro.init $(1)/etc/init.d/bell-rspro
endef
$(eval $(call BuildPackage,bell-rspro))

View File

@@ -32,19 +32,17 @@ static void writeToFile(const char *absoluteFileName, const char *contents) {
}
void gpioSetup(const char *pin) {
// TODO only export if not already exported...
if (access("/sys/class/gpio/unexport",W_OK) == 0)
writeToFile("/sys/class/gpio/unexport", pin);
writeToFile("/sys/class/gpio/export", pin);
char buf[33];
char buf[64];
struct stat statBuf;
int pinExported = -1;
sprintf(buf, "/sys/class/gpio/gpio%s/direction", pin);
if (stat(buf, &statBuf) != 0)
writeToFile("/sys/class/gpio/export", pin);
// May have to briefly wait for OS to make symlink!
while (pinExported != 0) {
while (pinExported != 0) {
msleep(1000);
pinExported = stat(buf, &statBuf);
}