📜 ⬆️ ⬇️

We connect the Chinese meteorological station

The network widely considered an embodiment of a temperature sensor made on a DS18B20 chip and connected to a TP-link MR-3020 router (with OpenWRT firmware) via a PL2303 converter.
The digitemp utility reads the sensor and sends the data to the site narodmon.ru.

But this functionality was not enough, I wanted something more ...

On the Chinese site was ordered weather station (Weather Station). Appearance:


')
According to the description, this miracle of Chinese engineering has rather tolerable technical characteristics and makes it possible to measure the following parameters:

  1. air temperature;
  2. air humidity;
  3. wind speed;
  4. Direction of the wind;
  5. precipitation amount.

The only negative is the lack of indications of atmospheric pressure.

The long-awaited device was received and assembled, but from the very beginning it refused to work stably. When enabled, the receiving unit did not want to show the parameters. He took out the batteries from the receiving and transmitting units, only occasionally readings appeared. In general, more time did not work than worked.

It was decided to disassemble the transmitter and see his work with an oscilloscope.

Experimentally, a modulator circuit was found that forms oscillograms of the following form:



Two identical packages were transmitted successively, then the transmitter was silent for about 40 seconds.

At one forum, the guys suggested that the encoding of the package resembles the Manchester code.

It was decided to make a signal receiving device (“hardware sniffer”) and look at the structure of the message, in the hope of a possible opening and extraction of useful information.

A couple of debug boards on the STM32F103C8T6 microcontroller, previously purchased through a Chinese website, were lying in the store:



The modulator circuit was hooked onto the PA0, PA1 pins, the impulses were processed by interrupts (on the leading and trailing edges), the bits were packed into bytes and output via the UART.

As a result, the following messages were received:
temperature: 23 C humidity: 61%
0xF5 0x3F 0x42 0x00 0xF0 0xE6 0x3D 0x00 0x00 0x00 0x01 0x00 0x8A 0x0A
temperature: 22.4 C humidity: 53%
0xF5 0x3F 0x42 0x00 0xF0 0xE0 0x35 0x00 0x00 0x00 0x01 0x00 0x7C 0x76
temperature: 27.7 C humidity: 20%
0xF5 0x3F 0x42 0x00 0xF1 0x15 0x14 0x00 0x00 0x00 0x01 0x00 0x91 0x8B

After long-term observations of the received messages, it was possible to identify which byte that encodes. Apparently, the Chinese did not bother much when implementing this protocol, everything is quite simple and intuitive. The only thing is that we could not determine the algorithm for calculating the checksum (the last 2 bytes), but you can live like that.

While the research continued, it was decided to fasten the BMP085 atmospheric pressure sensor in the appendix to everything (on a scarf with a strapping around 200 rubles from the Chinese). It looks like this:



I hooked it to the I2C debug board, the source code for working with it was found on the network. Everything worked right away. Now it is possible to measure atmospheric pressure , temperature and calculate altitude .
Now, in response to the request (send the '?' Sign on UART) we get the following message:

01 Pressure : 762.02 mmHg 02 Temp_indoor : 23.10 C 03 Humidity : 37 % 04 Temp_outdoor : 19.00 C 05 Wind_speed : 2.0 m/s 06 Wind_direction : 360 07 Precipitation: 0 mm 

Now everything needs to be packaged and sent to the network on narodmon, for which we connect the debug board to the MR-3020 router:



Custom firmware, with support for 3G modem (relied on autonomy).

Here's a script jerking cron every 6 minutes:

 #!/bin/sh TEST_WAN="`ifconfig | grep 3g | cut -b 1`" if [ "$TEST_WAN" = 3 ]; then # echo "3G-WAN OK" logger "3G router OK" else reboot && exit fi #----------------------------------------------------------------- ifconfig | grep HWaddr | awk '{FS=" "; if(NR==1) {print "#"$5;}}' > /var/log/HWaddr count=0 echo "?" > /dev/ttyUSB0 sed -e 's/:/-/g' /var/log/HWaddr > /var/log/temp while read -t 3 LINE < /dev/ttyUSB0 ; do echo $LINE | awk '{FS=" "; if($3==":") { print MAC $1"#"$4;}}' MAC=`cat /var/log/HWaddr` >> /var/log/temp done < /dev/ttyUSB0 rm /var/log/HWaddr echo "##" >> /var/log/temp sed -e 's/://g' /var/log/temp > /var/log/narodmon rm /var/log/temp cat /var/log/narodmon LC=`cat /var/log/narodmon | wc -l` if [ $LC -gt 2 ] then cat /var/log/narodmon | nc narodmon.ru 8283 > /var/log/narodmon.log fi 


Here is the result of the script:

 #64-65-B3-2C-25-AA #6465B32C25AA01#740.46 #6465B32C25AA02#25.50 #6465B32C25AA03#27 #6465B32C25AA04#29.50 #6465B32C25AA05#0.00 #6465B32C25AA06#NONE #6465B32C25AA07#0 ## 


Yes, even in autoload, we register initialization of port settings:

stty -F / dev / ttyUSB0 cs8 57600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts -hupcl

As a result, we get the opportunity to watch and save a bunch of parameters about the weather.

Source: https://habr.com/ru/post/241599/


All Articles