Skip to content

Commit

Permalink
v3.7, Enable "HA-BLE"
Browse files Browse the repository at this point in the history
  • Loading branch information
pvvx committed Mar 5, 2022
1 parent d81e2eb commit 649242a
Show file tree
Hide file tree
Showing 24 changed files with 377 additions and 357 deletions.
Binary file removed ATC_v36c.bin
Binary file not shown.
Binary file added ATC_v37a.bin
Binary file not shown.
Binary file removed ATC_v37a_test.bin
Binary file not shown.
Binary file removed CGDK2_v36c.bin
Binary file not shown.
Binary file added CGDK2_v37a.bin
Binary file not shown.
Binary file removed CGDK2_v37a_test.bin
Binary file not shown.
Binary file removed CGG1_v36c.bin
Binary file not shown.
Binary file added CGG1_v37a.bin
Binary file not shown.
Binary file removed MHO_C401_v36c.bin
Binary file not shown.
Binary file added MHO_C401_v37a.bin
Binary file not shown.
Binary file removed MHO_v37a_test.bin
Binary file not shown.
15 changes: 7 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ The custom firmware can be flashed _via a modern browser_ and _over-the-air (OTA

* Extended battery life (over a year)
* Improved measurement accuracy and extended format in 0.01 units
* Full support in HA ['Passive BLE Monitor integration'](https://github.com/custom-components/ble_monitor)
* Full support in HA ['Passive BLE Monitor integration'](https://github.com/custom-components/ble_monitor) and 'HA BLE' format (DIY sensors)
* Supports [encrypted connections using **PIN-code**](https://github.com/pvvx/ATC_MiThermometer/issues/174#issuecomment-1003987084) and encrypted **bindkey** beacon
* Support BT5.0+ PHY, CSA1/CSA2
* **3 LCD Display Screens** (Looping): Temperature & Humidity & Comfort, Temperature & Battery Level, Clock
Expand Down Expand Up @@ -110,10 +110,10 @@ You can directly update/flash the firmware without downloading the binaries belo

**Custom Firmware Versions:**

* [LYWSD03MMC Custom Firmware Version 3.6](https://github.com/pvvx/ATC_MiThermometer/raw/master/ATC_v36c.bin) (HW: B1.4, B1.6, B1.7, B1.9, B2.0)
* [MHO-C401 Custom Firmware Version 3.6](https://github.com/pvvx/ATC_MiThermometer/raw/master/MHO_C401_v36c.bin) (manufacturer Xiaomi, not [Azarton](https://github.com/pvvx/ATC_MiThermometer/issues/114)!)
* [CGG1 Custom Firmware Version 3.6](https://github.com/pvvx/ATC_MiThermometer/raw/master/CGG1_v36c.bin) ([CGG1-M](https://github.com/pvvx/ATC_MiThermometer/issues/41#issuecomment-812803456))
* [CGDK2 Custom Firmware Version 3.6](https://github.com/pvvx/ATC_MiThermometer/raw/master/CGDK2_v36c.bin) ([CGDK2](https://pvvx.github.io/CGDK2))
* [LYWSD03MMC Custom Firmware Version 3.7](https://github.com/pvvx/ATC_MiThermometer/raw/master/ATC_v37a.bin) (HW: B1.4, B1.6, B1.7, B1.9, B2.0)
* [MHO-C401 Custom Firmware Version 3.7](https://github.com/pvvx/ATC_MiThermometer/raw/master/MHO_C401_v37a.bin) (manufacturer Xiaomi, not [Azarton](https://github.com/pvvx/ATC_MiThermometer/issues/114)!)
* [CGG1 Custom Firmware Version 3.7](https://github.com/pvvx/ATC_MiThermometer/raw/master/CGG1_v37a.bin) ([CGG1-M](https://github.com/pvvx/ATC_MiThermometer/issues/41#issuecomment-812803456))
* [CGDK2 Custom Firmware Version 3.7](https://github.com/pvvx/ATC_MiThermometer/raw/master/CGDK2_v37a.bin) ([CGDK2](https://pvvx.github.io/CGDK2))

**Original Manufacturer Firmware Version**

Expand Down Expand Up @@ -156,9 +156,8 @@ In case you want to go back to the original firmware, you can download them here
| 3.3 | Added autodetection for [LYWSD03MMC hardware versions B1.6 and B1.9](https://github.com/pvvx/ATC_MiThermometer/issues/125). For CGG1-M and MHO-C401 - autodetection of SHTV3 or SHT4x sensors |
| 3.4 | Correct Hardware Version Setting for [LYWSD03MMC B1.7](https://github.com/pvvx/ATC_MiThermometer/issues/145) |
| 3.5 | Correction of moisture readings for SHT4x sensors. [Rounding off sensor values on display.](https://github.com/pvvx/ATC_MiThermometer/issues/163). Saving HW string B2.0 on LYWSD03MMC. Eliminated [battery voltage noise](https://github.com/pvvx/ATC_MiThermometer/issues/180) in CGG1-M. CGG1 - correction of the battery charge display. Added CGDK2 and modified [(DIY) variant of CGDK2-2](https://pvvx.github.io/CGDK2/CGDK2-2/). |
| 3.6 | Additional parameters: Support BT5.0 PHY, Channel Selection Algorithm 2 |
| 3.6c | Correct RF-TX Power in suspend |
| 3.7 | Test version! : [Reed switch counter, Switch: opened/closed](https://github.com/pvvx/ATC_MiThermometer/issues/191) |
| 3.6 | Additional parameters: Support BT5.0 PHY, Channel Selection Algorithm 2, Correct RF-TX Power in suspend |
| 3.7 | Added [format 'HA BLE' (DIY sensors)](https://github.com/custom-components/ble_monitor/issues/548), reed switch operation mode: Switch and Count |

## Applications

Expand Down
4 changes: 2 additions & 2 deletions firmware.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{"version": 54,
"custom":["ATC_v36c.bin", "MHO_C401_v36c.bin", "CGG1_v36c.bin", "ATC_v36c.bin", "ATC_v36c.bin", "ATC_v36c.bin", "CGDK2_v36c.bin", "?"],
{"version": 55,
"custom":["ATC_v37a.bin", "MHO_C401_v37a.bin", "CGG1_v37a.bin", "ATC_v37a.bin", "ATC_v37a.bin", "ATC_v37a.bin", "CGDK2_v37a.bin", "?"],
"original":["Original_OTA_Xiaomi_LYWSD03MMC_v1.0.0_0130.bin","Original_OTA_Xiaomi_MHO_C401_v1.0.0_0010.bin","Original_OTA_CGG1_v1.0.1_0093.bin","Original_OTA_Xiaomi_LYWSD03MMC_v1.0.0_0130.bin","Original_OTA_Xiaomi_LYWSD03MMC_v1.0.0_0130.bin","Original_OTA_Xiaomi_LYWSD03MMC_v1.0.0_0130.bin", "Original_OTA_CGDK2_v1.1.1_0217.bin", "?"]}
6 changes: 3 additions & 3 deletions src/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ __attribute__((optimize("-Os"))) void test_config(void) {
else if (cfg.rf_tx_power > RF_POWER_P10p46dBm)
cfg.rf_tx_power = RF_POWER_P10p46dBm;
}
if (cfg.measure_interval == 0)
cfg.measure_interval = 1; // T = cfg.measure_interval * advertising_interval_ms (ms), Tmin = 1 * 1*62.5 = 62.5 ms / 1 * 160 * 62.5 = 10000 ms
if (cfg.measure_interval < 2)
cfg.measure_interval = 2; // T = cfg.measure_interval * advertising_interval_ms (ms), Tmin = 1 * 1*62.5 = 62.5 ms / 1 * 160 * 62.5 = 10000 ms
else if (cfg.measure_interval > 25) // max = (0x100000000-1.5*10000000*16)/(10000000*16) = 25.3435456
cfg.measure_interval = 25; // T = cfg.measure_interval * advertising_interval_ms (ms), Tmax = 25 * 160*62.5 = 250000 ms = 250 sec
if (cfg.flg.tx_measures)
Expand Down Expand Up @@ -250,7 +250,7 @@ _attribute_ram_code_ void WakeupLowPowerCb(int par) {
write_memo();
#endif
#if USE_MIHOME_BEACON
if ((cfg.flg.advertising_type & ADV_TYPE_MASK_REF) && cfg.flg2.mi_beacon)
if ((cfg.flg.advertising_type == ADV_TYPE_MI) && cfg.flg2.adv_crypto)
mi_beacon_summ();
#endif
}
Expand Down
10 changes: 4 additions & 6 deletions src/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ enum {
ADV_TYPE_ATC = 0,
ADV_TYPE_PVVX, // (default)
ADV_TYPE_MI,
ADV_TYPE_ALL
ADV_TYPE_HA_BLE
} ADV_TYPE_ENUM;

#define ADV_TYPE_MASK_REF 2 // advertising_type & ADV_TYPE_MASK_REF = ADV_TYPE_MI, ADV_TYPE_ALL -> refresh all beacon -> set_adv_data() in main cycle
#define ADV_TYPE_DEFAULT ADV_TYPE_PVVX

typedef struct __attribute__((packed)) _cfg_t {
struct __attribute__((packed)) {
uint8_t advertising_type : 2; // 0 - atc1441, 1 - Custom (pvvx), 2 - Mi, 3 - all
uint8_t advertising_type : 2; // 0 - atc1441, 1 - Custom (pvvx), 2 - Mi, 3 - HA_BLE
uint8_t comfort_smiley : 1;
uint8_t blinking_time_smile : 1; //(USE_CLOCK = 0 - smile, =1 time)
uint8_t temp_F_or_C : 1;
Expand Down Expand Up @@ -60,7 +58,7 @@ typedef struct __attribute__((packed)) _cfg_t {
* 6 = "^-^" sad
* 7 = "oOo" */
uint8_t smiley : 3; // 0..7
uint8_t mi_beacon : 1; // advertising uses crypto beacon
uint8_t adv_crypto : 1; // advertising uses crypto beacon
uint8_t adv_flags : 1; // advertising add flags
uint8_t bt5hgy : 1; // support BT5.0 Coded PHY
uint8_t chalg2 : 1; // ChannelSelectionAlgorithm 2
Expand All @@ -69,7 +67,7 @@ typedef struct __attribute__((packed)) _cfg_t {
int8_t temp_offset; // Set temp offset, -12,5 - +12,5 °C (-125..125)
int8_t humi_offset; // Set humi offset, -12,5 - +12,5 % (-125..125)
uint8_t advertising_interval; // multiply by 62.5 for value in ms (1..160, 62.5 ms .. 10 sec)
uint8_t measure_interval; // measure_interval = advertising_interval * x (1..10)
uint8_t measure_interval; // measure_interval = advertising_interval * x (2..25)
uint8_t rf_tx_power; // RF_POWER_N25p18dBm .. RF_POWER_P3p01dBm (130..191)
uint8_t connect_latency; // +1 x0.02 sec ( = connection interval), Tmin = 1*20 = 20 ms, Tmax = 256 * 20 = 5120 ms
uint8_t min_step_time_update_lcd; // x0.05 sec, 0.5..12.75 sec (10..255)
Expand Down
10 changes: 5 additions & 5 deletions src/app_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ extern "C" {

#define DEVICE_TYPE DEVICE_LYWSD03MMC // DEVICE_LYWSD03MMC or DEVICE_MHO_C401 or DEVICE_CGG1 or DEVICE_CGDK2

// Special DIY version - Voltage Logger:
// Temperature 0..36.00 = ADC pin PB7 input 0..3.6V, LYWSD03MMC pcb mark "B1"
// Humidity 0..36.00 = ADC pin PC4 input 0..3.6V, LYWSD03MMC pcb mark "P9"
// Set DIY_ADC_TO_TH 1
/* Special DIY version - Voltage Logger:
* Temperature 0..36.00 = ADC pin PB7 input 0..3.6V, LYWSD03MMC pcb mark "B1"
* Humidity 0..36.00 = ADC pin PC4 input 0..3.6V, LYWSD03MMC pcb mark "P9"
* Set DIY_ADC_TO_TH 1 */
#define DIY_ADC_TO_TH 0

#define BLE_SECURITY_ENABLE 1
Expand All @@ -28,7 +28,7 @@ extern "C" {
#define USE_TIME_ADJUST 1 // = 1 time correction enabled
#define USE_FLASH_MEMO 1 // = 1 flash logger enable
#define USE_WK_RDS_COUNTER 1 // = 1 wake up when the reed switch is triggered + pulse counter (Not completed! Only: CGDK2, LYWSD03MMC)
#define USE_HA_BLE_FORMAT 0 // Test Only! if USE_WK_RDS_COUNTER = 1, https://github.com/custom-components/ble_monitor/issues/548
#define USE_HA_BLE_FORMAT 1 // if USE_WK_RDS_COUNTER = 1, https://github.com/custom-components/ble_monitor/issues/548

#define USE_DEVICE_INFO_CHR_UUID 1 // = 1 enable Device Information Characteristics
#define USE_MIHOME_SERVICE 0 // = 1 MiHome service compatibility (missing in current version! Set = 0!)
Expand Down
Loading

0 comments on commit 649242a

Please sign in to comment.