So far my experience with the Tradfri Hub has been reasonable, but I am cursed with a constant urge to fiddle with things and add more functionality. Enter zigbee2mqtt - "It bridges events and allows you to control your Zigbee devices via MQTT. In this way you can integrate your Zigbee devices with whatever smart home infrastructure you are using."
zigbee2mqtt is compatible with the Tradfri range and the Xiaomi sensors, and a bunch of other zigbee devices. It utilises a USB dongle, the CC2531 to handle the RF side. Clones are cheap and readily available.
zigbee2mqtt requires you to flash the USB dongle with a different firmware. For whatever reason most guides assume you'll be using a CC Debugger to do this, however it's an added expense and isn't necessary - You can also use an Arduino or Raspberry Pi to flash the firmware.
I opted to use a Raspberry Pi as I already had one on the bench. Click read more to learn how to use the Pi to flash the Dongle
CC2531 Dongle |
Required Items
- Raspberry Pi, Power Supply,
- CC2531 Dongle
- CC2531 Cable Adapter
- 4 Male to Female Jumper Wires
Assumptions
It's assumed you already have an Operating System running on the Raspberry Pi and know your way around the command line.
Connecting the dongle to the Pi
With the Raspberry Pi turned off, plug the Dongle into an available USB port. The smaller connector on the debug cable should be carefully fitted to the header pins on the dongle, with the ribbon cable coming off to the left assuming the dongle is orientated with the USB connector to the top, shown in the photo below
Dongle with debug cable connected |
Next you need to connect the other end of the debug cable to the GPIO pins on the Raspberry Pi. There's some pinouts etc online, but the orientation wasn't clear to me. I did some verification with a multimeter and managed to figure it out. The pinout diagram assumes you're looking into the larger connector on the debug cable, with the locator at the top.
The debug cable (Click to expand) |
You only need to connect 4 cables between the debug cable and the Raspberry Pi. These are ground, DC, DD and Reset. I used some short, Male to Female jumper cables.
Debug Cable Pinout |
Raspberry Pi Pinout, Assuming USB ports are on the right. |
Debug Connector | Raspberry Pi GPIO | |
---|---|---|
GND | 1 | 39 |
RESET | 4 | 35 |
DC | 2 | 36 |
DD | 7 | 38 |
Hopefully the above diagrams give you enough to figure out the wiring. I've included some photos below for reference. I was using Black for Ground, Grey for Reset, Orange for DC and Yellow for DD
Front view of large debug connector showing connections |
Connections to Raspberry Pi GPIOs |
Once everything is connected up, you can power on the Raspberry Pi. Hopefully you won't see any magic smoke escaping.
Flashing the firmware
The next step is to flash the zigbee2mqtt firmware to the dongle.sudo su
Install some dependancies:
apt-get install wiringpi git unzip
Change into the opt directory:
cd /opt
Clone the repo:
git clone https://github.com/jmichault/flash_cc2531.git
Change into the new directory:
cd flash_cc2531
Check the dongle is properly connected, by running the command below. It should return the ID as b524. If there is an error, check the connections!
./cc_chipid
Download the latest firmware and unzip it:
wget https://github.com/Koenkk/Z-Stack-firmware/raw/master/coordinator/Z-Stack_Home_1.2/bin/default/CC2531_DEFAULT_20190608.zip unzip CC2531_DEFAULT_20190608.zip
Erase and flash the firmware. It should take around 3 minutes:
./cc_erase ./cc_write CC2531ZNP-Prod.hex
Once you see "Flash Ok" you've finished flashing the firmware and can start using the dongle.
I think that the pinout drawing for the pi is wrong. USB ports should be on the RIGHT.
ReplyDeleteGood tutorial! Clear and precise.
ReplyDelete