Post by raspipeter on Jul 8, 2014 12:51:17 GMT -8
Hi,
I intended to use the new available objects and facing problems to set it up correctly.
Despite the "example" available here under the RasPiConnect App --> General Questions, I cannot make the "Bubble Log" to work.
To be on the safe side I started with a complete new install of the server Version 3.0.
I used in the past some code for activating outputs and reading inputs of the PiFace module fitted on the RPI and that worked without a problem.
No I would like to send a text string to the "Bubble Log", but it does not appear to work.
I'm using the "default" Control Code "BTL-1", select my "raspberry home" system (url is working with all the other objects), but the BTL-1 Validate indicator does not turn GREEN when pushing the "Validate" button in the Edit Control screen.
If I'm ignoring the validate, I'm simply getting the "INVALID RASPICONNECT CODE" as response in the Bubble Log object.
I switched on the DEBUG function and this is the response
pi@raspberrypi ~/RasPiConnectServer $ sudo python RasPiConnectServer.py
192.168.2.109:9600/
<XMLObjectXMLRequests><XMLCOMMAND><VALIDATE>YES</VALIDATE><OBJECTSERVERID>BTL-1</OBJECTSERVERID><USERNAME>027C697DC48E9F294D450E5DF7372253</USERNAME><PASSWORD>01A4AFA6E8030895733322634DA47D14</PASSWORD><OBJECTNAME>Bubble Table</OBJECTNAME><OBJECTTYPE>43</OBJECTTYPE><OBJECTFLAGS>0</OBJECTFLAGS><OBJECTACTION>GETVALUE</OBJECTACTION><OBJECTID>3000</OBJECTID></XMLCOMMAND></XMLObjectXMLRequests>
XMLCOMMAND:
USERNAME: 027C697DC48E9F294D450E5DF7372253
PASSWORD: 01A4AFA6E8030895733322634DA47D14
OBJECTNAME: Bubble Table
OBJECTTYPE: 43
OBJECTSERVERID: BTL-1
OBJECTID: 3000
027C697DC48E9F294D450E5DF7372253
01A4AFA6E8030895733322634DA47D14
objectType = 43
objectServerID = BTL-1
VALIDATE=YES
objectServerID = BTL-1
<XMLCOMMAND><OBJECTID>3000</OBJECTID><OBJECTSERVERID>BTL-1</OBJECTSERVERID><OBJECTTYPE>43</OBJECTTYPE><OBJECTFLAGS>0</OBJECTFLAGS><RASPICONNECTSERVERVERSIONNUMBER>3.0</RASPICONNECTSERVERVERSIONNUMBER><RESPONSE><![CDATA[INVALID RASPICONNECT CODE]]></RESPONSE></XMLCOMMAND>
Local user objects returns: <XMLCOMMAND><OBJECTID>3000</OBJECTID><OBJECTSERVERID>BTL-1</OBJECTSERVERID><OBJECTTYPE>43</OBJECTTYPE><OBJECTFLAGS>0</OBJECTFLAGS><RASPICONNECTSERVERVERSIONNUMBER>3.0</RASPICONNECTSERVERVERSIONNUMBER><RESPONSE><![CDATA[INVALID RASPICONNECT CODE]]></RESPONSE></XMLCOMMAND>
final outgoing data =<XMLRESPONSES><XMLCOMMAND><OBJECTID>3000</OBJECTID><OBJECTSERVERID>BTL-1</OBJECTSERVERID><OBJECTTYPE>43</OBJECTTYPE><OBJECTFLAGS>0</OBJECTFLAGS><RASPICONNECTSERVERVERSIONNUMBER>3.0</RASPICONNECTSERVERVERSIONNUMBER><RESPONSE><![CDATA[INVALID RASPICONNECT CODE]]></RESPONSE></XMLCOMMAND></XMLRESPONSES>
192.168.2.106:53419 - - [08/Jul/2014 22:46:53] "HTTP/1.1 POST /raspi" - 200 OK
Any idea what can be wrong?
Thanks in advance,
Peter
My Local.py file below.
I intended to use the new available objects and facing problems to set it up correctly.
Despite the "example" available here under the RasPiConnect App --> General Questions, I cannot make the "Bubble Log" to work.
To be on the safe side I started with a complete new install of the server Version 3.0.
I used in the past some code for activating outputs and reading inputs of the PiFace module fitted on the RPI and that worked without a problem.
No I would like to send a text string to the "Bubble Log", but it does not appear to work.
I'm using the "default" Control Code "BTL-1", select my "raspberry home" system (url is working with all the other objects), but the BTL-1 Validate indicator does not turn GREEN when pushing the "Validate" button in the Edit Control screen.
If I'm ignoring the validate, I'm simply getting the "INVALID RASPICONNECT CODE" as response in the Bubble Log object.
I switched on the DEBUG function and this is the response
pi@raspberrypi ~/RasPiConnectServer $ sudo python RasPiConnectServer.py
192.168.2.109:9600/
<XMLObjectXMLRequests><XMLCOMMAND><VALIDATE>YES</VALIDATE><OBJECTSERVERID>BTL-1</OBJECTSERVERID><USERNAME>027C697DC48E9F294D450E5DF7372253</USERNAME><PASSWORD>01A4AFA6E8030895733322634DA47D14</PASSWORD><OBJECTNAME>Bubble Table</OBJECTNAME><OBJECTTYPE>43</OBJECTTYPE><OBJECTFLAGS>0</OBJECTFLAGS><OBJECTACTION>GETVALUE</OBJECTACTION><OBJECTID>3000</OBJECTID></XMLCOMMAND></XMLObjectXMLRequests>
XMLCOMMAND:
USERNAME: 027C697DC48E9F294D450E5DF7372253
PASSWORD: 01A4AFA6E8030895733322634DA47D14
OBJECTNAME: Bubble Table
OBJECTTYPE: 43
OBJECTSERVERID: BTL-1
OBJECTID: 3000
027C697DC48E9F294D450E5DF7372253
01A4AFA6E8030895733322634DA47D14
objectType = 43
objectServerID = BTL-1
VALIDATE=YES
objectServerID = BTL-1
<XMLCOMMAND><OBJECTID>3000</OBJECTID><OBJECTSERVERID>BTL-1</OBJECTSERVERID><OBJECTTYPE>43</OBJECTTYPE><OBJECTFLAGS>0</OBJECTFLAGS><RASPICONNECTSERVERVERSIONNUMBER>3.0</RASPICONNECTSERVERVERSIONNUMBER><RESPONSE><![CDATA[INVALID RASPICONNECT CODE]]></RESPONSE></XMLCOMMAND>
Local user objects returns: <XMLCOMMAND><OBJECTID>3000</OBJECTID><OBJECTSERVERID>BTL-1</OBJECTSERVERID><OBJECTTYPE>43</OBJECTTYPE><OBJECTFLAGS>0</OBJECTFLAGS><RASPICONNECTSERVERVERSIONNUMBER>3.0</RASPICONNECTSERVERVERSIONNUMBER><RESPONSE><![CDATA[INVALID RASPICONNECT CODE]]></RESPONSE></XMLCOMMAND>
final outgoing data =<XMLRESPONSES><XMLCOMMAND><OBJECTID>3000</OBJECTID><OBJECTSERVERID>BTL-1</OBJECTSERVERID><OBJECTTYPE>43</OBJECTTYPE><OBJECTFLAGS>0</OBJECTFLAGS><RASPICONNECTSERVERVERSIONNUMBER>3.0</RASPICONNECTSERVERVERSIONNUMBER><RESPONSE><![CDATA[INVALID RASPICONNECT CODE]]></RESPONSE></XMLCOMMAND></XMLRESPONSES>
192.168.2.106:53419 - - [08/Jul/2014 22:46:53] "HTTP/1.1 POST /raspi" - 200 OK
Any idea what can be wrong?
Thanks in advance,
Peter
My Local.py file below.
#!/usr/bin/python
# Filename: Local.py
# MiloCreek JS MiloCreek
# RaspiPeter (PiFace section)
# Version 1.0 March 12, 2014
#
# Local Execute Objects for RasPiConnect
# to add Execute objects, modify this file
#
#
# This Local.py file will allow you to monitor and control each Input and Output of the PiFace module fitted on the Rasberry Pi.
# Use L-000 up to L-007 as LED indicator to monitor each of the digital inputs 0 - 7.
# Use B-0 up to B-7 as Action Button to switch ON output 0 - 7
# Use B-00 up to B-70 as Action Button to switch OFF output 0 - 7
# Use FB-00 up to FB-07 as Feedback Action Button to control output 0 - 7.
# Use L-00 up to L-07 as LED indicator to monitor output 0 - 7 (note: you need to create a text file for each output!).
# Simply create a text file here: "/home/pi/RasPiConnectServer/relay0state.txt" for relay 0; "relay1state.txt" for relay 1; etc.
# This file only should have a number in it "1" or "0". Does not matter what you start with.
# It will take the status of the Digital Output when it changes.
# The M-0 up to M-2 are the Voltmeter objects that will display the Temperature of the 3 digital temperature sensors type DB18B20.
# The BTL-1 will provide "text" history of the various "actions".
# 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
BUBBLE_TABLE_VIEW_LIVE_UITYPE = 43
# system imports
import sys
import subprocess
# PiFace import
import piface.pfio as pfio
pfio.init()
# RasPiConnectImports
import Config
import Validate
import BuildResponse
import os
import glob
import time
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
#this "objectName" line below is important for the Feedback Button functionality!
objectName = element.find("./OBJECTNAME").text
objectFlags = element.find("./OBJECTFLAGS").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
# object Type match
if (objectType == FEEDBACK_ACTION_BUTTON_UITYPE):
if (Config.debug()):
print "FEEDBACK_ACTION_BUTTON_UITYPE of %s found" % objectServerID
#****************************************************************************************
# FB-00 - turn on relay0)
if (objectServerID == "FB-00"):
#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
responseData = "XXX"
if (objectName is None):
objectName = "XXX"
lowername = objectName.lower()
if (lowername == "relay0 on"):
pfio.digital_write(0,1) #turn on
# create some textfiles that only contain a "0" or a "1" and place them in a folder referring to.
f = open("/home/pi/RasPiConnectServer/relay0state.txt", "w") # the file will be opened
f.write("1") # the value "1" will be written to match the output state of the "relay0"
f.close() # the file will be closed again
f = open("/home/pi/RasPiConnectServer/bubblelog.txt", "w") # the file will be opened
f.write("relay0 switched on") # this text "relay0 switched on" should be displayed in the bubble table LIVE object.
f.close() # the file will be closed again
responseData = "relay0 off"
responseData = responseData.title()
elif (lowername == "relay0 off"):
pfio.digital_write(0,0) #turn off
f = open("/home/pi/RasPiConnectServer/relay0state.txt", "w")
f.write("0")
f.close()
f = open("/home/pi/RasPiConnectServer/bubblelog.txt", "w") # the file will be opened
f.write("relay0 switched off") #
f.close() # the file will be closed again
responseData = "relay0 on"
responseData = responseData.title()
else:
lowername = "relay0 on"
pfio.digital_write(0,1) #turn off
f = open("/home/pi/RasPiConnectServer/relay0state.txt", "w")
f.write("0")
f.close()
f = open("/home/pi/RasPiConnectServer/bubblelog.txt", "w") # the file will be opened
f.write("relay0 switched off") #
f.close() # the file will be closed again
responseData = lowername.title()
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#****************************************************************************************
# object Type match
if (objectType == SINGLE_LED_DISPLAY_UITYPE):
if (Config.debug()):
print "SINGLE_LED_DISPLAY_UITYPE of %s found" % objectServerID
#****************************************************************************************
# L-000 sends back the current state of the PiFace digital input "0"
if (objectServerID == "L-000"):
#check for validate request
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
# read PiFace digital input
try:
inputstate= pfio.digital_read(0)
#relaystate = f
except IOError as e:
inputstate = 0
if (inputstate == 0):
ledoutput = 5
else:
ledoutput = 2
responseData = "%i" % ledoutput
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#****************************************************************************************
# L-001 sends back the current state of the PiFace digital input "1"
if (objectServerID == "L-001"):
#check for validate request
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
# read PiFace digital input
try:
inputstate= pfio.digital_read(1)
#relaystate = f
except IOError as e:
inputstate = 0
if (inputstate == 0):
ledoutput = 5
else:
ledoutput = 2
responseData = "%i" % ledoutput
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#****************************************************************************************
# L-00 sends back the current state of the relay0
if (objectServerID == "L-00"):
#check for validate request
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
# read from relay0 state file
try:
f = open("/home/pi/RasPiConnectServer/relay0state.txt", "r")
tempString = f.read()
f.close()
relaystate = int(tempString)
except IOError as e:
relaystate = 0
if (relaystate == 0):
ledoutput = 5
else:
ledoutput = 2
responseData = "%i" % ledoutput
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#****************************************************************************************
# L-01 sends back the current state of the relay1
if (objectServerID == "L-01"):
#check for validate request
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
# read from relay1 state file
try:
f = open("/home/pi/RasPiConnectServer/relay1state.txt", "r")
tempString = f.read()
f.close()
relaystate = int(tempString)
except IOError as e:
relaystate = 0
if (relaystate == 0):
ledoutput = 5
else:
ledoutput = 2
responseData = "%i" % ledoutput
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#****************************************************************************************
if (objectType == ACTION_BUTTON_UITYPE):
if (Config.debug()):
print "ACTION_BUTTON_UITYPE of %s found" % objectServerID
# B-0 - activate relay PiFace (switch it "ON")
if (objectServerID == "B-0"):
#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
pfio.digital_write(0,1)
f = open("/home/pi/RasPiConnectServer/relay0state.txt", "w")
f.write("1")
f.close()
# B-00 - de-activate relay PiFace (switch it "OFF")
if (objectServerID == "B-00"):
#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
pfio.digital_write(0,0)
f = open("/home/pi/RasPiConnectServer/relay0state.txt", "w")
f.write("0")
f.close()
# B-1 - activate relay PiFace
if (objectServerID == "B-1"):
#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
pfio.digital_write(1,1)
f = open("/home/pi/RasPiConnectServer/relay1state.txt", "w")
f.write("1")
f.close()
# B-10 - de-activate relay PiFace
if (objectServerID == "B-10"):
#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
pfio.digital_write(1,0)
f = open("/home/pi/RasPiConnectServer/relay1state.txt", "w")
f.write("0")
f.close()
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#**************************************************************************************
# The VOLTMETER UITYPE object will display the Temperature of a DS18B20 digital temperature sensor
# This set-up is prepared for readout of 3 temperature sensors, but can be expanded if required.
if (objectType == VOLTMETER_UITYPE):
if (Config.debug()):
print "VOLTMETER_UITYPE of %s found" % objectServerID
# normal response requested
os.system('modprobe w1-gpio')
os.system('modprobe w1-therm')
base_dir = '/sys/bus/w1/devices/'
def read_temp_raw(device_file):
f = open(device_file, 'r')
lines = f.readlines()
f.close()
return lines
def read_temp(device_file):
lines = read_temp_raw(device_file)
while lines[0].strip()[-3:] != 'YES':
time.sleep(0.2)
lines = read_temp_raw(device_file)
equals_pos = lines[1].find('t=')
if equals_pos != -1:
temp_string = lines[1][equals_pos+2:]
temp_c = float(temp_string) / 1000.0
return temp_c
#**********************************************************************************************
# The M-0 is Temperature sensor #1
#M-0 is the DS18B20 temperature
if (objectServerID == "M-0"):
#check for validate request
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
device_folder = glob.glob(base_dir +'28*')[0]
device_file = device_folder + '/w1_slave'
temp_c = read_temp(device_file)
responseData = "%3.1f" % temp_c
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
# The M-1 is Temperature sensor #2
#M-1 is the DS18B20 temperature
if (objectServerID == "M-1"):
#check for validate request
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
device_folder = glob.glob(base_dir +'28*')[1]
device_file = device_folder + '/w1_slave'
temp_c = read_temp(device_file)
responseData = "%3.1f" % temp_c
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
# The M-2 is Temperature sensor #3
#M-2 is the DS18B20 temperature
if (objectServerID == "M-2"):
#check for validate request
if (validate == "YES"):
outgoingXMLData += Validate.buildValidateResponse("YES")
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
device_folder = glob.glob(base_dir +'28*')[2]
device_file = device_folder + '/w1_slave'
temp_c = read_temp(device_file)
responseData = "%3.1f" % temp_c
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#******************************************************************************************************
#
# BTL-1 Bubble Log
if (objectServerID == "BTL-1"):
#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
responseData =""
# not validate request, so execute
# note that python is in the main directory for this call, not the local directory
try:
f = open("/home/pi/RasPiConnectServer/bubblelog.txt", "r")
tempString = f.read()
f.close()
os.remove("/home/pi/RasPiConnectServer/bubblelog.txt")
except IOError as e:
tempString = ""
responseData = tempString
print "responseData =", responseData
outgoingXMLData += BuildResponse.buildResponse(responseData)
outgoingXMLData += BuildResponse.buildFooter()
return outgoingXMLData
#******************************************************************************************************
else:
# invalid RaspiConnect Code
outgoingXMLData += Validate.buildValidateResponse("NO")
outgoingXMLData += BuildResponse.buildFooter()
if (Config.debug()):
print outgoingXMLData
return outgoingXMLData
insert code here