How To Build simple WX station using Pi Zero + BME280

You can built your own weather station using Argent ADS-WS1 or any other devices that capable submiting to aprs-is or cwop network, but it was too expensive for me.
i began my research how to craft APRS WX packet using python and bash script on direwolf. that
was not easy for newbie amateur like me, LOL. Luckily i’ve found aprs-weather-submit created by KC1HBK.
it makes my research easier.

first of all, we need some hardwares Raspi Zero, BME280 sensorand some jumper wires.
Conect all wires from pi zero to bme280 using i2c pin. you can find pinout configuration here:

https://pinout.xyz

or type pinout in ssh shell

don’t forget to activate i2c pin, go ssh shell. issue command sudo raspi-config and go to interface options to activate i2c

Wiring:

  1. BME280 VIN pin connects to GPIO pin 1 (3.3V)
  2. BME280 GND pin connects to GPIO pin 6 (GND)
  3. BME280 SCL pin connects to GPIO pin 5 (SCL)
  4. BME280 SDA pin connects to GPIO pin 3 (SDA)

i’m using python and bme280 library from https://github.com/pimoroni/bme280-python
there’s some example script there, i silghtly modify the script to obtain bme280 values

building aprs-weather-submit.

git clone https://github.com/rhymeswithmogul/aprs-weather-submit.git

cd aprs-weather-submit

follow the instructions at build scripts section here:

https://github.com/rhymeswithmogul/aprs-weather-submit/blob/master/INSTALL.md

./autogen.sh ./configure [--disable-aprs-is] [--enable-debug] 
make 
sudo make install

when i first compiled, i got this error:

modify main.c

vi src/main.c

at line 588

i changed this line from:

(note at %lu)

fprintf(stderr, “Your comment was %lu characters long, but APRS allows %u characters. Your comment was truncated.\n”, strlen(optarg), MAX_COMMENT_LENGTH);

i changed it to %ul

than it compiled propperly.

here is my wx.sh script to generate wx format:

wx.sh

#!/bin/bash
STR=$(/home/pi/bme280_cjb_AA.py)

Temp=$(echo $STR | cut -f 1 -d" ")
Hum=$(echo $STR | cut -f 3 -d" ")
Bar=$(echo $STR | cut -f 2 -d" ")
Alt=$(echo $STR | cut -f 4 -d" ")
#aprs-weather-submit -k YD0BCX-13 -n -06.714692S -e 106.728514 -t $Temp -A $Alt -h $Hum -b $Bar -V 9
STR2=$(aprs-weather-submit -k YD0BCX-13 -n -6.198611 -e 106.87000E -T $Temp -h $Hum -b $Bar -M " WX on Pi Zero + BME280 + DW 1.7")

echo "${STR2:22}"
#echo "$Temp $Hum $Bar $Alt"

/home/pi/bme280_cjb_AA.py

chmod 755 bme280_cjb_AA.py

#!/usr/bin/env python
#Import modules for time and to access sensor
import time
from smbus import SMBus
from bme280 import BME280
#Initialise the BME280
bus = SMBus(1)
bme280 = BME280(i2c_dev=bus)
#Get data and discard to avoid garbage first reading
temperature = bme280.get_temperature()
pressure = bme280.get_pressure()
humidity = bme280.get_humidity()
altitude = bme280.get_altitude()
time.sleep(1)
#while True:
temperature = bme280.get_temperature()
pressure = bme280.get_pressure()
humidity = bme280.get_humidity()
altitude = bme280.get_altitude()
if ( temperature and pressure and humidity and altitude ):
print('{:05.2f} {:05.2f} {:05.2f}'.format(temperature, pressure, humidity), round(altitude),  end="")
time.sleep(1)

in wx.sh, there’s command part
echo “${STR2:22}”

this command will remove leading 22 characters(based on my lat long value)
in this case when i’m executing aprs-weather-submit -k YD0BCX-13 -n -6.198611 -e 106.87000E
the result will be:
YD0BCX-13>APRS,TCPIP:@200431z0611.92S/10652.20E_…/…t…aprs-weather-submit/1.6

we need to remove “YD0BCX-13>APRS,TCPIP:” part, that’s what “echo “${STR2:22}”” is for.

if it’s not removed direwolf will also submit those part and make it position beacon failed to aprs-is(YD0BCX-13>APRS,TCPIP*: submit 2 times)

direwolf configuration:

ADEVICE plughw:1,0
#ACHANNELS 1
#CHANNEL 0
MYCALL YOURCALLSIGN
MODEM 1200
IGSERVER rotate.aprs2.net
IGLOGIN YOURCALLSIGN passcode

CBEACON sendto=IG delay=1 every=05:00 infocmd="echo '>WX Station' $(date)"

CBEACON sendto=IG delay=01:10 every=10:00 infocmd="telem-parm.pl YD0BCX-13 Temperature Pressure Humidity Altitude"
CBEACON sendto=IG delay=01:11 every=10:00 infocmd=&"telem-unit.pl YD0BCX-13 deg.C hPa % masl"
CBEACON sendto=IG delay=01:11 every=10:00 infocmd="telem-eqns.pl YD0BCX-13 0 1 0 0 1 0 0 1 0 0 1 0 0 1 0"
CBEACON sendto=IG delay=01:15 every=10:00 infocmd="telem-data.pl telem-seq.sh /home/pi/bme280_cjb_AA.py"

CBEACON sendto=IG delay=1 every=05:00 infocmd="/home/pi/wx.sh"

IBEACON sendto=IG delay=30 every=30 via=WIDE1-1

LOGDIR /var/log/direwolf
PTT GPIO 21

note on direwolf configuration, i also submiting telemetries data, you can ommit it if you want.
i think that’s it. i’m not good at talking or writing.

if there’s something to ask just drop me a message 😀

9 Comments

  1. Joe

    Hello, thanks for sharing your projects.

    When I run wx.sh I get a error:

    File “/home/pi/./wx.sh”, line 2
    STR=$(/home/pi/bme280_cjb_AA.py)
    ^
    SyntaxError: invalid syntax

    Not sure what to do now.

    Regards
    Joe
    VK5EI

    • try change

      STR=$(/home/pi/bme280_cjb_AA.py)
      

      to

      STR=`/home/pi/bme280_cjb_AA.py`
      

      note (` = backtick`)
      and don’t forget make bme280_cjb_AA.py executable

      chmod 755 bme280_cjb_AA.py
      
  2. Joe

    Hello Hari, thanks for your reply, I tried what you suggested and I get the same error.

    I am using the latest Raspberry Pi image, not sure what to do now

    Regards
    Joe

    • hmm, that’s strange. i reproduce the python and wx.sh script it still work.

      pi@raspberrypi:~ $ ls -al wx.sh 
      -rwxr-xr-x 1 pi pi 2321 Nov 30 13:59 wx.sh
      pi@raspberrypi:~ $ ls -al bme280_cjb_AA.py
      -rwxr-xr-x 1 pi pi 2191 Nov 29 21:25 bme280_cjb_AA.py
      pi@raspberrypi:~ $ pwd
      /home/pi
      pi@raspberrypi:~ $ ./wx2.sh 
      @150655z0611.92S/10652.20E_.../...t090h57b10040 WX on Pi Zero + BME280 + DW 1.7
      

      the script

      #!/bin/bash
      
      STR=$(/home/pi/bme280_cjb_AA.py)
      
      Temp=$(echo $STR | cut -f 1 -d" ")
      Hum=$(echo $STR | cut -f 3 -d" ")
      Bar=$(echo $STR | cut -f 2 -d" ")
      Alt=$(echo $STR | cut -f 4 -d" ")
      
      STR2=$(aprs-weather-submit -k YD0BCX-13 -n -6.198611 -e 106.87000E -T $Temp -h $Hum -b $Bar -M " WX on Pi Zero + BME280 + DW 1.7")
      
      echo "${STR2:22}"
      #echo "$Temp $Hum $Bar $Alt"
      

      make sure bme280_cjb_AA.py script output the right result when executed.

      pi@raspberrypi:~ $ ./bme280_cjb_AA.py
      0032 1004 0057 0080 001 11111111
      pi@raspberrypi:~ $
      pi@raspberrypi:~ $ /home/pi/bme280_cjb_AA.py
      0032 1004 0057 0080 100 11111111
      pi@raspberrypi:~ $
      

      can you post the script you’ve made. maybe i can recheck.
      regards
      YD0BCX

  3. Joe

    Hari, thanks for your help, I have the script working perfectly now. I re-imaged a SD card with new Pi os and started from scratch and it all worked ok. I must have done something before with my Pi and it may have corrupted some files.

    Thanks again
    Joe
    VK5EI

    • you’re very welcome joe, i’m glad finally it works for you.
      it could be sdcard or os, could be my typo writing, could be yours too.
      i always update my writing. based on reader’s feedback.

      thanks for the comments 🙂
      73, YD0BCX

  4. CT1DRB David Quental

    Hello Hari,

    how are you doing?

    A HNY 2023 to you and your family.

    your schematic seems very interesting but I have to questions:

    1) could it be compiled/used in another Raspberry PI;

    2) could it be possible to use an Ethernet device instead WIFI ????

    I am looking forward to reading from you.

    Best 73.

    CT1DRB/OK8RB
    David Quental

    • hi,
      happy new year to you too.
      i will try to answer your questions
      1. sure every os with linux based can compile as long as dependecies/libraries was installed.
      2 yes, any connection would be suffice as long as they have route to internet available.

      73
      YD0BCX hari

  5. CT1DRB David Quental

    Hello Hari,

    tks a lot for your answer.

    Best 73.

    CT1DRB/OK8RB
    David Quental

Leave a Reply

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