Skip to content

Instantly share code, notes, and snippets.

@davidferguson
davidferguson / xiaomi_mi_2_2.1.1_0159_firmware_flashing
Created August 27, 2026 06:13
Flashing Xiaomi Mi 2 temperature sensors with firmware 2.1.1_0159
## Background
The Xiaomi Mi 2 temperature sensors are very cheap (less than £5 with battery included) temperature sensors that are designed to work with the Xiaomi Home IoT system. However, clever people have written custom firmware allowing them to be used outside of this, on Bluetooth BLE or Zigbee.
However starting in mid 2025, a new firmware was flashed by default on the Mi 2 sensors that means that in order to flash the custom firmware, you first have to obtain the device ID, token and key. You can do this by connecting it to Xiaomi Home, using a tool to extract the keys, and then not using Xiaomi Home again.
## Checking if you have firmware 2.1.1_0159
1. Go to https://pvvx.github.io/ATC_MiThermometer/TelinkMiFlasher.html in Chrome
var websocket
function doConnect()
{
websocket = new WebSocket('ws://localhost:8000/')
websocket.onopen = function(evt) { onOpen(evt) }
websocket.onclose = function(evt) { onClose(evt) }
websocket.onmessage = function(evt) { onMessage(evt) }
websocket.onerror = function(evt) { onError(evt) }
}
@davidferguson
davidferguson / server.py
Created September 10, 2016 21:51
Python bottle server for @all_about_code's Blockly EduPython interface
from bottle import *
app = Bottle()
@app.hook('after_request')
def enable_cors():
print("after_request hook")
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, PUT, OPTIONS'
response.headers['Access-Control-Allow-Headers'] = 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
@davidferguson
davidferguson / toolbox.xml
Created September 10, 2016 20:54
Blockly Deafult Blocks Toolbox
<xml id="toolbox" style="display: none">
<category name="{catLogic}" colour="210">
<block type="controls_if"></block>
<block type="logic_compare"></block>
<block type="logic_operation"></block>
<block type="logic_negate"></block>
<block type="logic_boolean"></block>
<block type="logic_null"></block>
<block type="logic_ternary"></block>
</category>