How atc1441/atc_mithermometer works
Project Type and Purpose
• The repository provides custom firmware (found in the “ATC_Thermometer” folder) for a Xiaomi thermometer that uses a Telink TLSR8251 MCU. It includes mechanisms for both OTA flashing via a custom Web Flasher tool and direct USB-to-UART flashing through a Python tool.
• The README highlights two primary functions: flashing the custom firmware (or reverting to stock) and building the firmware using a provided Makefile. In addition, it explains how the firmware integrates with third-party systems such as ESPHome, OpenMQTTGateway, and Home Assistant.
• The existence of auxiliary directories (like “contrib/nodejs” and “contrib/python”) further indicates that external scripts are provided to scan or interface with the thermometer.
File Structure
• Top-level files: You have two binary firmware images (ATC_Exploit.bin, ATC_Thermometer.bin), flashing tools (ATCtelink.py, ATCtelink_one_way.py, flash.py), and build-related files (Makefile, project.mk).
• The “ATC_Thermometer” folder contains source files (e.g., main.c, app.c, battery.c, ble.c, flash.c, lcd.c, sensor.c, etc.) and header files that show a modular design: each module (battery, BLE, I2C, command parser) is separated into its own C file.
• The “.github” folder with workflows indicates that CI/CD for building and testing may be in place.
• The “contrib” folder includes additional tooling with separate folders for nodejs and python implementations of scanner utilities.
Identifying the Main Components
• Embedded Firmware:
– The “ATC_Thermometer” core module that integrates various functionalities such as:
▪ Application Logic (app.c / app_att.c)
▪ Hardware interfacing: battery management (battery.c), sensor readout (sensor.c), and LCD display (lcd.c)
▪ Communication interfaces: BLE module (ble.c) and I2C communication (i2c.c)
▪ Firmware management: flash operations (flash.c) and command parsing (cmd_parser.c)
– Build configuration files (Makefile, project.mk) providing instructions to compile the firmware.
• Flashing and Upgrade Mechanisms:
– OTA Flashing: The README details a Web-based flasher (hosted externally at atc1441.github.io/TelinkFlasher.html) allowing OTA firmware upgrades.
– USB-to-UART Flashing: Tools like ATCtelink.py facilitate programming/unbricking the device via USB to serial converters.
• Auxiliary Integration Layers:
– External tools provided in “contrib/python” and “contrib/nodejs” for scanning the device and possibly handling advertisement data.
– Integration with third-party ecosystems (ESPHome and OpenMQTTGateway) is supported by the firmware’s advertising structure.
Specific Elements
▪ The compilation flow (source files → firmware binary).
▪ The flashing/update process from the flashing tools to the device.
▪ Data churn from sensor modules feeding into the BLE advertising, then to integrating systems like ESPHome.
▪ Another for external utilities (OTA, USB flasher),
▪ And a third for integration points (MQTT, ESPHome).