ShapeShifter:
I handled getting the data from the sketch a little differently than you, I used the Bridge library. The sketch reads a set of temperature sensors, and uses Bridge.put() calls to save the current values. Then the python script periodically uses the Bridge to get() the values and send them to collectd. This is my python script:#!/usr/bin/python
A python script designed to be run by the exec module of collectd.
It uses the Bridge library to "get" values that were "put" by the sketch.
This script assumes that there will be a value 'tempCnt' that indicates
how many temperature values there are to read. The actual values are
named 'tempF_1', 'tempF_2', etc.
import os
import sys
import time
sys.path.insert(0, '/usr/lib/python2.7/bridge/')
from bridgeclient import BridgeClient as bridgeclient
bridge = bridgeclient()
Read hostname environment variable set by collectd exec plugin.
hostname = os.environ.get('COLLECTD_HOSTNAME', 'localhost')
while True:
#Gather temperatures
count = int(bridge.get('tempCnt'))
if count > 0:
for c in range(count):
# Form the name and get the value from the bridge
key = 'tempF_{0}'.format(c+1)
temp = bridge.get(key)
# Make sure a value was actually read
if (temp != None):
#output value to be sent to collectd exec plugin
print 'PUTVAL "{0}/exec-{1}/gauge" {2}:{3}'.format(hostname, key, 0, temp)
sys.stdout.flush()
# give up processing time to not bog down the CPU and limit the update rate
time.sleep(10)
Just another way of approaching it. It may be a little more overhead using the Bridge, but it doesn't require parsing data on the python end. And, for my application, I also wanted to be able to remotely retrieve the current data values without having to tap into the collectd stream: using the bridge gives you the ability to access "http:arduino.local/data/get" to retrieve all bridge data values -- for free with no extra code needed!
That's very useful, thanks!