XRF Temperature Sensor -> XRF Slice of Pi


Over the last few days I have been working on getting my XRF Sensors all working with my Raspberry Pi. I have 3 XRF Temperature sensors. WHen I got them I updated the sensors to use a different Channel so that if someone else in the neighbourhood uses XRF we do not clash (in the future I will be looking to enable encryption too).

To start with I just used the button battery but decided as I would use a double AA battery back as I wanted to use have the update interval set to every minute. The battery back should give me around a years worth of use from 1 pair of batteries.

Once I built them up and boxed the sensors in I ended up with the following mostly damp proof unit…

So to get the system working I have a python script which takes the data from the SliceOfPi with the XRF receiver on and publishes a message using Mosquitto MQTT broker to a topic according to the data it receives. It also stores the data in an RRDTool database

[sourcecode language=”python”]
#!/usr/bin/python
import mosquitto
import os
import time
import serial
import datetime
import rrdtool
import re

broker = "127.0.0.1"
tcpport = 1883

baud = 9600
port = ‘/dev/ttyAMA0’
ser = serial.Serial(port, baud)
rrddir = ‘/home/pi/rrd-data/’

mypid = os.getpid()
client_uniq = "pubclient_"+str(mypid)
mqttc = mosquitto.Mosquitto(client_uniq)
#connect to broker
mqttc.connect(broker, tcpport, 60, True)

#remain connected and publish
while mqttc.loop() == 0:
llapMsg = ser.read(12)
now = datetime.datetime.now()
mqttc.publish("TempSensors", llapMsg)
if re.search("TMPA", llapMsg):
rrdfile = llapMsg[1:7]
value = llapMsg[7:12]
print now.strftime("%Y-%m-%d %H:%M:%S ") + ‘String = |’ + llapMsg + ‘| Updating RRD – File: ‘ + rrdfile + ‘.rrd with temperature value: ‘ + value
rrdtool.update(rrddir + ‘XRFTemp/’ + rrdfile + ‘.rrd’,’N:’ + str(value));
elif re.search("BATTLOW", llapMsg):
sensor = llapMsg[1:3]
print now.strftime("%Y-%m-%d %H:%M:%S ") + ‘String = |’ + llapMsg + ‘| Warning Sensor ‘ + sensor + ‘ has low battery’
elif re.search("WAKE", llapMsg):
sensor = llapMsg[1:3]
print now.strftime("%Y-%m-%d %H:%M:%S ") + ‘String = |’ + llapMsg + ‘| Sensor ‘ + sensor + ‘ waking’
elif re.search("BATT", llapMsg):
rrdfile = llapMsg[1:7]
value = llapMsg[7:11]
print now.strftime("%Y-%m-%d %H:%M:%S ") + ‘String = |’ + llapMsg + ‘| Updating RRD – File: ‘ + rrdfile + ‘.rrd with battery voltage: ‘ + value
rrdtool.update(rrddir + ‘XRFBattery/’ + rrdfile + ‘.rrd’,’N:’ + str(value));
elif re.search("SLEEPING", llapMsg):
sensor = llapMsg[1:3]
print now.strftime("%Y-%m-%d %H:%M:%S ") + ‘String = |’ + llapMsg + ‘| Sensor ‘ + sensor + ‘ sleeping’
else:
print now.strftime("%Y-%m-%d %H:%M:%S ") + ‘String = |’ + llapMsg + ‘| No match’

[/sourcecode]

The Apache TomCat server on the RaspberryPi then uses php & rrd to create charts accordingly. Below is a sample of the output from the sensors.


One response to “XRF Temperature Sensor -> XRF Slice of Pi”

Leave a Reply

Your email address will not be published.