Post by Bruster999 on May 21, 2016 20:42:39 GMT -8
Hi
I just downloaded the app and installed the server on my RasPi 2. I'm trying to get a few object working like the Speedometer to read temperature from a DHT22 but I cannot seem to find a way to get debug info. I thought it was through the print statements but no matter what I print, I don't see anything in the RasPiConnectServer.log file.
How can I create log entries and where can I read them?
Here is the code I am using. There is one feedback button which works fine and one Speedometer that I am trying to send the temperature back to to show on my iPad. Any feedback on the code would be welcome as well. Thanks
Bruster
#!/usr/bin/python
# Filename: local.py
# MiloCreek BP MiloCreek
# Version 3.0 6/11/2014
#
# Local Execute Objects for RasPiConnect
# to add Execute objects, modify this file
#
#
#
# system imports
import sys
import subprocess
import os
import time
import time
import glob
import picamera
# RasPiConnectImports
import Config
import Validate
import BuildResponse
import RPi.GPIO as GPIO ## Import GPIO library
GPIO.setmode(GPIO.BCM) ## Use BCM numbering
GPIO.setup(25, GPIO.OUT)
pin = 4
sensor=22
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)
#
# FB-1 Turns on Relay1
if (objectServerID == "FB-1"):
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#if (Config.debug()):
print("Button # %s: Toggle relay" % objectServerID)
#GPIO.output(25,True) ## Turn on GPIO pin 7
GPIO.output(25,not GPIO.input(25))
#time.sleep(1) ## sleep 1 second
#GPIO.output(7,False) ## Turn off GPIO pin 7
if (GPIO.input(25) == True):
responseData = "Relay On"
else:
responseData = "Relay Off"
print "FB-1 responseData =", responseData
#
#
# Done with your code
#
#
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
else:
# returning a zero length string tells the server that you have not matched
# the object and server
return ""
if (objectServerID == "M-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
if (Config.debug()):
print("Getting temperature # %s: " % objectServerID)
humidity = None
tempF = None
temperature=None
while temperature is None: #loop until it gets a reading
print("while temperature loop")
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) #retries 15x
if humidity is not None and temperature is not None:
humidity = round(humidity,1)
tmp = round(temperature*9/5,1)
tempF=tmp+32
print("TempF: %s", tempF)
if (tempF is not None):
responseData = tempF
else:
responseData = "99"
print "M-2 responseData =", responseData
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
I just downloaded the app and installed the server on my RasPi 2. I'm trying to get a few object working like the Speedometer to read temperature from a DHT22 but I cannot seem to find a way to get debug info. I thought it was through the print statements but no matter what I print, I don't see anything in the RasPiConnectServer.log file.
How can I create log entries and where can I read them?
Here is the code I am using. There is one feedback button which works fine and one Speedometer that I am trying to send the temperature back to to show on my iPad. Any feedback on the code would be welcome as well. Thanks
Bruster
#!/usr/bin/python
# Filename: local.py
# MiloCreek BP MiloCreek
# Version 3.0 6/11/2014
#
# Local Execute Objects for RasPiConnect
# to add Execute objects, modify this file
#
#
#
# system imports
import sys
import subprocess
import os
import time
import time
import glob
import picamera
# RasPiConnectImports
import Config
import Validate
import BuildResponse
import RPi.GPIO as GPIO ## Import GPIO library
GPIO.setmode(GPIO.BCM) ## Use BCM numbering
GPIO.setup(25, GPIO.OUT)
pin = 4
sensor=22
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)
#
# FB-1 Turns on Relay1
if (objectServerID == "FB-1"):
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#if (Config.debug()):
print("Button # %s: Toggle relay" % objectServerID)
#GPIO.output(25,True) ## Turn on GPIO pin 7
GPIO.output(25,not GPIO.input(25))
#time.sleep(1) ## sleep 1 second
#GPIO.output(7,False) ## Turn off GPIO pin 7
if (GPIO.input(25) == True):
responseData = "Relay On"
else:
responseData = "Relay Off"
print "FB-1 responseData =", responseData
#
#
# Done with your code
#
#
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
else:
# returning a zero length string tells the server that you have not matched
# the object and server
return ""
if (objectServerID == "M-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
if (Config.debug()):
print("Getting temperature # %s: " % objectServerID)
humidity = None
tempF = None
temperature=None
while temperature is None: #loop until it gets a reading
print("while temperature loop")
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) #retries 15x
if humidity is not None and temperature is not None:
humidity = round(humidity,1)
tmp = round(temperature*9/5,1)
tempF=tmp+32
print("TempF: %s", tempF)
if (tempF is not None):
responseData = tempF
else:
responseData = "99"
print "M-2 responseData =", responseData
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData