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.
Requirements:
- Raspberry Pi with Xastir already installed and configured. (Instructions)
- DS18B20 Temp Sensor, Resistor, and supporting wiring/breadboard.
Instructions
- Follow these instructions to wire and test your temp sensor.
- Copy and modify Xastir config, to add some text to replace later:
- sudo leafpad /root/.xastir/config/xastir.cnf
- Change ‘STATION_COMMENTS:’ to include ‘*TEST*’, save the file as xastir.aaa
- Create a new python script, based on step 1.
- leafpad therm2.py
- Cut and paste:
-
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() f.close() return lines def read_temp(): lines = read_temp_raw() while lines[0].strip()[-3:] != 'YES': time.sleep(0.2) 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 temp_f=read_temp() print(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: file.write(filedata)
- save and quit
- Create shell script
- leafpad runther.sh
- cut and paste
-
sudo python therm2.py sudo xastir & TASK_PID=$! sleep 900 kill $TASK_PID sudo sh runther.sh
- save
- run
- sudo sh runther.sh