Alternative firmware for temperature and humidity sensor Sonoff SNZB-02 Zigbee

Greetings to all readers of Habr. In this article I want to share with you my new small project.

The star of this project is the temperature and humidity sensor. SONOFF SNZB-02 from company ITEAD. This sensor appeared on the market about 2 years ago, it was in fact ITEAD’s first attempt to enter the Zigbee device segment. The company produced a series of sensors in the amount of 4 pieces and a gateway to them.

The SONOFF SNZB-02 sensor is built on microcontroller cc2530 from Texas Instruments, a sensor that measures temperature and humidity installed hdc1080apparently ITEAD sought to do everything on a component base from Texas Instruments.

With the help of a table lamp, a magnifying glass and an hour of time, the sensor circuit was transferred to paper. The circuit is not intricate, the i2c interface lines from the HDC1080 on this sensor are brought to the legs p1.6 and p.17. The LED is connected to the leg p1.0 by the cathode. The button is connected to the p2.0 leg with a binding that suppresses contact bounce. There are a lot of contact pads on the board, they are all marked on the device diagram. In the photo below, I have highlighted the areas to which you need to solder to flash the device with my alternative firmware.

The firmware process should not cause any difficulties, the places for soldering wires are very convenient. For flashing you will need to go to my github and download the firmware file. Next you will need SmartRF Flash Programmer version 1. I’ll leave how to download and install it outside the scope of this article, I’m sure the Internet will help with this. You will also need CC Debugger or Smart RF04E (recommended for ease of connection).







The source code of the project is also posted on the github, this is for those who want to change something in the project to their taste.

Flashing process using SmartRF Flash Programmer v1

Solder 5 wires to the pads indicated in the photo and connect these wires to the corresponding signed debugger contacts. Connect the debugger to the computer’s usb port, open the SmartRF Flash Programmer v1. To the right of the field in the Flash Image item, click on the “browse” icon and select the firmware file downloaded earlier. In the Actions section, select Erase and click on the Perform actions button below. After you have cleaned the chip, select Erase and program in the same Actions item and press the Perform actions button again.

Solder the wires, assemble the sensor back into the case, insert the battery.

Flashing process using ESP8266

Connect the ESP8266 board to your computer with a USB data cable and make sure it is recognized by the system.

If the necessary drivers for your board are not installed:

Download the fork CCLoader by Jason2866 by clicking Download ZIPand extract it to a folder.

Flash the ESP8266 (NodeMCU) with the pre-compiled CCLoader_Arduino.bin from the Bin folder of the downloaded zip file using one of your ESP8266 flashing tools, such as: ESP Flasher, NodeMCU-pyflasher, esptool.py.

Connect ESP8266 to Sonoff sensor as shown in the table below.

Download alternative firmware from my github. If the file opens as text, right-click “Save As…” and save as sonoff.hex.

Windows

Download objcopy.exe from

sourceforge

and unpack. (If objcopy.exe does not run, you need to download

libiconv

and unzip to the same folder.)

Copy the alternative firmware .hex file to the same folder and convert it to .bin with:

objcopy.exe --gap-fill 0xFF --pad-to 0x040000 -I ihex sonoff.hex -O binary sonoff.bin

Move the converted .bin to the CCLoader folder.

linux

Install

binutils

package using the package manager (Debian example: sudo apt install binutils)

Copy the .hex firmware file to the same folder and convert it to .bin with:

objcopy --gap-fill 0xFF --pad-to 0x040000 -I ihex sonoff.hex -O binary sonoff.bin

Firmware

CCLoader will use a NodeMCU with a downloaded CCLoader binary as a bridge to upload firmware to the Sonoff sensor.

Windows

Use CCLoader_x86_64.exe or CCloader.exe from the \Windows folder. Place the prepared .bin in the same folder as the CCLoader executable.

The command to start the firmware process. Change COM# to the COM port number your ESP8266 is connected to.

CCLoader_x86_64.exe [COM#] sonoff.bin 0

Example: from NodeMCU to COM6

CCLoader_x86_64.exe 6 sonoff.bin 0

linux

First you need to compile CCLoader:

  • cd to CCLoader/SourceCode/Linux
  • run
gcc main.c -o CCLoader

Place the prepared .bin in the same folder as the compiled CCLoader executable.

Command to start the firmware process

./CCLoader [port path] sonoff.bin 0

Example: with NodeMCU enabled /dev/ttyACM0

./CCLoader /dev/ttyACM0 sonoff.bin 0

The firmware was successful if you see this:

Upload successfully!
File closed!
Comport closed!

Possible problems

If the flashing failed or stuck on Request sent already! Waiting for response…:

try using 1 instead of 0 in the last parameter (./CCLoader [port path] sonoff.bin 1)
Reconnect NodeMCU and try again
Check how the wires are connected, … check again how the wires are connected.


Successful firmware in Windows looks like this.

Solder the wires, assemble the sensor back into the case, insert the battery.

Networking

To add a device to z2m, you need to click on the Allow Connections button in the z2m web interface. After that, press and hold the button on the SONOFF SNZB-02 sensor for 2 seconds, the LED will start flashing and the login process should begin.

To remove the device from the network, it is necessary to hold down the button for 10 seconds, after this time the LED will start flashing, and the sensor will start the procedure for leaving the network. A short press initiates the reading and sending of all data from the sensor out of schedule.

What will change in the operation of the sensor.

The sensor now transmits temperature and humidity data through temperature and humidity clusters. The sensor can be bound to these clusters to other devices that have implemented binding according to these clusters. After binding, the sensor will transmit temperature and humidity data directly to the devices to which it is associated.



Also, the sensor will start to work with the oNoFF cluster. This can be useful for direct relay control. For these purposes, the simple functionality of a thermostat and a hygrostat is implemented in the sensor. For direct control of the sensor by external relays, it is necessary to bind the sensor to the relay with which it will work. To do this, go to the sensor page in the z2m web interface, go to the communication tab. And in the new line in the first field, select the starting point -1, in the next field to the right in the drop-down list, find the relay to which you plan to bind the sensor. Further to the right, in the oNoFF checkbox, check the box and click the Connect button. After that, press the button on the sensor body so that the sensor wakes up and accepts new configuration data.

After binding, you must go to the properties tab, set the thresholds in the thermostat or hydrostat section, after each value entered in the fields, you must press the button on the sensor body so that it wakes up and accepts the configuration. After setting the thresholds, you need to activate the control with the switch, also after switching by pressing the button on the sensor.

Well, the last functionality in this alternative firmware is setting the sleep interval, the default interval is 5 minutes. The available range is from 1 minute to 1 hour.

The project is open, the source files of the project, firmware, scheme are placed on my github

My telegram chat DIY DEV | My instagram

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *