My smart home infrastructure contains several Xiaomi humidity/temperature and door sensors. I’ve used these sensors with the corresponding Xiaomi gateway. The gateway was connected with my BananaPi M2U and Pimatic. But my home is long and tall. One gateway does not cover all rooms, and therefore far sensors disappear periodically.
I’ve googled and found I can use Xiaomi sockets (Zigbee edition) like Zigbee routers. This socket is less expensive than a new gateway, and it has a smaller size. I’ve purchased tow sockets and used them for about a month. This socket has a big problem (from my point of view). It can go into the deep sleep mode and cannot forward data packets from sensors.
I’ve decided to use a CC2530 based development board and build my router. Aliexpress.com offers some variants. I’ve purchased two samples:
1. This board will be used in my Zigbee router.
2. This board will be used in Banana Pi as a coordinator instead of the CC2531 USB stick. This board has an external antenna, and I hope it will work better.
Firmware for Zigbee Coordinator
Z-Stack Home Automation SDK 1.2.2a comes with a precompiled firmware for CC2530 ZNP (Projects\zstack\ZNP\CC253x\bin\CC2530ZNP-SB.hex), but all my attempts to launch it on my samples failed. The gateway software xiaomi-zb2mqtt cannot detect and work with boards through a UART port.
P0_2 <=> RS232 RX
P0_3 <=> RS232 TX
P0_4 <=> RS232 CTS
P0_5 <=> RS232 RTS
The precompiled firmware uses hardware flow control wires. If you do not want to use it, you must connect P2_0 (CFG1) to GND.
So I’ve installed the trial version of IAR Embedded Workbench for 8051 (CC2530 is based on this processor architecture) and compiled the “SampleLight” demo application as a coordinator. Yes, of course, it may take some time. Below are my defined symbols:
SECURE=1 TC_LINKKEY_JOIN NV_INIT NV_RESTORE xHOLD_AUTO_START ZTOOL_P1 MT_TASK MT_APP_FUNC MT_SYS_FUNC MT_ZDO_FUNC HAL_LCD=FALSE xLCD_SUPPORTED=DEBUG MULTICAST_ENABLED=FALSE xZCL_READ xZCL_WRITE xZCL_REPORT xZCL_EZMODE xZCL_BASIC xZCL_IDENTIFY xZCL_ON_OFF xZCL_SCENES xZCL_GROUPS xZCL_LEVEL_CTRL xZCL_DIAGNOSTIC FEATURE_SYSTEM_STATS MT_UART_DEFAULT_BAUDRATE=HAL_UART_BR_115200 MT_UART_DEFAULT_OVERFLOW=FALSE HAL_LED=FALSE HAL_SPI=FALSE MT_UTIL_FUNC MT_AF_FUNC MT_SAPI_FUNC MT_SAPI_CB_FUNC MT_ZDO_CB_FUNC MT_ZDO_FUNC MT_SYS_FUNC OSAL_SAPI=FALSE SAPI_CB_FUNC=FALSE xHAL_UART_DMA_RX_MAX=128 MT_TASK_CUSTOM MT_ZDO_MGMT
How to use
Download and flash the firmware.
Baud rate: 115200
Hardware flow control: Disabled
P2_o pin state: ignored
P0_2 <=> UART (RS232) RX
P0_3 <=> UART (RS232) TX
UART port uses the DMA mode.
You may also connect to this port using ZTool.
Firmware for Zigbee Router
I’ve used the source code of the “SampleLight” demo application for my router’s firmware. I did some modifications and improvements:
- The pre-configured manufacturer code for Xiaomi devices.
- The pre-configured security key.
- LED blinking for some states:
- Short fast blinks (one per second) – the router is connecting to a network.
- Short long blinks (one per 4 seconds) – normal operations.
- Three short blinks – the router cannot send a report to a coordinator.
- The router sends the “genOnOff” report to a coordinator every minute (you may configure an interval using the corresponding ZCL command). It works like a keep-alive message.
- The debug version of the firmware additionally sends the “genBinaryValue” report for every neighbor in a network:
description – network and MAC address.
inactiveText – device role in a network.
presentValue – RSSI value of the last received packet (rxLqi).
relinquishDefault (optional) – path depth.
minimumOffTime (optional) – number of associated devices.
Defined symbols from the project:
SECURE=1 TC_LINKKEY_JOIN NV_INIT NV_RESTORE xHOLD_AUTO_START ZTOOL_P1 MT_TASK MT_APP_FUNC MT_SYS_FUNC xMT_ZDO_FUNC LCD_SUPPORTED=DEBUG xHAL_LCD=FALSE HAL_SPI=FALSE MULTICAST_ENABLED=FALSE ZCL_READ xZCL_WRITE ZCL_REPORT xZCL_EZMODE ZCL_BASIC xZCL_IDENTIFY ZCL_ON_OFF xZCL_SCENES xZCL_GROUPS xZCL_LEVEL_CTRL xZCL_DIAGNOSTIC ZCL_DISCOVER FEATURE_SYSTEM_STATS MT_UART_DEFAULT_BAUDRATE=HAL_UART_BR_115200 MT_UART_DEFAULT_OVERFLOW=FALSE HAL_LED=TRUE MT_UTIL_FUNC HAL_KEY=TRUE ZSTACK_MANUFACTURER_CODE=4447 BLINK_LEDS DIAG_INFO_REPORT
How to use
1. Download and flash the firmware.
2. Power off/on (restart) the router.
3. Permit joining to a network on your coordinator.
Added the “Aging” mode. The router forgets child devices that didn’t send any data for four hours. It helps when an end-device selects a new path to a coordinator.
1. Allows a router to use all possible channels (the old firmware was used the channel #11). But now, the router will take more time to connect to a coordinator.
2. A router may report link quality for all connected neighbors.
1. The previous version allowed joining for deleted devices.
2. СС2530 can be re-paired if you power on/power off it three times (power on, wait 2 seconds, power off, repeat this cycle three times).