Add experimental support for NRF24L01 as BLE-bridge

Add experimental support for NRF24L01 as BLE-bridge for Mijia Bluetooth sensors by Christian Baars (#7394)
This commit is contained in:
Theo Arends 2020-01-02 16:58:20 +01:00
parent 5489c91172
commit c4f6a359a7
5 changed files with 44 additions and 38 deletions

View File

@ -69,3 +69,4 @@ The following binary downloads have been compiled with ESP8266/Arduino library c
- Add Zigbee attribute decoder for Xiaomi Aqara Cube
- Add support for ``AdcParam`` parameters to control ADC0 Current Transformer Apparent Power formula by Jodi Dillon (#7100)
- Add optional support for Prometheus using file xsns_91_prometheus.ino (#7216)
- Add experimental support for NRF24L01 as BLE-bridge for Mijia Bluetooth sensors by Christian Baars (#7394)

View File

@ -5,6 +5,7 @@
- Add support for ``AdcParam`` parameters to control ADC0 Current Transformer Apparent Power formula by Jodi Dillon (#7100)
- Add optional support for Prometheus using file xsns_91_prometheus.ino (#7216)
- Add command ``ShutterButton <parameters>`` to control shutter(s) by to-scho (#7403)
- Add experimental support for NRF24L01 as BLE-bridge for Mijia Bluetooth sensors by Christian Baars (#7394)
- Fix LCD line and column positioning (#7387)
- Fix Display handling of hexadecimal escape characters (#7387)
- Fix Improved fade linearity with gamma correction

View File

@ -440,25 +440,21 @@
// -- SPI sensors ---------------------------------
//#define USE_SPI // Hardware SPI using GPIO12(MISO), GPIO13(MOSI) and GPIO14(CLK) in addition to two user selectable GPIOs(CS and DC)
#ifdef USE_SPI
// #ifndef USE_DISPLAY
// #define USE_DISPLAY // Add SPI Display support for 320x240 and 480x320 TFT
// #endif
// #define USE_DISPLAY_ILI9341 // [DisplayModel 4] Enable ILI9341 Tft 480x320 display (+19k code)
// #define USE_DISPLAY_EPAPER_29 // [DisplayModel 5] Enable e-paper 2.9 inch display (+19k code)
// #define USE_DISPLAY_EPAPER_42 // [DisplayModel 6] Enable e-paper 4.2 inch display
// #define USE_DISPLAY_ILI9488 // [DisplayModel 8] [I2cDriver38] (Touch)
// #define USE_DISPLAY_SSD1351 // [DisplayModel 9]
// #define USE_DISPLAY_RA8876 // [DisplayModel 10] [I2cDriver39] (Touch)
#define USE_NRF24 // add support for NRF24L01(+), (+2k3 of code)
#ifdef USE_DISPLAY
#undef USE_DISPLAY // Display drivers should be disabled
// #define USE_NRF24 // Add SPI support for NRF24L01(+) (+2k6 code)
#ifdef USE_NRF24
#define USE_MIBLE // BLE-bridge for some Mijia-BLE-sensors (+4k7 code)
#else
#ifndef USE_DISPLAY
#define USE_DISPLAY // Add SPI Display support for 320x240 and 480x320 TFT
#endif
#ifdef USE_NRF24
#define USE_MIBLE // BLE-bridge for some Mijia-BLE-sensors (+4k6 of code)
#endif // USE_NRF24
#define USE_DISPLAY_ILI9341 // [DisplayModel 4] Enable ILI9341 Tft 480x320 display (+19k code)
// #define USE_DISPLAY_EPAPER_29 // [DisplayModel 5] Enable e-paper 2.9 inch display (+19k code)
// #define USE_DISPLAY_EPAPER_42 // [DisplayModel 6] Enable e-paper 4.2 inch display
// #define USE_DISPLAY_ILI9488 // [DisplayModel 8] [I2cDriver38] (Touch)
// #define USE_DISPLAY_SSD1351 // [DisplayModel 9]
// #define USE_DISPLAY_RA8876 // [DisplayModel 10] [I2cDriver39] (Touch)
#endif // USE_NRF24
#endif // USE_SPI
// -- Serial sensors ------------------------------

View File

@ -1,14 +1,18 @@
/*
nrf24l01 support for Tasmota
Copyright (C) 2019 Christian Baars and Theo Arends
xdrv_33_nrf24l01.ino - nrf24l01 support for Tasmota
Copyright (C) 2020 Christian Baars and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@ -54,7 +58,7 @@ struct {
RF24 NRF24radio;
bool NRF24initRadio()
bool NRF24initRadio()
{
NRF24radio.begin(pin[GPIO_SPI_CS],pin[GPIO_SPI_DC]);
NRF24radio.powerUp();
@ -68,7 +72,7 @@ bool NRF24initRadio()
}
bool NRF24Detect(void)
{
{
if ((pin[GPIO_SPI_CS]<99) && (pin[GPIO_SPI_DC]<99)){
SPI.pins(SCK,MOSI,MISO,-1);
if(NRF24initRadio()){
@ -80,7 +84,7 @@ bool NRF24Detect(void)
}
return true;
}
}
}
return false;
}

View File

@ -1,14 +1,18 @@
/*
MI-BLE-sensors via nrf24l01 support for Tasmota
Copyright (C) 2019 Christian Baars and Theo Arends
xsns_61_Ml_BLE.ino - MI-BLE-sensors via nrf24l01 support for Tasmota
Copyright (C) 2020 Christian Baars and Theo Arends
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
@ -39,7 +43,7 @@
* MIBLE
* BLE-Sniffer/Bridge for MIJIA/XIAOMI Temperatur/Humidity-Sensor, Mi Flora
*
* Usage: Configure NRF24
* Usage: Configure NRF24
\*********************************************************************************************/
#define XSNS_61 61
@ -131,7 +135,7 @@ union MJ_HT_V1Packet_t { // related to the whole 32-byte-packet/buffer
uint8_t valueTen;
uint8_t effectiveDataLength; // 4
uint16_t temp;
uint16_t hum;
uint16_t hum;
} TH; // mode 0d
struct {
uint8_t padding[3];
@ -246,7 +250,7 @@ std::vector<mi_sensor_t> MIBLEsensors;
/********************************************************************************************/
bool MIBLEinitBLE(uint8_t _mode)
bool MIBLEinitBLE(uint8_t _mode)
{
NRF24radio.begin(pin[GPIO_SPI_CS],pin[GPIO_SPI_DC]);
NRF24radio.setAutoAck(false);
@ -280,7 +284,7 @@ void MIBLEhopChannel()
/**
* @brief Read out FIFO-buffer, swap buffer and whiten
*
*
* @return true - If something is in the buffer
* @return false - Nothing is in the buffer
*/
@ -335,10 +339,10 @@ void MIBLEshowBuffer(uint8_t (&buf)[32]){ // we use this only for the 32-byte-FI
/**
* @brief change lsfrBuffer content to "wire bit order"
*
*
* @param len Buffer lenght (could be hardcoded to 32)
*/
void MIBLEswapbuf(uint8_t len)
void MIBLEswapbuf(uint8_t len)
{
uint8_t* buf = (uint8_t*)&MIBLE.buffer;
while(len--) {
@ -358,7 +362,7 @@ void MIBLEswapbuf(uint8_t len)
/**
* @brief Whiten the packet buffer
*
*
* @param buf The packet buffer
* @param len Lenght of the packet buffer
* @param lfsr Start lsfr-byte
@ -385,11 +389,11 @@ void MIBLEwhiten(uint8_t *buf, uint8_t len, uint8_t lfsr)
/**
* @brief Set packet mode and fitting PDU-type of the NRF24L01
*
*
* @param _mode The internal packet mode number
*/
void MIBLEchangePacketModeTo(uint8_t _mode) {
switch(_mode){
switch(_mode){
case 0: // normal BLE advertisement
NRF24radio.openReadingPipe(0,0x6B7D9171); // advertisement address: 0x8E89BED6 (bit-reversed -> 0x6B7D9171)
break;
@ -407,7 +411,7 @@ void MIBLEchangePacketModeTo(uint8_t _mode) {
/**
* @brief Return the slot number of a known sensor or return create new sensor slot
*
*
* @param _serial BLE address of the sensor
* @param _type Type number of the sensor
* @return uint32_t Known or new slot in the sensors-vector
@ -442,7 +446,7 @@ uint32_t MIBLEgetSensorSlot(uint8_t (&_serial)[6], uint8_t _type){
_newSensor.MJ_HT_V1.temp=-1000.0f;
_newSensor.MJ_HT_V1.hum=-1.0f;
_newSensor.MJ_HT_V1.bat=0xff;
break;
break;
default:
break;
}
@ -659,7 +663,7 @@ void MIBLEShow(bool json)
ResponseAppend_P(PSTR(",\"Battery\":%u"), MIBLEsensors.at(i).MJ_HT_V1.bat);
}
ResponseAppend_P(PSTR("}"));
break;
break;
}
}
#ifdef USE_WEBSERVER
@ -684,7 +688,7 @@ void MIBLEShow(bool json)
WSContentSend_PD(HTTP_SNS_TEMP, MIBLESlaveFlora, temperature_flora, TempUnit());
}
if(MIBLEsensors.at(i).Flora.lux!=0xffff){ // this is the error code -> no temperature
WSContentSend_PD(HTTP_SNS_ILLUMINANCE, MIBLESlaveFlora, MIBLEsensors.at(i).Flora.lux);
WSContentSend_PD(HTTP_SNS_ILLUMINANCE, MIBLESlaveFlora, MIBLEsensors.at(i).Flora.lux);
}
if(MIBLEsensors.at(i).Flora.moisture!=-1000.0f){ // this is the error code -> no temperature
WSContentSend_PD(HTTP_SNS_MOISTURE, MIBLESlaveFlora, MIBLEsensors.at(i).Flora.moisture);
@ -716,7 +720,7 @@ void MIBLEShow(bool json)
}
}
}
}
}
#endif // USE_WEBSERVER
}