We connect the Chinese weather station

The network has widely considered the implementation of a temperature sensor implemented on a DS18B20 chip and connected to a TP-link MR-3020 router (with OpenWRT firmware) through a PL2303 converter.
With the digitemp utility, the sensor was read and the data was sent to the site narodmon.ru.

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

A Weather Station was ordered on the Chinese site. Appearance:



This miracle of Chinese engineering, according to the description, has pretty tolerable specifications and allows you to measure the following parameters:

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

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

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

It was decided to disassemble the transmitter and see its operation with an oscilloscope.

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



Two identical packages were transmitted sequentially, 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 see the structure of the message, in the hope of a possible opening and extraction of useful information.

A couple of debugging boards on the STM32F103C8T6 microcontroller, previously purchased through the Chinese website,



were lying in the zashashnik : the modulator circuit was hooked to the pins PA0, PA1, the pulses were processed by interrupts (along the leading and trailing edges), the bits were packed into bytes and output via UART.

The result was prepared to the following:
Temperature: 23 C Humidity: 61%
0xF5 0x42 0x00 0x3F 0xF0 0xE6 0x3D 0x00 0x00 0x00 0x01 0x00 0x8A 0x0A
temperature: 22.4 C Humidity: 53%
0xF5 0x3F 0x42 0x00 0x35 0x00 0xE0 0xF0 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 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 clearly. The only thing is, it was not possible to determine the algorithm for calculating the checksum (last 2 bytes), but you can live like that.

While the research continued, it was decided to add the BMP085 atmospheric pressure sensor (on a scarf with a strapping of about 200 rubles for the Chinese) in addition to everything. 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 you can measure atmospheric pressure ,temperature and calculate the height .
Now, in response to the request (send the '?' Sign by 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 packed and sent to the network on narodmon, for which we connect the debugging board to the MR-3020 router:



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

Here is a script I pull cron'om 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, we also initialize the port settings at startup:

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 weather parameters.

Also popular now: