diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 5acc552..39efc54 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -162,8 +162,12 @@ jobs: run: 'echo -e "wifi_ssid: ssid\nwifi_password: password\nmqtt_host: host\nmqtt_username: username\nmqtt_password: password" > secrets.yaml' - run: | esphome -s external_components_source components config esp32-example.yaml + esphome -s external_components_source components config esp32-example-debug.yaml + esphome -s external_components_source components config esp32-example-faker.yaml - run: | esphome -s external_components_source components config esp8266-example.yaml + esphome -s external_components_source components config esp8266-example-debug.yaml + esphome -s external_components_source components config esp8266-example-faker.yaml esphome-compile: runs-on: ubuntu-latest @@ -201,6 +205,6 @@ jobs: shell: bash run: 'echo -e "wifi_ssid: ssid\nwifi_password: password\nmqtt_host: host\nmqtt_username: username\nmqtt_password: password" > secrets.yaml' - run: | - esphome -s external_components_source components compile esp32-example.yaml + esphome -s external_components_source components compile esp32-example-faker.yaml - run: | - esphome -s external_components_source components compile esp8266-example.yaml + esphome -s external_components_source components compile esp8266-example-faker.yaml diff --git a/components/jbd_bms/jbd_bms.cpp b/components/jbd_bms/jbd_bms.cpp index b65ef63..580e4ec 100644 --- a/components/jbd_bms/jbd_bms.cpp +++ b/components/jbd_bms/jbd_bms.cpp @@ -64,7 +64,26 @@ void JbdBms::loop() { } } -void JbdBms::update() { this->send_command_(JBD_CMD_READ, JBD_CMD_HWINFO); } +void JbdBms::update() { + this->send_command_(JBD_CMD_READ, JBD_CMD_HWINFO); + + if (this->enable_fake_traffic_) { + // Start: 0xDD 0x03 0x00 0x1D + this->on_jbd_bms_data_(JBD_CMD_HWINFO, {0x06, 0x18, 0x00, 0x00, 0x01, 0xF2, 0x01, 0xF4, 0x00, 0x00, 0x2C, + 0x7C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x64, 0x03, 0x04, + 0x03, 0x0B, 0x8B, 0x0B, 0x8A, 0x0B, 0x84, 0xFA, 0x8D, 0x77}); + // End: 0xFA 0x8D 0x77 + + // Start: 0xDD 0x04 0x00 0x08 + this->on_jbd_bms_data_(JBD_CMD_CELLINFO, {0x0F, 0x45, 0x0F, 0x3D, 0x0F, 0x37, 0x0F, 0x3D, 0xFE, 0xC6, 0x77}); + // End: 0xFE 0xC6 0x77 + + // Start: 0xDD 0x05 0x00 0x19 + this->on_jbd_bms_data_(JBD_CMD_HWVER, {0x4A, 0x42, 0x44, 0x2D, 0x53, 0x50, 0x30, 0x34, 0x53, 0x30, 0x33, 0x34, 0x2D, + 0x4C, 0x34, 0x53, 0x2D, 0x32, 0x30, 0x30, 0x41, 0x2D, 0x42, 0x2D, 0x55}); + // End: 0xFA, 0x08, 0x77 + } +} bool JbdBms::parse_jbd_bms_byte_(uint8_t byte) { size_t at = this->rx_buffer_.size(); @@ -289,6 +308,8 @@ void JbdBms::on_hardware_version_data_(const std::vector &data) { void JbdBms::dump_config() { // NOLINT(google-readability-function-size,readability-function-size) ESP_LOGCONFIG(TAG, "JbdBms:"); + ESP_LOGCONFIG(TAG, " RX timeout: %d ms", this->rx_timeout_); + ESP_LOGCONFIG(TAG, " Fake traffic enabled: %s", YESNO(this->enable_fake_traffic_)); LOG_SENSOR("", "Total voltage", this->total_voltage_sensor_); LOG_SENSOR("", "Battery strings", this->battery_strings_sensor_); @@ -344,7 +365,6 @@ void JbdBms::dump_config() { // NOLINT(google-readability-function-size,readabi LOG_SENSOR("", "Cell Voltage 30", this->cells_[29].cell_voltage_sensor_); LOG_SENSOR("", "Cell Voltage 31", this->cells_[30].cell_voltage_sensor_); LOG_SENSOR("", "Cell Voltage 32", this->cells_[31].cell_voltage_sensor_); - ESP_LOGCONFIG(TAG, " RX timeout: %d ms", this->rx_timeout_); } float JbdBms::get_setup_priority() const { // After UART bus diff --git a/esp32-example-debug.yaml b/esp32-example-debug.yaml new file mode 100644 index 0000000..e0b7b59 --- /dev/null +++ b/esp32-example-debug.yaml @@ -0,0 +1,12 @@ +<<: !include esp32-example.yaml + +logger: + level: DEBUG + +uart: + id: uart0 + baud_rate: 9600 + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + debug: + direction: BOTH diff --git a/esp32-example-faker.yaml b/esp32-example-faker.yaml new file mode 100644 index 0000000..6374c7e --- /dev/null +++ b/esp32-example-faker.yaml @@ -0,0 +1,5 @@ +<<: !include esp32-example-debug.yaml + +jbd_bms: + rx_timeout: ${rx_timeout} + enable_fake_traffic: true diff --git a/esp32-example.yaml b/esp32-example.yaml index 7ca9d9d..ea03adf 100644 --- a/esp32-example.yaml +++ b/esp32-example.yaml @@ -4,6 +4,7 @@ substitutions: external_components_source: github://syssi/esphome-jbd-bms@main tx_pin: GPIO16 rx_pin: GPIO17 + rx_timeout: 150ms esphome: name: ${name} @@ -34,11 +35,9 @@ uart: baud_rate: 9600 tx_pin: ${tx_pin} rx_pin: ${rx_pin} - debug: - direction: BOTH jbd_bms: - rx_timeout: 150ms + rx_timeout: ${rx_timeout} binary_sensor: - platform: jbd_bms diff --git a/esp8266-example-debug.yaml b/esp8266-example-debug.yaml new file mode 100644 index 0000000..13a3db1 --- /dev/null +++ b/esp8266-example-debug.yaml @@ -0,0 +1,12 @@ +<<: !include esp8266-example.yaml + +logger: + level: DEBUG + +uart: + id: uart0 + baud_rate: 9600 + tx_pin: ${tx_pin} + rx_pin: ${rx_pin} + debug: + direction: BOTH diff --git a/esp8266-example-faker.yaml b/esp8266-example-faker.yaml new file mode 100644 index 0000000..e01c973 --- /dev/null +++ b/esp8266-example-faker.yaml @@ -0,0 +1,5 @@ +<<: !include esp8266-example-debug.yaml + +jbd_bms: + rx_timeout: ${rx_timeout} + enable_fake_traffic: true diff --git a/esp8266-example.yaml b/esp8266-example.yaml index 5eacacd..10b5beb 100644 --- a/esp8266-example.yaml +++ b/esp8266-example.yaml @@ -4,6 +4,7 @@ substitutions: external_components_source: github://syssi/esphome-jbd-bms@main tx_pin: GPIO4 rx_pin: GPIO5 + rx_timeout: 150ms esphome: name: ${name} @@ -31,11 +32,9 @@ uart: baud_rate: 9600 tx_pin: ${tx_pin} rx_pin: ${rx_pin} - debug: - direction: BOTH jbd_bms: - rx_timeout: 150ms + rx_timeout: ${rx_timeout} binary_sensor: - platform: jbd_bms diff --git a/test-esp32.sh b/test-esp32.sh index 9e28db1..5607a3e 100755 --- a/test-esp32.sh +++ b/test-esp32.sh @@ -1,3 +1,3 @@ #!/bin/bash -esphome -s external_components_source components ${1:-run} esp32-example.yaml +esphome -s external_components_source components ${1:-run} ${2:-esp32-example-faker.yaml} diff --git a/test-esp8266.sh b/test-esp8266.sh index 4eb755b..332ef1a 100755 --- a/test-esp8266.sh +++ b/test-esp8266.sh @@ -1,3 +1,3 @@ #!/bin/bash -esphome -s external_components_source components ${1:-run} ${2:-esp8266-example.yaml} +esphome -s external_components_source components ${1:-run} ${2:-esp8266-example-faker.yaml}