diff --git a/Makefile b/Makefile index b5ba3a8..05067d1 100644 --- a/Makefile +++ b/Makefile @@ -11,12 +11,16 @@ CONFIG_FILE=Makefile.inc include $(CONFIG_FILE) -GATEWAY=examples_RPi/MySGateway -GATEWAY_SOURCES=$(wildcard drivers/Linux/*.cpp) examples_RPi/MySGateway.cpp +GATEWAY=examples_linux/mysGateway +GATEWAY_SOURCES=$(wildcard drivers/Linux/*.cpp) examples_linux/mysGateway.cpp GATEWAY_OBJECTS=$(patsubst %.cpp,%.o,$(GATEWAY_SOURCES)) DEPS+=$(patsubst %.cpp,%.d,$(GATEWAY_SOURCES)) -CINCLUDE=-I. -I./core -I./drivers/Linux -I$(RF24H_LIB_DIR) +CINCLUDE=-I. -I./core -I./drivers/Linux + +ifneq ($(RF24H_LIB_DIR),) +CINCLUDE+=-I$(RF24H_LIB_DIR) +endif .PHONY: all gateway cleanconfig clean install uninstall force diff --git a/MyConfig.h b/MyConfig.h index 10444f8..3834b5f 100644 --- a/MyConfig.h +++ b/MyConfig.h @@ -410,17 +410,8 @@ #define MY_RF24_CE_PIN 4 #elif defined(ARDUINO_ARCH_SAMD) #define MY_RF24_CE_PIN 27 - #elif defined(RASPBERRYPI_ARCH) - #include - #include - #ifdef __RPI_BPLUS - #define MY_RF24_CE_PIN RPI_BPLUS_GPIO_J8_22 - #define MY_RF24_CS_PIN RPI_BPLUS_GPIO_J8_24 - #else - #define MY_RF24_CE_PIN RPI_V2_GPIO_P1_22 - #define MY_RF24_CS_PIN BCM2835_SPI_CS0 - #endif - #define MY_RF24_SPI_SPEED BCM2835_SPI_SPEED_8MHZ + #elif defined(LINUX) + #define MY_RF24_CE_PIN 22 #else #define MY_RF24_CE_PIN 9 #endif @@ -435,6 +426,8 @@ #define MY_RF24_CS_PIN 15 #elif defined(ARDUINO_ARCH_SAMD) #define MY_RF24_CS_PIN 3 + #elif defined(LINUX) + #define MY_RF24_CS_PIN 24 #else #define MY_RF24_CS_PIN 10 #endif @@ -616,7 +609,6 @@ //#define MY_GATEWAY_W5100 //#define MY_GATEWAY_ENC28J60 //#define MY_GATEWAY_ESP8266 -//#define MY_GATEWAY_RASPBERRYPI //#define MY_GATEWAY_LINUX /** diff --git a/MySensors.h b/MySensors.h index 81b514b..d4c7a5a 100644 --- a/MySensors.h +++ b/MySensors.h @@ -40,7 +40,7 @@ * @def MY_NODE_TYPE * @brief Contain a string describing the class of sketch/node (gateway/repeater/sensor). */ -#if defined(MY_GATEWAY_SERIAL) || defined(MY_GATEWAY_W5100) || defined(MY_GATEWAY_ENC28J60) || defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_RASPBERRYPI) || defined(MY_GATEWAY_LINUX) || defined(MY_GATEWAY_MQTT_CLIENT) +#if defined(MY_GATEWAY_SERIAL) || defined(MY_GATEWAY_W5100) || defined(MY_GATEWAY_ENC28J60) || defined(MY_GATEWAY_ESP8266) || defined(MY_GATEWAY_LINUX) || defined(MY_GATEWAY_MQTT_CLIENT) #define MY_GATEWAY_FEATURE #define MY_IS_GATEWAY (true) #define MY_NODE_TYPE "GW" @@ -52,10 +52,6 @@ #define MY_NODE_TYPE "NODE" #endif -#if defined(MY_GATEWAY_RASPBERRYPI) - #define MY_GATEWAY_LINUX -#endif - // Enable radio "feature" if one of the radio types was enabled #if defined(MY_RADIO_NRF24) || defined(MY_RADIO_RFM69) || defined(MY_RS485) #define MY_RADIO_FEATURE @@ -73,7 +69,7 @@ #include "core/MyHwATMega328.cpp" #elif defined(ARDUINO_ARCH_SAMD) #include "core/MyHwSAMD.cpp" -#elif defined(LINUX_ARCH_GENERIC) +#elif defined(LINUX) // Remove PSTR macros from debug prints #undef PSTR #define PSTR(x) (x) @@ -288,7 +284,7 @@ #if defined(MY_RF24_ENABLE_ENCRYPTION) #include "drivers/AES/AES.cpp" #endif - #if !defined(RASPBERRYPI_ARCH) + #if !defined(LINUX) #include "drivers/RF24/RF24.cpp" #endif #include "core/MyTransportNRF24.cpp" @@ -333,7 +329,7 @@ #if !defined(MY_CORE_ONLY) #if defined(ARDUINO_ARCH_ESP8266) #include "core/MyMainESP8266.cpp" - #elif defined(LINUX_ARCH_GENERIC) + #elif defined(LINUX) #include "core/MyMainLinux.cpp" #else #include "core/MyMainDefault.cpp" diff --git a/configure b/configure index 7507807..7ad5629 100755 --- a/configure +++ b/configure @@ -32,11 +32,15 @@ Installation options: --gateway-dir= Gateway files installation directory. [PREFIX/bin] MySensors options: - --my-debug Enables debug. - --my-gateway-type=[ethernet|mqtt] - Gateway type, default to ethernet. + --my-debug=[enable|disable] + Enables or disables debugging. + Default to enable. + --my-gateway=[none|ethernet|mqtt] + Gateway type, set to none to disable gateway feature. + Default to ethernet. --my-config-file= Config file path. [/etc/MySensorGateway.cfg] - --my-rf24-enable Enables RF24 radio. + --my-radio=[none|nrf24] Radio type, set to none to disable radio feature. + Default to rf24. --my-rf24-channel=<0-125> RF channel for the sensor net, 0-125. --my-rf24-pa-level=[RF24_PA_MAX|RF24_PA_LOW] RF24 PA level. @@ -45,7 +49,8 @@ MySensors options: --my-controller-ip-address= Controller or MQTT broker ip. Use commas instead of points. Example: 127,0,0,1 - --my-port= Controller or MQTT broker port. + --my-port= The port to keep open on gateway mode. + If gateway is set to mqtt, it sets the broker port. --my-mqtt-client-id= MQTT client id. --my-mqtt-publish-topic-prefix= MQTT publish topic prefix. @@ -164,10 +169,10 @@ function gcc_cpu_flags { local soc=$1 case $soc in BCM2835) - flags="-march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DRASPBERRYPI_ARCH" + flags="-march=armv6zk -mtune=arm1176jzf-s -mfpu=vfp -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI" ;; BCM2836) - flags="-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -DRASPBERRYPI_ARCH" + flags="-march=armv7-a -mtune=cortex-a7 -mfpu=neon-vfpv4 -mfloat-abi=hard -DLINUX_ARCH_RASPBERRYPI" ;; AM33XX) flags="-march=armv7-a -mtune=cortex-a8 -mfpu=neon -mfloat-abi=hard" @@ -190,7 +195,12 @@ function gcc_cpu_flags { echo ${flags} } -params="OS SOC CPUFLAGS CXXFLAGS LDFLAGS PREFIX CXX RF24H_LIB_DIR GATEWAY_DIR INIT_SYSTEM" +# Default values +debug=enable +gateway_type=ethernet +radio_type=nrf24 + +params="OS SOC CXXFLAGS LDFLAGS PREFIX CXX RF24H_LIB_DIR GATEWAY_DIR INIT_SYSTEM" for opt do if [ "$opt" = "-h" ] || [ "$opt" = "--help" ]; then @@ -229,20 +239,17 @@ for opt do --gateway-dir=*) GATEWAY_DIR="$optarg" ;; - --my-debug*) - CXXFLAGS="-DMY_DEBUG $CXXFLAGS" + --my-debug=*) + debug=${optarg} ;; - --my-gateway-type=*) - if [[ ${optarg} == "mqtt" ]]; then - LDFLAGS="-lmosquitto $LDFLAGS" - CXXFLAGS="-DMY_GATEWAY_MQTT_CLIENT $CXXFLAGS" - fi + --my-gateway=*) + gateway_type=${optarg} ;; --my-config-file=*) CXXFLAGS="-DMY_CONFIG_FILE=${optarg} $CXXFLAGS" ;; - --my-rf24-enable*) - CXXFLAGS="-DMY_RADIO_NRF24 $CXXFLAGS" + --my-radio=*) + radio_type=${optarg} ;; --my-rf24-channel=*) CXXFLAGS="-DMY_RF24_CHANNEL=${optarg} $CXXFLAGS" @@ -281,7 +288,6 @@ for opt do done PREFIX=${PREFIX:-/usr/local} -RF24H_LIB_DIR=${PREFIX}/include/RF24 GATEWAY_DIR=${GATEWAY_DIR:-${PREFIX}/bin} CXX=${CXX:-g++} @@ -299,13 +305,30 @@ if [ -z "${CPUFLAGS}" ]; then CPUFLAGS=$(gcc_cpu_flags $SOC) fi -CXXFLAGS="$CPUFLAGS -Ofast -g -Wall -Wextra -DLINUX_ARCH_GENERIC $CXXFLAGS" +CXXFLAGS="$CPUFLAGS -Ofast -g -Wall -Wextra -DLINUX $CXXFLAGS" if [[ $TYPE == "RPi2" || $TYPE == "RPi3" || $REV == "0010" ]]; then CXXFLAGS+="-D__RPI_BPLUS" -fi +fi -LDFLAGS="-pthread -lrf24-bcm $LDFLAGS" +if [[ ${debug} == "enable" ]]; then + CXXFLAGS="-DMY_DEBUG $CXXFLAGS" +fi + +if [[ ${gateway_type} == "ethernet" ]]; then + CXXFLAGS="-DMY_GATEWAY_LINUX $CXXFLAGS" +elif [[ ${gateway_type} == "mqtt" ]]; then + LDFLAGS="-lmosquitto $LDFLAGS" + CXXFLAGS="-DMY_GATEWAY_MQTT_CLIENT $CXXFLAGS" +fi + +if [[ ${radio_type} == "nrf24" ]]; then + CXXFLAGS="-DMY_RADIO_NRF24 $CXXFLAGS" + LDFLAGS="-lrf24-bcm $LDFLAGS" + RF24H_LIB_DIR=${PREFIX}/include/RF24 +fi + +LDFLAGS="-pthread $LDFLAGS" if [ -x /usr/bin/systemctl ] || [ -x /bin/systemctl ]; then INIT_SYSTEM=systemd diff --git a/core/MySensorsCore.cpp b/core/MySensorsCore.cpp index b142fe2..2d0a9db 100644 --- a/core/MySensorsCore.cpp +++ b/core/MySensorsCore.cpp @@ -51,7 +51,7 @@ void _process() { transportProcess(); #endif - #if defined(LINUX_ARCH_GENERIC) + #if defined(LINUX) // To avoid high cpu usage usleep(10000); // 10ms #endif @@ -65,7 +65,7 @@ void _infiniteLoop() { #if defined (MY_LEDS_BLINKING_FEATURE) ledsProcess(); #endif - #if defined(LINUX_ARCH_GENERIC) + #if defined(LINUX) exit(1); #endif } diff --git a/core/MyTransportNRF24.cpp b/core/MyTransportNRF24.cpp index 6dce160..ce39008 100644 --- a/core/MyTransportNRF24.cpp +++ b/core/MyTransportNRF24.cpp @@ -20,8 +20,8 @@ #include "MyConfig.h" #include "MyTransport.h" -#ifdef RASPBERRYPI_ARCH - #include "drivers/RF24/RF24_RPi.cpp" +#ifdef LINUX_ARCH_RASPBERRYPI + #include "drivers/RF24/RF24_Linux.cpp" #else #include "drivers/RF24/RF24.h" #endif diff --git a/drivers/Linux/Arduino.h b/drivers/Linux/Arduino.h index 39f0f6e..e928b04 100644 --- a/drivers/Linux/Arduino.h +++ b/drivers/Linux/Arduino.h @@ -51,6 +51,7 @@ char *ltoa(long value, char* result, int base); char *ultoa(long num, char *str, int radix); char *utoa(int num, char *str, int radix); char *dtostrf(float f, int width, int decimals, char *result); +void delay(unsigned int millis); #ifdef __cplusplus } diff --git a/drivers/Linux/utility.cpp b/drivers/Linux/compatibility.cpp similarity index 95% rename from drivers/Linux/utility.cpp rename to drivers/Linux/compatibility.cpp index aa36905..5c1e5fe 100644 --- a/drivers/Linux/utility.cpp +++ b/drivers/Linux/compatibility.cpp @@ -1,4 +1,5 @@ #include +#include #include "Arduino.h" /** @@ -175,3 +176,12 @@ char *dtostrf(float f, int width, int decimals, char *result) sprintf(result,"%*.*f", width, decimals, f); return result; } + +void delay(unsigned int millis) +{ + struct timespec sleeper; + + sleeper.tv_sec = (time_t)(millis / 1000); + sleeper.tv_nsec = (long)(millis % 1000) * 1000000; + nanosleep(&sleeper, NULL); +} diff --git a/drivers/RF24/RF24_RPi.cpp b/drivers/RF24/RF24_Linux.cpp similarity index 87% rename from drivers/RF24/RF24_RPi.cpp rename to drivers/RF24/RF24_Linux.cpp index f130df0..9b4c25a 100644 --- a/drivers/RF24/RF24_RPi.cpp +++ b/drivers/RF24/RF24_Linux.cpp @@ -16,35 +16,11 @@ * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * - * Based on Olivier Mauti work(RF24.h), copyright (C) 2016 Olivier Mauti + * This is a wrapper for maniacbug's RF24 library, copyright (C) 2011 J. Coliz */ -#include "RF24.h" - -// verify RF24 IRQ defs -#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) - #if !defined(MY_RF24_IRQ_PIN) - #error Message buffering feature requires MY_RF24_IRQ_PIN to be defined! - #endif - #ifndef SPI_HAS_TRANSACTION - #error RF24 IRQ usage requires transactional SPI support - #endif -#else - #ifdef MY_RX_MESSAGE_BUFFER_SIZE - #error Receive message buffering requires RF24 IRQ usage - #endif -#endif - -// pipes -#define BROADCAST_PIPE 1 -#define NODE_PIPE 2 - -// debug -#if defined(MY_DEBUG_VERBOSE_RF24) - #define RF24_DEBUG(x,...) debug(x, ##__VA_ARGS__) -#else - #define RF24_DEBUG(x,...) -#endif +#include +#include "RF24_Linux.h" #ifdef MY_RX_MESSAGE_BUFFER_FEATURE typedef void (*RF24_receiveCallbackType)(void); @@ -57,7 +33,7 @@ static uint8_t MY_RF24_BASE_ADDR[MY_RF24_ADDR_WIDTH] = { MY_RF24_BASE_RADIO_ID }; static uint8_t MY_RF24_NODE_ADDRESS = AUTO; -RF24 _rf24(MY_RF24_CE_PIN, MY_RF24_CS_PIN); +RF24 _rf24(RF24_CE_PIN, RF24_CS_PIN, MY_RF24_SPI_MAX_SPEED); static void RF24_startListening(void) { RF24_DEBUG(PSTR("start listening\n")); diff --git a/drivers/RF24/RF24_Linux.h b/drivers/RF24/RF24_Linux.h new file mode 100644 index 0000000..d1e00ac --- /dev/null +++ b/drivers/RF24/RF24_Linux.h @@ -0,0 +1,302 @@ +/** + * The MySensors Arduino library handles the wireless radio link and protocol + * between your home built sensors/actuators and HA controller of choice. + * The sensors forms a self healing radio network with optional repeaters. Each + * repeater and gateway builds a routing tables in EEPROM which keeps track of the + * network topology allowing messages to be routed to nodes. + * + * Created by Marcelo Aquino + * Copyright (C) 2016 Marcelo Aquino + * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors + * + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + * + */ + +#ifndef __RF24_LINUX_H__ +#define __RF24_LINUX_H__ + +// SPI settings +#if !defined(MY_RF24_SPI_MAX_SPEED) + #define MY_RF24_SPI_MAX_SPEED BCM2835_SPI_SPEED_8MHZ +#endif + +// verify RF24 IRQ defs +#if defined(MY_RX_MESSAGE_BUFFER_FEATURE) + #if !defined(MY_RF24_IRQ_PIN) + #error Message buffering feature requires MY_RF24_IRQ_PIN to be defined! + #endif + #ifndef SPI_HAS_TRANSACTION + #error RF24 IRQ usage requires transactional SPI support + #endif +#else + #ifdef MY_RX_MESSAGE_BUFFER_SIZE + #error Receive message buffering requires RF24 IRQ usage + #endif +#endif + +// pipes +#define BROADCAST_PIPE 1 +#define NODE_PIPE 2 + +// debug +#if defined(MY_DEBUG_VERBOSE_RF24) + #define RF24_DEBUG(x,...) debug(x, ##__VA_ARGS__) +#else + #define RF24_DEBUG(x,...) +#endif + +#ifdef LINUX_ARCH_RASPBERRYPI + // CE pin + #ifdef MY_RF24_CE_PIN + #ifdef __RPI_BPLUS + #if MY_RF24_CE_PIN == 3 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_03 + #elif MY_RF24_CE_PIN == 5 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_05 + #elif MY_RF24_CE_PIN == 7 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_07 + #elif MY_RF24_CE_PIN == 8 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_08 + #elif MY_RF24_CE_PIN == 10 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_10 + #elif MY_RF24_CE_PIN == 11 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_11 + #elif MY_RF24_CE_PIN == 12 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_12 + #elif MY_RF24_CE_PIN == 13 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_13 + #elif MY_RF24_CE_PIN == 15 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_15 + #elif MY_RF24_CE_PIN == 16 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_16 + #elif MY_RF24_CE_PIN == 18 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_18 + #elif MY_RF24_CE_PIN == 19 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_19 + #elif MY_RF24_CE_PIN == 21 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_21 + #elif MY_RF24_CE_PIN == 22 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_22 + #elif MY_RF24_CE_PIN == 23 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_23 + #elif MY_RF24_CE_PIN == 24 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_24 + #elif MY_RF24_CE_PIN == 26 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_26 + #elif MY_RF24_CE_PIN == 29 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_29 + #elif MY_RF24_CE_PIN == 31 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_31 + #elif MY_RF24_CE_PIN == 32 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_32 + #elif MY_RF24_CE_PIN == 33 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_33 + #elif MY_RF24_CE_PIN == 35 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_35 + #elif MY_RF24_CE_PIN == 36 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_36 + #elif MY_RF24_CE_PIN == 37 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_37 + #elif MY_RF24_CE_PIN == 38 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_38 + #elif MY_RF24_CE_PIN == 40 + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_40 + #else + #error invalid value for MY_RF24_CE_PIN + #endif + #else + #if MY_RF24_CE_PIN == 3 + #define RF24_CE_PIN RPI_V2_GPIO_P1_03 + #elif MY_RF24_CE_PIN == 5 + #define RF24_CE_PIN RPI_V2_GPIO_P1_05 + #elif MY_RF24_CE_PIN == 7 + #define RF24_CE_PIN RPI_V2_GPIO_P1_07 + #elif MY_RF24_CE_PIN == 8 + #define RF24_CE_PIN RPI_V2_GPIO_P1_08 + #elif MY_RF24_CE_PIN == 10 + #define RF24_CE_PIN RPI_V2_GPIO_P1_10 + #elif MY_RF24_CE_PIN == 11 + #define RF24_CE_PIN RPI_V2_GPIO_P1_11 + #elif MY_RF24_CE_PIN == 12 + #define RF24_CE_PIN RPI_V2_GPIO_P1_12 + #elif MY_RF24_CE_PIN == 13 + #define RF24_CE_PIN RPI_V2_GPIO_P1_13 + #elif MY_RF24_CE_PIN == 15 + #define RF24_CE_PIN RPI_V2_GPIO_P1_15 + #elif MY_RF24_CE_PIN == 16 + #define RF24_CE_PIN RPI_V2_GPIO_P1_16 + #elif MY_RF24_CE_PIN == 18 + #define RF24_CE_PIN RPI_V2_GPIO_P1_18 + #elif MY_RF24_CE_PIN == 19 + #define RF24_CE_PIN RPI_V2_GPIO_P1_19 + #elif MY_RF24_CE_PIN == 21 + #define RF24_CE_PIN RPI_V2_GPIO_P1_21 + #elif MY_RF24_CE_PIN == 22 + #define RF24_CE_PIN RPI_V2_GPIO_P1_22 + #elif MY_RF24_CE_PIN == 23 + #define RF24_CE_PIN RPI_V2_GPIO_P1_23 + #elif MY_RF24_CE_PIN == 24 + #define RF24_CE_PIN RPI_V2_GPIO_P1_24 + #elif MY_RF24_CE_PIN == 26 + #define RF24_CE_PIN RPI_V2_GPIO_P1_26 + #elif MY_RF24_CE_PIN == 29 + #define RF24_CE_PIN RPI_V2_GPIO_P1_29 + #elif MY_RF24_CE_PIN == 31 + #define RF24_CE_PIN RPI_V2_GPIO_P1_31 + #elif MY_RF24_CE_PIN == 32 + #define RF24_CE_PIN RPI_V2_GPIO_P1_32 + #elif MY_RF24_CE_PIN == 33 + #define RF24_CE_PIN RPI_V2_GPIO_P1_33 + #elif MY_RF24_CE_PIN == 35 + #define RF24_CE_PIN RPI_V2_GPIO_P1_35 + #elif MY_RF24_CE_PIN == 36 + #define RF24_CE_PIN RPI_V2_GPIO_P1_36 + #elif MY_RF24_CE_PIN == 37 + #define RF24_CE_PIN RPI_V2_GPIO_P1_37 + #elif MY_RF24_CE_PIN == 38 + #define RF24_CE_PIN RPI_V2_GPIO_P1_38 + #elif MY_RF24_CE_PIN == 40 + #define RF24_CE_PIN RPI_V2_GPIO_P1_40 + #else + #error invalid value for MY_RF24_CE_PIN + #endif + #endif + #else + #ifdef __RPI_BPLUS + #define RF24_CE_PIN RPI_BPLUS_GPIO_J8_22 + #else + #define RF24_CE_PIN RPI_V2_GPIO_P1_22 + #endif + #endif + + // CS pin + #ifdef MY_RF24_CS_PIN + #ifdef __RPI_BPLUS + #if MY_RF24_CS_PIN == 3 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_03 + #elif MY_RF24_CS_PIN == 5 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_05 + #elif MY_RF24_CS_PIN == 7 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_07 + #elif MY_RF24_CS_PIN == 8 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_08 + #elif MY_RF24_CS_PIN == 10 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_10 + #elif MY_RF24_CS_PIN == 11 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_11 + #elif MY_RF24_CS_PIN == 12 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_12 + #elif MY_RF24_CS_PIN == 13 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_13 + #elif MY_RF24_CS_PIN == 15 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_15 + #elif MY_RF24_CS_PIN == 16 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_16 + #elif MY_RF24_CS_PIN == 18 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_18 + #elif MY_RF24_CS_PIN == 19 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_19 + #elif MY_RF24_CS_PIN == 21 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_21 + #elif MY_RF24_CS_PIN == 22 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_22 + #elif MY_RF24_CS_PIN == 23 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_23 + #elif MY_RF24_CS_PIN == 24 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_24 + #elif MY_RF24_CS_PIN == 26 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_26 + #elif MY_RF24_CS_PIN == 29 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_29 + #elif MY_RF24_CS_PIN == 31 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_31 + #elif MY_RF24_CS_PIN == 32 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_32 + #elif MY_RF24_CS_PIN == 33 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_33 + #elif MY_RF24_CS_PIN == 35 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_35 + #elif MY_RF24_CS_PIN == 36 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_36 + #elif MY_RF24_CS_PIN == 37 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_37 + #elif MY_RF24_CS_PIN == 38 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_38 + #elif MY_RF24_CS_PIN == 40 + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_40 + #else + #error invalid value for MY_RF24_CS_PIN + #endif + #else + #if MY_RF24_CS_PIN == 3 + #define RF24_CS_PIN RPI_V2_GPIO_P1_03 + #elif MY_RF24_CS_PIN == 5 + #define RF24_CS_PIN RPI_V2_GPIO_P1_05 + #elif MY_RF24_CS_PIN == 7 + #define RF24_CS_PIN RPI_V2_GPIO_P1_07 + #elif MY_RF24_CS_PIN == 8 + #define RF24_CS_PIN RPI_V2_GPIO_P1_08 + #elif MY_RF24_CS_PIN == 10 + #define RF24_CS_PIN RPI_V2_GPIO_P1_10 + #elif MY_RF24_CS_PIN == 11 + #define RF24_CS_PIN RPI_V2_GPIO_P1_11 + #elif MY_RF24_CS_PIN == 12 + #define RF24_CS_PIN RPI_V2_GPIO_P1_12 + #elif MY_RF24_CS_PIN == 13 + #define RF24_CS_PIN RPI_V2_GPIO_P1_13 + #elif MY_RF24_CS_PIN == 15 + #define RF24_CS_PIN RPI_V2_GPIO_P1_15 + #elif MY_RF24_CS_PIN == 16 + #define RF24_CS_PIN RPI_V2_GPIO_P1_16 + #elif MY_RF24_CS_PIN == 18 + #define RF24_CS_PIN RPI_V2_GPIO_P1_18 + #elif MY_RF24_CS_PIN == 19 + #define RF24_CS_PIN RPI_V2_GPIO_P1_19 + #elif MY_RF24_CS_PIN == 21 + #define RF24_CS_PIN RPI_V2_GPIO_P1_21 + #elif MY_RF24_CS_PIN == 22 + #define RF24_CS_PIN RPI_V2_GPIO_P1_22 + #elif MY_RF24_CS_PIN == 23 + #define RF24_CS_PIN RPI_V2_GPIO_P1_23 + #elif MY_RF24_CS_PIN == 24 + #define RF24_CS_PIN BCM2835_SPI_CS0 + #elif MY_RF24_CS_PIN == 26 + #define RF24_CS_PIN BCM2835_SPI_CS1 + #elif MY_RF24_CS_PIN == 29 + #define RF24_CS_PIN RPI_V2_GPIO_P1_29 + #elif MY_RF24_CS_PIN == 31 + #define RF24_CS_PIN RPI_V2_GPIO_P1_31 + #elif MY_RF24_CS_PIN == 32 + #define RF24_CS_PIN RPI_V2_GPIO_P1_32 + #elif MY_RF24_CS_PIN == 33 + #define RF24_CS_PIN RPI_V2_GPIO_P1_33 + #elif MY_RF24_CS_PIN == 35 + #define RF24_CS_PIN RPI_V2_GPIO_P1_35 + #elif MY_RF24_CS_PIN == 36 + #define RF24_CS_PIN RPI_V2_GPIO_P1_36 + #elif MY_RF24_CS_PIN == 37 + #define RF24_CS_PIN RPI_V2_GPIO_P1_37 + #elif MY_RF24_CS_PIN == 38 + #define RF24_CS_PIN RPI_V2_GPIO_P1_38 + #elif MY_RF24_CS_PIN == 40 + #define RF24_CS_PIN RPI_V2_GPIO_P1_40 + #else + #error invalid value for MY_RF24_CS_PIN + #endif + #endif + #else + #ifdef __RPI_BPLUS + #define RF24_CS_PIN RPI_BPLUS_GPIO_J8_24 + #else + #define RF24_CS_PIN BCM2835_SPI_CS0 + #endif + #endif +#endif + +#endif diff --git a/examples_RPi/MySGateway.cpp b/examples_RPi/MySGateway.cpp deleted file mode 100644 index 8a7e9dd..0000000 --- a/examples_RPi/MySGateway.cpp +++ /dev/null @@ -1,91 +0,0 @@ -/** - * The MySensors Arduino library handles the wireless radio link and protocol - * between your home built sensors/actuators and HA controller of choice. - * The sensors forms a self healing radio network with optional repeaters. Each - * repeater and gateway builds a routing tables in EEPROM which keeps track of the - * network topology allowing messages to be routed to nodes. - * - * Created by Marcelo Aquino - * Copyleft (c) 2016, Marcelo Aquino - * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors - * - * Documentation: http://www.mysensors.org - * Support Forum: http://forum.mysensors.org - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * version 2 as published by the Free Software Foundation. - */ - -#include -#include -#include - -// Enable debug prints to monitor -#ifndef MY_DEBUG - #define MY_DEBUG -#endif - -// Config file -#ifndef MY_LINUX_CONFIG_FILE - #define MY_LINUX_CONFIG_FILE "/etc/MySensorGateway.cfg" -#endif - -// Enables and select radio type (if attached) -#ifndef MY_RADIO_NRF24 - #define MY_RADIO_NRF24 -#endif - -#define MY_GATEWAY_RASPBERRYPI - -// How many clients should be able to connect to this gateway (default 1) -#define MY_GATEWAY_MAX_CLIENTS 10 - -#ifdef MY_GATEWAY_MQTT_CLIENT - // Set MQTT client id - #ifndef MY_MQTT_CLIENT_ID - #define MY_MQTT_CLIENT_ID "mysensors-1" - #endif - // MQTT broker ip address. - #ifndef MY_CONTROLLER_IP_ADDRESS - #define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 - #endif - // The MQTT broker port to to open - #ifndef MY_PORT - #define MY_PORT 1883 - #endif - - // Enable these if your MQTT broker requires usenrame/password - //#define MY_MQTT_USER "username" - //#define MY_MQTT_PASSWORD "password" - - // Set this node's subscribe and publish topic prefix - #ifndef MY_MQTT_PUBLISH_TOPIC_PREFIX - #define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out" - #endif - #ifndef MY_MQTT_SUBSCRIBE_TOPIC_PREFIX - #define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in" - #endif -#else - // Enable MY_IP_ADDRESS here if you want to listen for incoming network - // connections on the specified IP address/hostname only - //#define MY_IP_ADDRESS 192,168,178,87 - - // The port to keep open on node server mode - #ifndef MY_PORT - #define MY_PORT 5003 - #endif -#endif - -#include - -void setup() { -} - -void presentation() { - // Present locally attached sensors here -} - -void loop() { - // Send locally attached sensors data here -} diff --git a/examples_linux/mysGateway.cpp b/examples_linux/mysGateway.cpp new file mode 100644 index 0000000..b53ffcc --- /dev/null +++ b/examples_linux/mysGateway.cpp @@ -0,0 +1,55 @@ +/** + * The MySensors Arduino library handles the wireless radio link and protocol + * between your home built sensors/actuators and HA controller of choice. + * The sensors forms a self healing radio network with optional repeaters. Each + * repeater and gateway builds a routing tables in EEPROM which keeps track of the + * network topology allowing messages to be routed to nodes. + * + * Created by Marcelo Aquino + * Copyleft (c) 2016, Marcelo Aquino + * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors + * + * Documentation: http://www.mysensors.org + * Support Forum: http://forum.mysensors.org + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * version 2 as published by the Free Software Foundation. + */ + +#include +#include +#include + +// For more options run ./configure --help + +// Config file +//#define MY_LINUX_CONFIG_FILE "/etc/MySensorGateway.cfg" + +// How many clients should be able to connect to this gateway (default 1) +#define MY_GATEWAY_MAX_CLIENTS 10 + +// MQTT options +//#define MY_CONTROLLER_IP_ADDRESS 192, 168, 178, 68 +//#define MY_PORT 1883 +//#define MY_MQTT_CLIENT_ID "mysensors-1" +//#define MY_MQTT_PUBLISH_TOPIC_PREFIX "mygateway1-out" +//#define MY_MQTT_SUBSCRIBE_TOPIC_PREFIX "mygateway1-in" + +// Enable these if your MQTT broker requires usenrame/password +//#define MY_MQTT_USER "username" +//#define MY_MQTT_PASSWORD "password" + + +#include + +void setup() { +} + +void presentation() { + // Present locally attached sensors here +} + +void loop() { + // Send locally attached sensors data here +} diff --git a/initscripts/mysgateway.systemd b/initscripts/mysgateway.systemd index 9763c66..5b707c6 100644 --- a/initscripts/mysgateway.systemd +++ b/initscripts/mysgateway.systemd @@ -3,7 +3,7 @@ Description=MySensors Gateway daemon Requires=network.target [Service] -ExecStart=%gateway_dir%/MySGateway +ExecStart=%gateway_dir%/mysGateway [Install] WantedBy=multi-user.target diff --git a/initscripts/mysgateway.sysvinit b/initscripts/mysgateway.sysvinit index df01c6c..34ee0c4 100644 --- a/initscripts/mysgateway.sysvinit +++ b/initscripts/mysgateway.sysvinit @@ -1,6 +1,6 @@ #! /bin/sh ### BEGIN INIT INFO -# Provides: MySGateway +# Provides: mysGateway # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 @@ -20,7 +20,7 @@ # PATH should only include /usr/* if it runs after the mountnfs.sh script PATH=/sbin:/usr/sbin:/bin:/usr/bin:/usr/local/sbin:/usr/local/bin DESC="MySensors Gateway" -NAME=MySGateway +NAME=mysGateway DAEMON=%gateway_dir%/$NAME DAEMON_ARGS="-d" PIDFILE=/var/run/$NAME.pid