ted
New Member
Posts: 1
|
Post by ted on Nov 11, 2013 8:25:10 GMT -8
Bought the app, installed it in my PI, looks like good to go. But when I went to configure the app I really couldn't find any instructions that made any sense to me. The statement "Building your own responses is easy" perhaps to the developer is true,but I assume you folks plan on making some $$ because "We can code this, others can't", and I'm one of those who can't, and instructions that Assume I know as much as the developers is not much help.
How about a "quick start" guide for the code challenged?
|
|
|
Post by SDL on Nov 11, 2013 8:53:10 GMT -8
Ted, Understand your confusion. A quick start guide makes sense to me. Did you look in the wiki at the examples there? www2.milocreek.com:8080/wiki/index.php/GettingStartedYou need to configure your server as shown in this section. The test your Pi server by: http://localhost:<Your port number>/Version example: OR On another computer (on the same local network), type into a web browser http://<your IP Address>:<Your port number>/Version IP Address>:<Your port number>/Version example: 192.168.1.130:9600/VersionTo find out your local IP number type: ifconfig If you see "RasPiConnectServer Version X.Y", then you are successfully running the RasPiConnectServer Let me know if you get to this point. Then we can take a look at the server itself. The Local.py file in specific. Best Regards, BP
|
|
|
Post by Tedhill3470 on Nov 12, 2013 12:13:45 GMT -8
Sorry, "good to go" meant I was able to see the "RasPiConnectServer Version 2.9" using the :9600/Version URL, and got the green LED on the Sever Report tab right away. I followed the getting started section. The instructions were very detailed and mostly clear.
no problems there.
it's just when I went to add the readings of a DS18b20 I have running on my PI that I got lost. I may have missed the correct reference, but the instructions refer to the examples buried deep in the RasPiConnectSever files on the Pi. I took one look at those and realized I had NO idea how to get that info into the raspiconnect app, much less into the web page as displayed on my IPad. That's where I got lost.
|
|
|
Post by SDL on Nov 13, 2013 8:50:54 GMT -8
Ted,
Got it. It's all in the Local.py file that you make your changes.
I'll do the following. Post your DS18b20 python code that takes a reading and I'll post a step-by-step tutorial how to set up the App and Local.py file.
Will that help?
Best regards,
BP
|
|
grandad
New Member
No Quite So Confused.
Posts: 30
Raspberry Pi: Yes
Other Device: 2nd Pi, PCs, iPad, Android Tablet and many, many gadgets!
|
Post by grandad on Feb 22, 2014 9:24:06 GMT -8
BP, Hi. I too am struggling with the creation of meaningful actions within the Pi. Communication / display from Raspi to iPad is fine, and I have a picture from the camera module displaying on the iPad. But that is only by using the "stock" ExecuteRemoteWebview.py and naming my camera image the same as the image within that file i.e. RovioImage.jpg (the picture is taken every minute using a crontab entry) Have you made any progress with the aformentioned tutorial as I have also used a DS18B20 in the past for temperature reading, and it would prove useful to have an insight into how to build that sort of input into the RasPiConnectServer. TIA Martin
|
|
|
Post by SDL on Feb 22, 2014 19:57:02 GMT -8
Martin, Have not written the aforementioned tutorial. Did you look at the documentation for LocalExample.py in the WIKI on the website? We have improved that. Based on your note, you are already 75% there. All your other changes will go into Local.py A great example of a huge Local.py with 95 controls can be found on github.com/projectcuracao/ This guy has got it! Do you have a python program that reads from your DS18B20? If not, look at this link: www.stuffaboutcode.com/2013/12/raspberry-pi-python-temp-sensor-ds18b20.htmlOnce you can read temperatures, you can post them to a meter, text control or many other things. Give me the code that you are using to read you DS18B20 and I will put it into a Local.py for you! Best regards, BP
|
|
ve7mkf
New Member
Posts: 13
Raspberry Pi: Yes
|
Post by ve7mkf on Feb 22, 2014 20:00:24 GMT -8
Hello "Grandad",
I have been doing some experimenting with the DS18B20 temperature sensor. Here is the relevant portion of my Local.py script. Maybe could move the modprobe lines somewhere else instead of every time we refresh, but it seems to work.
Hope this helps,
Mike
if (objectType == VOLTMETER_UITYPE):
if (Config.debug()): print "VOLTMETER_UITYPE of %s found" % objectServerID
#M-1 is DS18B20 temperature if (objectServerID == "M-1"):
#check for validate request if (validate == "YES"): outgoingXMLData += Validate.buildValidateResponse("YES") outgoingXMLData += BuildResponse.buildFooter() return outgoingXMLData
# normal response requested os.system('modprobe w1-gpio') os.system('modprobe w1-therm')
base_dir = '/sys/bus/w1/devices/' device_folder = glob.glob(base_dir + '28*')[0] device_file = device_folder + '/w1_slave'
def read_temp_raw(): f = open(device_file, 'r') lines = f.readlines() f.close() return lines
lines = read_temp_raw() while lines[0].strip()[-3:] != 'YES': time.sleep(0.2) lines = read_temp_raw() equals_pos = lines[1].find('t=') if equals_pos != -1: temp_string = lines[1][equals_pos+2:] temp_c = float(temp_string) / 1000.0
responseData = "%3.2f" % temp_c outgoingXMLData += BuildResponse.buildResponse(responseData) outgoingXMLData += BuildResponse.buildFooter() return outgoingXMLData
|
|
grandad
New Member
No Quite So Confused.
Posts: 30
Raspberry Pi: Yes
Other Device: 2nd Pi, PCs, iPad, Android Tablet and many, many gadgets!
|
Post by grandad on Feb 23, 2014 11:20:36 GMT -8
Martin, Have not written the aforementioned tutorial. Did you look at the documentation for LocalExample.py in the WIKI on the website? We have improved that. BP, Yes I have looked at the wiki, but I have to say most of this is very new to me and it appears a steep learning curve!Yes, I have read that project too - mostly gobble-de-gook to me I'm afraid! That is most kind BP. The program I used was written by me to encourage one of our grandchildren into Pi programming. It is extremely badly written and very basic, I am trying to get to grips with Python etc. but finding it difficult; probably too many senior moments methinks. Anyway, I have attached it for your perusal ) # Temperature monitoring project using Dallas DS18B20 devices and Raspberry Pi # Do these 2 commands before running this program # sudo modprobe w1-gpio # sudo modprobe w1.therm
#!/usr/bin/env python
from sys import stdout
# Define a function to print text to the screen at a specified position def print_there(x, y, text): stdout.write("\x1b7\x1b[%d;%df%s\x1b8" % (x, y, text)) stdout.flush()
# Place the basic text on the screen so that we don't have to do it every time print_there(1,1,"DS18B20 Temp. Sensors") print_there(2,1,"=====================") print_there(3,7," Deg. C at Sensor1") print_there(4,7," Deg. C at Sensor2") print_there(5,1,"=====================")
# Do what follows forever! while True:
# open a file to read first DS18B20 sensor # since I'm only using one sensor, the addresses are the same i.e.28-00xxxxxxxxx # if two are used, substitute the second sensor address as appropriate tfile = open("/sys/bus/w1/devices/28-0000040cc32f/w1_slave") # read the text in that file sensor1 = tfile.read() # now close that file tfile.close() # open a file to read second sensor tfile = open("/sys/bus/w1/devices/28-0000040cc32f/w1_slave") # read the text sensor2 = tfile.read() # close the file tfile.close() # split text with newline "\n" and choose 2nd line sensor1line = sensor1.split("\n")[1] sensor2line = sensor2.split("\n")[1] # split string using spaces " " and choose 10th word (zero count) tempdata1 = sensor1line.split(" ")[9] tempdata2 = sensor2line.split(" ")[9] # remove "t=" from word and convert to number t1 = float(tempdata1[2:]) t2 = float(tempdata2[2:]) # place decimal point in correct place t1 = t1 / 1000 t2 = t2 / 1000 # print results to screen print_there(3,0,t1) print_there(4,0,t2)
# continue ad infinitum or until ctrl/c is used
Mike,
Thank you for the code. I have tried to incorporate it into a Local.py file, but all I manage to do is crash the server. Steep learning curve as I keep mentioning!
Thanks again guys for your support, I'm sure I'll get there in the end. Martin
|
|
grandad
New Member
No Quite So Confused.
Posts: 30
Raspberry Pi: Yes
Other Device: 2nd Pi, PCs, iPad, Android Tablet and many, many gadgets!
|
Post by grandad on Feb 23, 2014 11:26:27 GMT -8
Ooooh! One more thing I meant to ask; I'm using the LocalExample.py and placing a button in the iPad app to play the sound (B-2) why does the sound play twice? I can only see one call to "aplay" in the code. Martin
|
|
|
Post by SDL on Feb 23, 2014 15:31:35 GMT -8
Grandad,
When you say you "Crash the server", could you capture and post the error? Post your Local.py file too.
Best regards,
BP
|
|
ve7mkf
New Member
Posts: 13
Raspberry Pi: Yes
|
Post by ve7mkf on Feb 23, 2014 21:36:47 GMT -8
Martin,
I noticed after I posted my example that the whitespace (tabs) must have got stripped when I copied and pasted it in. Just a guess, but this may be the cause of your crash. Here is a corrected copy with proper spacing.
Mike
if (objectType == VOLTMETER_UITYPE):
if (Config.debug()): print "VOLTMETER_UITYPE of %s found" % objectServerID
#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
# normal response requested os.system('modprobe w1-gpio') os.system('modprobe w1-therm')
base_dir = '/sys/bus/w1/devices/' device_folder = glob.glob(base_dir + '28*')[0] device_file = device_folder + '/w1_slave'
def read_temp_raw(): f = open(device_file, 'r') lines = f.readlines() f.close() return lines
lines = read_temp_raw() while lines[0].strip()[-3:] != 'YES': time.sleep(0.2) lines = read_temp_raw() equals_pos = lines[1].find('t=') if equals_pos != -1: temp_string = lines[1][equals_pos+2:] temp_c = float(temp_string) / 1000.0
responseData = "%3.2f" % temp_c outgoingXMLData += BuildResponse.buildResponse(responseData) outgoingXMLData += BuildResponse.buildFooter() return outgoingXMLData
|
|
ve7mkf
New Member
Posts: 13
Raspberry Pi: Yes
|
Post by ve7mkf on Feb 24, 2014 6:01:05 GMT -8
Martin,
One more thing. I didn't post the includes needed for the Local.py file. These are at the beginning of the file, near the top. Perhaps one of these is omitted, causing your crash:
# system imports import sys import subprocess import RPi.GPIO as GPIO import time import os import glob import picamera
For the DS18B20, you don't need picamera or RPi.GPIO, but I think the others need to be there.
Hope this helps,
Mike
|
|
grandad
New Member
No Quite So Confused.
Posts: 30
Raspberry Pi: Yes
Other Device: 2nd Pi, PCs, iPad, Android Tablet and many, many gadgets!
|
Post by grandad on Feb 24, 2014 9:06:13 GMT -8
Martin, One more thing. I didn't post the includes needed for the Local.py file. These are at the beginning of the file, near the top. Perhaps one of these is omitted, causing your crash: # system imports import sys import subprocess import RPi.GPIO as GPIO import time import os import glob import picamera For the DS18B20, you don't need picamera or RPi.GPIO, but I think the others need to be there. Hope this helps, Mike Mike, Thank you so much for sharing your code. I did try to implement your first post of the code, but I ran into my problem of being still very new to Linux and Python, so my attempts at inserting the "whitespace", which I knew should be there, was a disaster! However, with your later post, and the imports inserting those into a LocalExample.py file I have managed to get a temperature meter in the iPad app showing the ambient temperature as delivered by the DS18B20 - Yay!! Only thing is that the picture from my Pi camera module is not updating now - so I guess I've screwed something else up. I have to say that I really am not understanding what is going on yet, so I guess that I have a vast amount of reading to do.======= BP, The server crash (internal server error 504) must have been entirely due to my malformed LocalExample.py file. Below is the LocalExample.py file I am currently using. It is no more than the "default" plus Mike's code, and the sound changed to one of my own. One thing - does the server require LocalExample.py to be in the local directory, or can there just be a local.py file constructed by me? I notice that the server generates a .pyc file when started.#!/usr/bin/python # Filename: LocalExample.py # MiloCreek JS MiloCreek # Version 2.8 8/12/13 # # 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 import RPi.GPIO as GPIO import time import os import glob # import picamera
# RasPiConnectImports
import Config import Validate import BuildResponse
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
# object Type match if (objectType == ACTION_BUTTON_UITYPE):
if (Config.debug()): print "ACTION_BUTTON_UTYPE 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/dtmf.wav"]) responseData = "OK" outgoingXMLData += BuildResponse.buildResponse(responseData) outgoingXMLData += BuildResponse.buildFooter() return outgoingXMLData
if (objectType == VOLTMETER_UITYPE):
if (Config.debug()): print "VOLTMETER_UITYPE of %s found" % objectServerID
#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
# normal response requested os.system('modprobe w1-gpio') os.system('modprobe w1-therm')
base_dir = '/sys/bus/w1/devices/' device_folder = glob.glob(base_dir + '28*')[0] device_file = device_folder + '/w1_slave'
def read_temp_raw(): f = open(device_file, 'r') lines = f.readlines() f.close() return lines
lines = read_temp_raw() while lines[0].strip()[-3:] != 'YES': time.sleep(0.2) lines = read_temp_raw() equals_pos = lines[1].find('t=') if equals_pos != -1: temp_string = lines[1][equals_pos+2:] temp_c = float(temp_string) / 1000.0
responseData = "%3.2f" % temp_c 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 ""
Thanks again for the support guys, really appreciated 
|
|
ve7mkf
New Member
Posts: 13
Raspberry Pi: Yes
|
Post by ve7mkf on Feb 24, 2014 9:53:20 GMT -8
Martin, Glad to hear you got the temperature part working! It's always satisfying when things finally work  Regarding your problem with the camera image not updating, I have a similar problem here. I can take a new picture and the image is saved, but when I refresh the page on the RasPiConnect app, no new image is shown. I asked here about it, BP says there is a bug in the current version of the app that uses a cached version of the image: raspiconnect.boards.net/thread/117/remote-picture-webview-refreshingSince I posted my work-around with the meta-tags, it doesn't seem to work as well as I first thought. I can sometimes get a new image, but most of the time, only the old one is displayed. You can give it a try, but I guess the best will be to wait for a new version of the app. Mike EDIT: Hmmm. Tried the pi camera picture again this morning and it seems to be refreshing OK with: <META HTTP-EQUIV="CACHE-CONTROL" CONTENT="NO-CACHE"> I tried it a couple of days ago and couldn't get a new image. Strange... Will have to experiment some more 
|
|
grandad
New Member
No Quite So Confused.
Posts: 30
Raspberry Pi: Yes
Other Device: 2nd Pi, PCs, iPad, Android Tablet and many, many gadgets!
|
Post by grandad on Feb 24, 2014 14:31:46 GMT -8
Mike,
Yep, DS18B20 OK but I'm not using the same method as you to get a pic displayed. I have been using a "crontab" set to take a pic every minute between the hours of 7am and 6pm. But it seems to have stopped taking or updating the pic. I suppose it may be due to the cache as BP says, but I don't know enough about things yet to know where to put the "fix", and I just don't generally understand enough yet! I looked at the thread you mentioned, and have installed python-picam, taken pics by running a python script from the terminal, but have no idea how to create / modify what is necessary to get it working within RasPiConnectServer :=O
Ho-Hum. Lots to learn yet eh!
Martin
|
|