updates
This commit is contained in:
parent
269c6054eb
commit
419f70d8d2
|
@ -0,0 +1,41 @@
|
||||||
|
|
||||||
|
|
||||||
|
esphome:
|
||||||
|
name: arbeitszimmer-oben-ble-tracker
|
||||||
|
|
||||||
|
esp32:
|
||||||
|
board: m5stack-atom
|
||||||
|
framework:
|
||||||
|
type: arduino
|
||||||
|
|
||||||
|
logger:
|
||||||
|
|
||||||
|
ota:
|
||||||
|
password: !secret ota_password
|
||||||
|
|
||||||
|
wifi:
|
||||||
|
ssid: WLAN
|
||||||
|
password: !secret wifi_password
|
||||||
|
|
||||||
|
mqtt:
|
||||||
|
broker: homeassistant.fritz.box
|
||||||
|
username: !secret mqtt_ble_username
|
||||||
|
password: !secret mqtt_ble_password
|
||||||
|
discovery: false
|
||||||
|
|
||||||
|
esp32_ble_tracker:
|
||||||
|
scan_parameters:
|
||||||
|
interval: 1.2s
|
||||||
|
window: 500ms
|
||||||
|
active: false
|
||||||
|
on_ble_advertise:
|
||||||
|
- then:
|
||||||
|
- lambda: |-
|
||||||
|
auto build_json = [&](JsonObject obj) {
|
||||||
|
obj["rssi"] = x.get_rssi();
|
||||||
|
obj["address"] = x.address_str();
|
||||||
|
obj["address_uint64"] = x.address_uint64();
|
||||||
|
if(x.get_tx_powers().size() > 0)
|
||||||
|
obj["tx_power"] = x.get_tx_powers()[0];
|
||||||
|
};
|
||||||
|
global_mqtt_client->publish_json("my_btmonitor/raw_measurements/az_oben", build_json);
|
|
@ -111,13 +111,13 @@ packages:
|
||||||
name: "ventil-sprinkler-westen"
|
name: "ventil-sprinkler-westen"
|
||||||
dev_addr: 0x1
|
dev_addr: 0x1
|
||||||
register_addr: 0x03
|
register_addr: 0x03
|
||||||
#relay04: !include
|
relay04: !include
|
||||||
# file: "modbus_relay.yaml"
|
file: "modbus_relay.yaml"
|
||||||
# vars:
|
vars:
|
||||||
# cid: relayboard32
|
cid: relayboard32
|
||||||
# name: "ventil-gartenhaus-kein-rohr-angeschlossen"
|
name: "ventil-giessanlage-vorne"
|
||||||
# dev_addr: 0x1
|
dev_addr: 0x1
|
||||||
# register_addr: 0x04
|
register_addr: 0x04
|
||||||
relay05: !include
|
relay05: !include
|
||||||
file: "modbus_relay.yaml"
|
file: "modbus_relay.yaml"
|
||||||
vars:
|
vars:
|
||||||
|
@ -125,13 +125,13 @@ packages:
|
||||||
name: "ventil-sprinkler-sud"
|
name: "ventil-sprinkler-sud"
|
||||||
dev_addr: 0x1
|
dev_addr: 0x1
|
||||||
register_addr: 0x05
|
register_addr: 0x05
|
||||||
#relay06: !include
|
relay06: !include
|
||||||
# file: "modbus_relay.yaml"
|
file: "modbus_relay.yaml"
|
||||||
# vars:
|
vars:
|
||||||
# cid: relayboard32
|
cid: relayboard32
|
||||||
# name: "ventil-gartenhaus-kein-ventil-angeschlossen"
|
name: "ventil-beet-sued"
|
||||||
# dev_addr: 0x1
|
dev_addr: 0x1
|
||||||
# register_addr: 0x06
|
register_addr: 0x06
|
||||||
relay07: !include
|
relay07: !include
|
||||||
file: "modbus_relay.yaml"
|
file: "modbus_relay.yaml"
|
||||||
vars:
|
vars:
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
|
|
||||||
esphome:
|
esphome:
|
||||||
name: gartenhaus-taster-input
|
name: gartenhaus-taster-input
|
||||||
includes:
|
|
||||||
- my_btmonitor.h
|
|
||||||
libraries:
|
|
||||||
- mbedtls
|
|
||||||
|
|
||||||
esp32:
|
esp32:
|
||||||
board: esp32-poe
|
board: esp32-poe
|
||||||
|
@ -22,7 +18,6 @@ api:
|
||||||
ota:
|
ota:
|
||||||
password: !secret ota_password
|
password: !secret ota_password
|
||||||
|
|
||||||
|
|
||||||
ethernet:
|
ethernet:
|
||||||
type: LAN8720
|
type: LAN8720
|
||||||
mdc_pin: GPIO23
|
mdc_pin: GPIO23
|
||||||
|
@ -158,8 +153,6 @@ binary_sensor:
|
||||||
device_class: LIGHT
|
device_class: LIGHT
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
mqtt:
|
mqtt:
|
||||||
broker: homeassistant.fritz.box
|
broker: homeassistant.fritz.box
|
||||||
username: !secret mqtt_ble_username
|
username: !secret mqtt_ble_username
|
||||||
|
@ -175,17 +168,18 @@ esp32_ble_tracker:
|
||||||
on_ble_advertise:
|
on_ble_advertise:
|
||||||
- then:
|
- then:
|
||||||
- lambda: |-
|
- lambda: |-
|
||||||
const char * detected_device_name = ble_device_name(x.address());
|
auto build_json = [&](JsonObject obj) {
|
||||||
if(detected_device_name != nullptr) {
|
obj["rssi"] = x.get_rssi();
|
||||||
auto build_json = [&](JsonObject obj) {
|
obj["address"] = x.address_str();
|
||||||
obj["id"] = detected_device_name;
|
obj["address_uint64"] = x.address_uint64();
|
||||||
obj["rssi"] = x.get_rssi();
|
if(x.get_tx_powers().size() > 0)
|
||||||
if(x.get_tx_powers().size() > 0)
|
obj["tx_power"] = x.get_tx_powers()[0];
|
||||||
obj["tx_power"] = x.get_tx_powers()[0];
|
};
|
||||||
};
|
global_mqtt_client->publish_json("my_btmonitor/raw_measurements/garten", build_json);
|
||||||
global_mqtt_client->publish_json(std::string("my_btmonitor/devices/") + detected_device_name + "/garten",
|
|
||||||
build_json);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#on_multi_click:
|
#on_multi_click:
|
||||||
|
|
|
@ -91,7 +91,7 @@ light:
|
||||||
id: gartenhaus_wandlicht
|
id: gartenhaus_wandlicht
|
||||||
name: Gartenhaus Wandlicht
|
name: Gartenhaus Wandlicht
|
||||||
pin: 3
|
pin: 3
|
||||||
num_leds: 305
|
num_leds: 306
|
||||||
is_rgbw: true
|
is_rgbw: true
|
||||||
rmt_channel: 0
|
rmt_channel: 0
|
||||||
effects:
|
effects:
|
||||||
|
|
145
m5stackfire.yaml
145
m5stackfire.yaml
|
@ -1,17 +1,24 @@
|
||||||
esphome:
|
esphome:
|
||||||
name: m5stackfire
|
name: m5stackfire
|
||||||
includes:
|
|
||||||
- my_btmonitor.h
|
external_components:
|
||||||
libraries:
|
- source:
|
||||||
- mbedtls
|
type: git
|
||||||
platformio_options:
|
url: https://github.com/ssieb/custom_components
|
||||||
board_upload.flash_size: 16MB
|
components: [ip5306]
|
||||||
board_build.partitions: "../../../m5stackfire_partition.csv"
|
- source:
|
||||||
|
type: local
|
||||||
|
path: ./my_components
|
||||||
|
|
||||||
esp32:
|
esp32:
|
||||||
board: m5stack-fire
|
board: m5stack-fire
|
||||||
|
flash_size: 16MB
|
||||||
|
#framework:
|
||||||
|
# type: arduino
|
||||||
framework:
|
framework:
|
||||||
type: arduino
|
type: esp-idf
|
||||||
|
|
||||||
|
psram:
|
||||||
|
|
||||||
substitutions:
|
substitutions:
|
||||||
friendly_name: "M5StackFire"
|
friendly_name: "M5StackFire"
|
||||||
|
@ -23,6 +30,7 @@ api:
|
||||||
- service: mhz19_calibrate_zero
|
- service: mhz19_calibrate_zero
|
||||||
then:
|
then:
|
||||||
- mhz19.calibrate_zero: my_mhz19
|
- mhz19.calibrate_zero: my_mhz19
|
||||||
|
|
||||||
wifi:
|
wifi:
|
||||||
ssid: WLAN
|
ssid: WLAN
|
||||||
password: !secret wifi_password
|
password: !secret wifi_password
|
||||||
|
@ -33,11 +41,6 @@ ota:
|
||||||
logger:
|
logger:
|
||||||
|
|
||||||
# Power Management
|
# Power Management
|
||||||
external_components:
|
|
||||||
- source:
|
|
||||||
type: git
|
|
||||||
url: https://github.com/ssieb/custom_components
|
|
||||||
components: [ip5306]
|
|
||||||
|
|
||||||
ip5306:
|
ip5306:
|
||||||
battery_level:
|
battery_level:
|
||||||
|
@ -80,7 +83,7 @@ switch:
|
||||||
pin: 32
|
pin: 32
|
||||||
name: "Backlight"
|
name: "Backlight"
|
||||||
id: backlight
|
id: backlight
|
||||||
restore_mode: ALWAYS_ON
|
restore_mode: ALWAYS_OFF
|
||||||
|
|
||||||
light:
|
light:
|
||||||
#- platform: monochromatic # backlight
|
#- platform: monochromatic # backlight
|
||||||
|
@ -111,42 +114,44 @@ light:
|
||||||
from: 5
|
from: 5
|
||||||
to: 9
|
to: 9
|
||||||
|
|
||||||
|
|
||||||
i2c:
|
i2c:
|
||||||
sda: 21
|
sda: 21
|
||||||
scl: 22
|
scl: 22
|
||||||
scan: True
|
scan: True
|
||||||
|
|
||||||
# Display
|
# Display
|
||||||
#spi:
|
spi:
|
||||||
# clk_pin: 18
|
clk_pin: 18
|
||||||
# mosi_pin: 23
|
mosi_pin: 23
|
||||||
# miso_pin: 19
|
miso_pin: 19
|
||||||
#
|
|
||||||
#font:
|
font:
|
||||||
# - file: "gfonts://Roboto"
|
- file: "gfonts://Roboto"
|
||||||
# id: roboto
|
id: roboto
|
||||||
# size: 18
|
size: 18
|
||||||
#
|
|
||||||
#image:
|
image:
|
||||||
# - file: m5stack_display.png
|
- file: m5stack_display.png
|
||||||
# id: img_background
|
id: img_background
|
||||||
# type: RGB24
|
type: RGB24
|
||||||
#
|
|
||||||
#
|
|
||||||
#display:
|
display:
|
||||||
# - platform: ili9xxx
|
- platform: ili9xxx
|
||||||
# model: M5STACK
|
model: M5STACK
|
||||||
# cs_pin: 14
|
spi_mode: MODE3
|
||||||
# dc_pin: 27
|
data_rate: 20MHz
|
||||||
# reset_pin: 33
|
cs_pin: 14
|
||||||
# id: my_display
|
dc_pin: 27
|
||||||
# lambda: |-
|
reset_pin: 33
|
||||||
# it.image(0, 0, id(img_background));
|
update_interval: 20s
|
||||||
# it.printf(240, 67, id(roboto), Color(255, 255, 255), TextAlign::TOP_CENTER, "%.0f ppm", id(co2value).state );
|
id: my_display
|
||||||
# it.printf(240, 125, id(roboto), Color(255, 255, 255), TextAlign::TOP_CENTER, "%.1f °C", id(co2temp).state );
|
lambda: |-
|
||||||
# it.printf(240, 184, id(roboto), Color(255, 255, 255), TextAlign::TOP_CENTER, "%.1f %%", id(m5stackfire_dht22_humidity).state );
|
it.image(0, 0, id(img_background));
|
||||||
#
|
it.printf(240, 67, id(roboto), Color(255, 255, 255), TextAlign::TOP_CENTER, "%.0f ppm", id(co2value).state );
|
||||||
|
it.printf(240, 125, id(roboto), Color(255, 255, 255), TextAlign::TOP_CENTER, "%.1f °C", id(co2temp).state );
|
||||||
|
it.printf(240, 184, id(roboto), Color(255, 255, 255), TextAlign::TOP_CENTER, "%.1f %%", id(m5stackfire_dht22_humidity).state );
|
||||||
|
|
||||||
|
|
||||||
uart:
|
uart:
|
||||||
id: uart_co2
|
id: uart_co2
|
||||||
|
@ -175,30 +180,32 @@ sensor:
|
||||||
id: m5stackfire_dht22_humidity
|
id: m5stackfire_dht22_humidity
|
||||||
name: "DHT22 humidity"
|
name: "DHT22 humidity"
|
||||||
|
|
||||||
mqtt:
|
# BTLE doesn't work - not enough RAM
|
||||||
broker: homeassistant.fritz.box
|
# PSRAM isn't usable because chip is wired to same pins as UART PORT-C :(
|
||||||
username: !secret mqtt_ble_username
|
|
||||||
password: !secret mqtt_ble_password
|
|
||||||
discovery: false
|
|
||||||
|
|
||||||
esp32_ble_tracker:
|
|
||||||
scan_parameters:
|
|
||||||
interval: 1.2s
|
|
||||||
window: 500ms
|
|
||||||
active: false
|
|
||||||
on_ble_advertise:
|
|
||||||
- then:
|
|
||||||
- lambda: |-
|
|
||||||
const char * detected_device_name = ble_device_name(x.address());
|
|
||||||
if(detected_device_name != nullptr) {
|
|
||||||
auto build_json = [&](JsonObject obj) {
|
|
||||||
obj["id"] = detected_device_name;
|
|
||||||
obj["rssi"] = x.get_rssi();
|
|
||||||
if(x.get_tx_powers().size() > 0)
|
|
||||||
obj["tx_power"] = x.get_tx_powers()[0];
|
|
||||||
};
|
|
||||||
global_mqtt_client->publish_json(std::string("my_btmonitor/devices/") + detected_device_name + "/az_oben",
|
|
||||||
build_json);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
#
|
||||||
|
#mqtt:
|
||||||
|
# broker: homeassistant.fritz.box
|
||||||
|
# username: !secret mqtt_ble_username
|
||||||
|
# password: !secret mqtt_ble_password
|
||||||
|
# discovery: false
|
||||||
|
#
|
||||||
|
#nimble_tracker:
|
||||||
|
|
||||||
|
#esp32_ble_tracker:
|
||||||
|
# scan_parameters:
|
||||||
|
# interval: 1.2s
|
||||||
|
# window: 500ms
|
||||||
|
# active: false
|
||||||
|
# on_ble_advertise:
|
||||||
|
# - then:
|
||||||
|
# - lambda: |-
|
||||||
|
# auto build_json = [&](JsonObject obj) {
|
||||||
|
# obj["rssi"] = x.get_rssi();
|
||||||
|
# obj["address"] = x.address_str();
|
||||||
|
# obj["address_uint64"] = x.address_uint64();
|
||||||
|
# if(x.get_tx_powers().size() > 0)
|
||||||
|
# obj["tx_power"] = x.get_tx_powers()[0];
|
||||||
|
# };
|
||||||
|
# global_mqtt_client->publish_json("my_btmonitor/raw_measurements/az_oben", build_json);
|
||||||
|
#
|
|
@ -1,69 +0,0 @@
|
||||||
#pragma once
|
|
||||||
|
|
||||||
#include "mbedtls/aes.h"
|
|
||||||
|
|
||||||
int bt_encrypt_be(const uint8_t *key, const uint8_t *plaintext, uint8_t *enc_data) {
|
|
||||||
mbedtls_aes_context ctx;
|
|
||||||
mbedtls_aes_init(&ctx);
|
|
||||||
|
|
||||||
if (mbedtls_aes_setkey_enc(&ctx, key, 128) != 0) {
|
|
||||||
mbedtls_aes_free(&ctx);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mbedtls_aes_crypt_ecb(&ctx, MBEDTLS_AES_ENCRYPT, plaintext, enc_data) != 0) {
|
|
||||||
mbedtls_aes_free(&ctx);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
mbedtls_aes_free(&ctx);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct encryption_block {
|
|
||||||
uint8_t key[16];
|
|
||||||
uint8_t plain_text[16];
|
|
||||||
uint8_t cipher_text[16];
|
|
||||||
};
|
|
||||||
|
|
||||||
inline bool ble_ll_resolv_rpa(const uint8_t *rpa, const uint8_t *irk) {
|
|
||||||
struct encryption_block ecb;
|
|
||||||
|
|
||||||
auto irk32 = (const uint32_t *)irk;
|
|
||||||
auto key32 = (uint32_t *)&ecb.key[0];
|
|
||||||
auto pt32 = (uint32_t *)&ecb.plain_text[0];
|
|
||||||
|
|
||||||
key32[0] = irk32[0];
|
|
||||||
key32[1] = irk32[1];
|
|
||||||
key32[2] = irk32[2];
|
|
||||||
key32[3] = irk32[3];
|
|
||||||
|
|
||||||
pt32[0] = 0;
|
|
||||||
pt32[1] = 0;
|
|
||||||
pt32[2] = 0;
|
|
||||||
pt32[3] = 0;
|
|
||||||
|
|
||||||
ecb.plain_text[15] = rpa[5 - 3];
|
|
||||||
ecb.plain_text[14] = rpa[5 - 4];
|
|
||||||
ecb.plain_text[13] = rpa[5 - 5];
|
|
||||||
|
|
||||||
bt_encrypt_be(ecb.key, ecb.plain_text, ecb.cipher_text);
|
|
||||||
|
|
||||||
if (ecb.cipher_text[15] != rpa[5 - 0] || ecb.cipher_text[14] != rpa[5 - 1] || ecb.cipher_text[13] != rpa[5 - 2]) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
static const char * ble_device_name(const uint8_t * rpa) {
|
|
||||||
static constexpr uint8_t irk_martins_apple_watch[] = {0xaa, 0x67, 0x54, 0x2b, 0x82, 0xc0, 0xe0, 0x5d, 0x65, 0xc2, 0x7f, 0xb7, 0xe3, 0x13, 0xab, 0xa5};
|
|
||||||
static constexpr uint8_t irk_martins_iphone[] = {0x84, 0x0e, 0x38, 0x92, 0x64, 0x4c, 0x1e, 0xbd, 0x15, 0x94, 0xa9, 0x06, 0x9c, 0x14, 0xce, 0x0d};
|
|
||||||
if(ble_ll_resolv_rpa(rpa, irk_martins_apple_watch)) {
|
|
||||||
return "martins_apple_watch";
|
|
||||||
}
|
|
||||||
else if(ble_ll_resolv_rpa(rpa, irk_martins_iphone)) {
|
|
||||||
return "martins_iphone";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue