Xastir – Raspberry Pi 1-Wire Temp Sensor

Xastir,  Raspberry Pi, DS18B20 Temp Sensor

The instructions below are how I took Adafruits instructions for their temp sensor, and modified it slightly, to rewrite the config file of Xastir. An additional script updates the config file, launches Xastir, and then kills it after a specified period of time.


  • Raspberry Pi with Xastir already installed and configured. (Instructions)
  • DS18B20 Temp Sensor, Resistor, and supporting wiring/breadboard.


  1. Follow these instructions to wire and test your temp sensor.
  2. Copy and modify Xastir config, to add some text to replace later:
    1. sudo leafpad /root/.xastir/config/xastir.cnf
    2. Change ‘STATION_COMMENTS:’ to include ‘*TEST*’, save the file as xastir.aaa
  3. Create a new python script, based on step 1.
    1. leafpad therm2.py
    2. Cut and paste:
    3. import os
      import glob
      import time
      os.system('modprobe w1-gpio')
      os.system('modprobe w1-therm')
      base_dir = '/sys/bus/w1/devices/'
      device_folder = glob.glob(base_dir + '28*')[0]
      device_file = device_folder + '/w1_slave'
      def read_temp_raw():
       f = open(device_file, 'r')
       lines = f.readlines()
       return lines
      def read_temp():
       lines = read_temp_raw()
       while lines[0].strip()[-3:] != 'YES':
       lines = read_temp_raw()
       equals_pos = lines[1].find('t=')
       if equals_pos != -1:
       temp_string = lines[1][equals_pos+2:]
       temp_c = float(temp_string) / 1000.0
       temp_f = temp_c * 9.0 / 5.0 + 32.0
       return temp_f
      # Read in the file
      with open('/root/.xastir/config/xastir.aaa', 'r') as file :
       filedata = file.read()
      # Replace the target string
      filedata = filedata.replace('*TEST*',str(temp_f))
      # Write the file out again
      with open('/root/.xastir/config/xastir.cnf', 'w') as file:
    4. save and quit
  4. Create shell script
    1. leafpad runther.sh
    2. cut and paste
    3. sudo python therm2.py
      sudo xastir &
      sleep 900
      kill $TASK_PID
      sudo sh runther.sh
    4. save
  5. run
    1. sudo sh runther.sh