Hi Mike,
Thank you yet again - I feel like a real "leech" asking for and receiving all this help from you and the other guys, but I am learning slowly. That has answered my question regarding multiple sensors, so I'll get to work on that.
Yes, I do think it a good idea to maybe move the DS18B20 stuff to another thread; perhaps BP could make it so, but having said that, this thread does show noobs like me that the support is here if needed.
Thanks again all!Martin
Code needs a lot of cleaning up and rewriting, don't know how to post and retain the indention. All you need is the body and to change the names of the variables and sensors in the array. See red code. The values on the meters are just ambient in my computer room they are not installed on the engine at this time. Plan to add 4 or 5 more. The higher one is a probe by my CPU exhaust fan.
BTW the barmeters work opposite than I want, I want Green, Yellow, Red, not Red, Yellow, Green. I would like to see code added to reverse the graph. They need additional set points for the various color bars. I will more than likely go to a blinking button for high temp. Maybe 3 under each green, yellow, red.
#!/usr/bin/python
# Filename: Local.py
#
# Local Execute Objects for RasPiConnect
# to add Execute objects, modify this file
#
#
#
# RasPiConnectServer interface constants
REMOTE_WEBVIEW_UITYPE = 1
ACTION_BUTTON_UITYPE = 16
FEEDBACK_ACTION_BUTTON_UITYPE = 17
SINGLE_LED_DISPLAY_UITYPE = 32
SPEEDOMETER_UITYPE = 64
VOLTMETER_UITYPE = 128
BARMETER_UITYPE = 129
SERVER_STATUS_UITYPE = 256
PICTURE_REMOTE_WEBVIEW_UITYPE = 512
LABEL_UITYPE = 1024
FM_BLINK_LED_UITYPE = 2048
TEXT_DISPLAY_UITYPE = 4096
TOGGLE_SWITCH_UITYPE = 33
SEND_TEXT_UITYPE = 34
# system imports
import sys
import subprocess
# RasPiConnectImports
import Config
import Validate
import BuildResponse
#system inports
import sys
import subprocess
import RPi.GPIO as GPIO
import time
import os
import glob
def ExecuteUserObjects(objectType, element):
# Example Objects
# fetch information from XML for use in user elements
#objectServerID is the RasPiConnect ID from the RasPiConnect App
objectServerID = element.find("./OBJECTSERVERID").text
objectID = element.find("./OBJECTID").text
if (Config.debug()):
print("objectServerID = %s" % objectServerID)
#
# check to see if this is a Validate request
#
validate = Validate.checkForValidate(element)
if (Config.debug()):
print "VALIDATE=%s" % validate
# Build the header for the response
outgoingXMLData = BuildResponse.buildHeader(element)
# objects are split up by object types by Interface Constants
#
#
#
# search for matches to object Type
# This Code not used at this time.
# object Type match
if (objectType == ACTION_BUTTON_UITYPE):
if (Config.debug()):
print "SPEEDOMETER_UITY of %s found" % objectServerID
# B-2 - play a beep on the Raspberry Pi
if (objectServerID == "B-2"):
#check for validate request
# validate allows RasPiConnect to verify this object is here
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
# not validate request, so execute
# note that python is in the main directory for this call, not the local directory
output = subprocess.call(["aplay", "sounds/match1.wav"])
responseData = "OK"
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
######################################################################################################
# Location of all Voltmeter Gagues
# All Temperatures Converted to F
# Yanmar Coolant Water Temperature
#
temp_yc = Yanmar coolant if (objectType == VOLTMETER_UITYPE):
if (objectServerID == "M-1"):
#Check for valid request
#Validate allows RasPiConnect to verify this object is here.
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
sensorids = ["28-0000059e05c6", "28-0000059e4d34"] text = ''; # Choose which sensor you want to read. [0] or [1].
tfile = open("/sys/bus/w1/devices/"+ sensorids[0] +"/w1_slave") text = tfile.read() tfile.close() secondline = text.split("\n")[1] temperaturedata = secondline.split(" ")[9] temperature = float(temperaturedata[2:]) #Convert to F temp_yc = ( temperature / 1000 ) * 9.0 / 5.0 + 32.0 responseData = "%3.2f" %
temp_yc outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#######################################################################################################
# Yanmar Wet Exhaust Water Temperature
# temp_ye = Yanmar Wet Exhaust
if (objectServerID == "M-2"):
#Check for valid request
#Validate allows RasPiConnect to verify this object is here.
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
sensorids = ["28-0000059e05c6", "28-0000059e4d34"]
text = '';
tfile = open("/sys/bus/w1/devices/"+ sensorids[1] +"/w1_slave") text = tfile.read()
tfile.close()
secondline = text.split("\n")[1]
temperaturedata = secondline.split(" ")[9]
temperature = float(temperaturedata[2:])
temp_ye = ( temperature / 1000 ) * 9.0 / 5.0 + 32.0
responseData = "%3.2f" % temp_ye
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#####################################################################################################################
# Barmeter for Yanmar Coolant Temperature
# temp-yc = Coolant Temp.
if (objectType == BARMETER_UITYPE):
if (objectServerID == "BR-1"):
#Check for valid request
#Validate allows RasPiConnect to verify this object is here.
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
sensorids = ["28-0000059e05c6", "28-0000059e4d34"]
text = '';
tfile = open("/sys/bus/w1/devices/"+ sensorids
[0] +"/w1_slave")
text = tfile.read()
tfile.close()
secondline = text.split("\n")[1]
temperaturedata = secondline.split(" ")[9]
temperature = float(temperaturedata[2:])
temp_yc = ( temperature / 1000 ) * 9.0 / 5.0 + 32.0
responseData = "%3.2f" % temp_yc
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#####################################################################################################################
# Barmeter for Yanmar Coolant Temperature
# temp-ye = Wet Exhaust Temp.
if (objectServerID == "BR-2"):
#Check for valid request
#Validate allows RasPiConnect to verify this object is here.
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
sensorids = ["28-0000059e05c6", "28-0000059e4d34"]
text = '';
tfile = open("/sys/bus/w1/devices/"+ sensorids
[1] +"/w1_slave")
text = tfile.read()
tfile.close()
secondline = text.split("\n")[1]
temperaturedata = secondline.split(" ")[9]
temperature = float(temperaturedata[2:])
temp_ye = ( temperature / 1000 ) * 9.0 / 5.0 + 32.0
responseData = "%3.2f" % temp_ye
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
##################################################################################################################
else:
return ""
# returning a zero length string tells the server that you have not matched
# the object and server
return ""