From 9fc5ba99f5c1156180461bb0122b79d40255a13e Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sun, 3 May 2020 22:56:40 +0900 Subject: [PATCH] Allow pins/settings to be defined in INI file (#597) * Allow pins/settings to be defined in INI file * Open to make publishing ManufacturerData optional --- main/ZgatewayBT.ino | 2 ++ main/config_2G.h | 26 ++++++++++++++------------ main/config_ADC.h | 14 +++++++++++--- main/config_BT.h | 34 +++++++++++++++++++++++----------- main/config_DHT.h | 14 ++++++++------ main/config_DS1820.h | 19 ++++++++++++------- main/config_FASTLED.h | 13 +++++-------- main/config_HCSR501.h | 18 +++++++++++------- main/config_HTU21.h | 6 ++++-- 9 files changed, 90 insertions(+), 56 deletions(-) diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index 9d77aa5..cde2373 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -341,8 +341,10 @@ class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks { //if not black listed mac we go AND if we have no white mac or this mac is white we go out if (advertisedDevice.haveName()) BLEdata.set("name", (char *)advertisedDevice.getName().c_str()); + #if pubBLEManufacturerData if (advertisedDevice.haveManufacturerData()) BLEdata.set("manufacturerdata", (char *)advertisedDevice.getManufacturerData().c_str()); + #endif if (advertisedDevice.haveRSSI()) BLEdata.set("rssi", (int)advertisedDevice.getRSSI()); if (advertisedDevice.haveTXPower()) diff --git a/main/config_2G.h b/main/config_2G.h index 15ba8d0..0865b1e 100644 --- a/main/config_2G.h +++ b/main/config_2G.h @@ -42,18 +42,20 @@ extern void MQTTto2G(char *topicOri, JsonObject &SMSdata); #define _2G_MAX_SIGNAL 1000 /*-------------------PIN DEFINITIONS----------------------*/ -#ifdef ESP8266 - #define _2G_TX_PIN D6 //D6 to A6 RX, - #define _2G_RX_PIN D7 //D7 to A6 TX - #define _2G_PWR_PIN D5 // connect a MOSFET to power on and off your A6/7 module -#elif defined(ESP32) - #define _2G_TX_PIN 16 //D16 to A6 RX, - #define _2G_RX_PIN 17 //D17 to A6 TX - #define _2G_PWR_PIN 5 // connect a MOSFET to power on and off your A6/7 module -#else - #define _2G_TX_PIN 6 //D6 to A6 RX, - #define _2G_RX_PIN 7 //D7 to A6 TX - #define _2G_PWR_PIN 5 // connect a MOSFET to power on and off your A6/7 module +#if !defined(_2G_TX_PIN) || !defined(_2G_RX_PIN) || !defined(_2G_PWR_PIN) + #ifdef ESP8266 + #define _2G_TX_PIN D6 //D6 to A6 RX, + #define _2G_RX_PIN D7 //D7 to A6 TX + #define _2G_PWR_PIN D5 // connect a MOSFET to power on and off your A6/7 module + #elif defined(ESP32) + #define _2G_TX_PIN 16 //D16 to A6 RX, + #define _2G_RX_PIN 17 //D17 to A6 TX + #define _2G_PWR_PIN 5 // connect a MOSFET to power on and off your A6/7 module + #else + #define _2G_TX_PIN 6 //D6 to A6 RX, + #define _2G_RX_PIN 7 //D7 to A6 TX + #define _2G_PWR_PIN 5 // connect a MOSFET to power on and off your A6/7 module + #endif #endif #endif \ No newline at end of file diff --git a/main/config_ADC.h b/main/config_ADC.h index eddc5ea..bd3bf77 100644 --- a/main/config_ADC.h +++ b/main/config_ADC.h @@ -31,10 +31,18 @@ extern void ADCtoMQTT(); /*----------------------------USER PARAMETERS-----------------------------*/ /*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/ #define ADCTOPIC "/ADCtoMQTT" -#define TimeBetweenReadingADC 500 // time between 2 ADC readings, minimum 200 to let the time of the ESP to keep the connection -#define ThresholdReadingADC 50 // following the comparison between the previous value and the current one +- the threshold the value will be published or not + +#if !defined(TimeBetweenReadingADC) || (TimeBetweenReadingADC < 200) + #define TimeBetweenReadingADC 500 // time between 2 ADC readings, minimum 200 to let the time of the ESP to keep the connection +#endif + +#ifndef ThresholdReadingADC + #define ThresholdReadingADC 50 // following the comparison between the previous value and the current one +- the threshold the value will be published or not +#endif /*-------------------PIN DEFINITIONS----------------------*/ -#define ADC_PIN A0 //on nodeMCU this is D3 GPIO0 +#if defined(ESP8266) || !defined(ADC_PIN) + #define ADC_PIN A0 //on nodeMCU this is D3 GPIO0 +#endif #endif \ No newline at end of file diff --git a/main/config_BT.h b/main/config_BT.h index 22614fa..e82d3e1 100644 --- a/main/config_BT.h +++ b/main/config_BT.h @@ -32,14 +32,24 @@ extern void MQTTtoBT(char * topicOri, JsonObject& RFdata); /*----------------------BT topics & parameters-------------------------*/ #define subjectBTtoMQTT "/BTtoMQTT" #define subjectMQTTtoBTset "/commands/MQTTtoBT/config" -#define TimeBtw_Read 55555 //define default time between 2 scans #define MinimumRSSI -100 //default minimum rssi value, all the devices below -90 will not be reported #define Scan_duration 10 //define the time for a scan --WARNING-- changing this value can lead to instability on ESP32 #define HM-10 //#define HM-11 // uncomment this line if you use HM-11 and comment the line above //#define HM_BLUE_LED_STOP true //uncomment to stop the blue led light of HM1X #define BLEdelimiter "4f4b2b444953413a" -#define pubBLEServiceData true // comment if you don't want to publish service data (in case you are having too heavy service data) https://github.com/1technophile/OpenMQTTGateway/issues/318#issuecomment-446064707 + +#ifndef TimeBtw_Read + #define TimeBtw_Read 55555 //define default time between 2 scans +#endif + +#ifndef pubBLEServiceData + #define pubBLEServiceData true // comment if you don't want to publish service data (in case you are having too heavy service data) https://github.com/1technophile/OpenMQTTGateway/issues/318#issuecomment-446064707 +#endif + +#ifndef pubBLEManufacturerData + #define pubBLEManufacturerData false // define true if you want to publish the manufacturer's data (sometimes contains characters that aren't valid with receiving client) +#endif /*-------------------HOME ASSISTANT ROOM PRESENCE ----------------------*/ // if not commented Home presence integration with HOME ASSISTANT is activated @@ -68,15 +78,17 @@ struct decompose{ }; /*-------------------PIN DEFINITIONS----------------------*/ -#ifdef ESP8266 - #define BT_RX 13 //D7 ESP8266 RX connect HM-10 or 11 TX - #define BT_TX 12 //D6 ESP8266 TX connect HM-10 or 11 RX -#elif defined(ESP32) - #define BT_RX 18 // not tested - #define BT_TX 19 // not tested -#else - #define BT_RX 5 //arduino RX connect HM-10 or 11 TX - #define BT_TX 6 //arduino TX connect HM-10 or 11 RX +#if !defined(BT_RX) || !defined(BT_TX) + #ifdef ESP8266 + #define BT_RX 13 //D7 ESP8266 RX connect HM-10 or 11 TX + #define BT_TX 12 //D6 ESP8266 TX connect HM-10 or 11 RX + #elif defined(ESP32) + #define BT_RX 18 // not tested + #define BT_TX 19 // not tested + #else + #define BT_RX 5 //arduino RX connect HM-10 or 11 TX + #define BT_TX 6 //arduino TX connect HM-10 or 11 RX + #endif #endif #endif \ No newline at end of file diff --git a/main/config_DHT.h b/main/config_DHT.h index 1af44b5..92b9905 100644 --- a/main/config_DHT.h +++ b/main/config_DHT.h @@ -38,12 +38,14 @@ extern void DHTtoMQTT(); //#define DHT_SENSOR_TYPE DHT21 //uncomment for DHT21 Sensor #define DHT_SENSOR_TYPE DHT22 //uncomment for DHT22 Sensor (default for backwards compatibility) /*-------------------PIN DEFINITIONS----------------------*/ -#if defined(ESP8266) - #define DHT_RECEIVER_PIN 5 //5 = D1 you can put 14 = D5 if you don't use HCSR501 sensor and the RFM69 -#elif defined(ESP32) - #define DHT_RECEIVER_PIN 16 -#else - #define DHT_RECEIVER_PIN 8 +#ifndef DHT_RECEIVER_PIN + #if defined(ESP8266) + #define DHT_RECEIVER_PIN 5 //5 = D1 you can put 14 = D5 if you don't use HCSR501 sensor and the RFM69 + #elif defined(ESP32) + #define DHT_RECEIVER_PIN 16 + #else + #define DHT_RECEIVER_PIN 8 + #endif #endif #endif \ No newline at end of file diff --git a/main/config_DS1820.h b/main/config_DS1820.h index 922b95e..1d0e011 100644 --- a/main/config_DS1820.h +++ b/main/config_DS1820.h @@ -35,16 +35,21 @@ extern void DS1820toMQTT(); #define DS1820_ALWAYS true // if false only published current temperature if has changed from previous reading #define DS1820_INTERVAL_SEC 60 // time between DS1820 readings (seconds) #define DS1820_RESOLUTION 10 // conversion times: 9 bit (93.75 ms), 10 bit (187.5 ms), 11 bit (375 ms), 12 bit (750 ms) -#define DS1820_FAHRENHEIT false // defaults to Celcius +#ifndef DS1820_FAHRENHEIT + #define DS1820_FAHRENHEIT false // defaults to Celcius +#endif #define DS1820_DETAILS true // publish extented info for each sensor (resolution, address, type) #define DS1820_CONV_TIME 2000 // trigger conversion before requesting temperature readings (ms) /*-------------------PIN DEFINITIONS----------------------*/ -#if defined(ESP8266) - #define DS1820_OWBUS_PIN 2 -#elif defined(ESP32) - #define DS1820_OWBUS_PIN 2 -#else - #define DS1820_OWBUS_PIN 2 + +#ifndef DS1820_OWBUS_PIN + #if defined(ESP8266) + #define DS1820_OWBUS_PIN 2 + #elif defined(ESP32) + #define DS1820_OWBUS_PIN 2 + #else + #define DS1820_OWBUS_PIN 2 + #endif #endif #endif diff --git a/main/config_FASTLED.h b/main/config_FASTLED.h index e8ea371..56eec3b 100644 --- a/main/config_FASTLED.h +++ b/main/config_FASTLED.h @@ -21,6 +21,9 @@ along with this program. If not, see . */ +#ifndef config_FASTLED_h +#define config_FASTLED_h + /*-------------------FASTLED topics & parameters----------------------*/ //FASTLED MQTT Subjects #define subjectMQTTtoFASTLED "/commands/MQTTtoFASTLED" @@ -66,14 +69,6 @@ //#define DATA_PIN 3 //#define CLOCK_PIN 13 -#ifdef ESP8266 - -#elif ESP32 - -#else - -#endif - #ifdef ESP8266 //#define FASTLED_ESP8266_RAW_PIN_ORDER //#define FASTLED_ESP8266_NODEMCU_PIN_ORDER @@ -87,3 +82,5 @@ #define FASTLED_DATA_PIN 10 #define FASTLED_CLOCK_PIN 13 #endif + +#endif \ No newline at end of file diff --git a/main/config_HCSR501.h b/main/config_HCSR501.h index ab45808..6803ba2 100644 --- a/main/config_HCSR501.h +++ b/main/config_HCSR501.h @@ -32,15 +32,19 @@ extern void HCSR501toMQTT(); /*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/ #define subjectHCSR501toMQTT "/HCSR501toMQTT" -#define TimeBeforeStartHCSR501 60000 //define the time necessary for HC SR501 init +#ifndef TimeBeforeStartHCSR501 + #define TimeBeforeStartHCSR501 60000 //define the time necessary for HC SR501 init +#endif /*-------------------PIN DEFINITIONS----------------------*/ -#if defined(ESP8266) - #define HCSR501_PIN D5 -#elif defined(ESP32) - #define HCSR501_PIN 5 -#else - #define HCSR501_PIN 7 +#ifndef HCSR501_PIN + #if defined(ESP8266) + #define HCSR501_PIN D5 + #elif defined(ESP32) + #define HCSR501_PIN 5 + #else + #define HCSR501_PIN 7 + #endif #endif #endif \ No newline at end of file diff --git a/main/config_HTU21.h b/main/config_HTU21.h index 1cca815..28b08de 100644 --- a/main/config_HTU21.h +++ b/main/config_HTU21.h @@ -49,8 +49,10 @@ extern void HTU21toMQTT(); #define HTUTOPIC "/CLIMAtoMQTT/htu" #if defined(ESP32) - #define I2C_SDA 16 - #define I2C_SCL 0 + #if !defined(I2C_SDA) || !defined(I2C_SCL) + #define I2C_SDA 16 + #define I2C_SCL 0 + #endif #endif #endif \ No newline at end of file