OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) OSPi interval program – ospi_addon problems

This topic contains 2 replies, has 0 voices, and was last updated by  LLMoon 6 years ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #22547

    LLMoon
    Member

    I am trying to add a custom page using the new ospi_addon stub that was added in July 10 version. Has anyone else successfully used this to add functionality to interval program? If the custom class is defined in the ospi.py file everything works fine, but moving it to ospi_addon.py creates errors.

    When accessing the custom page from a browser, I get errors that indicate my class (‘view_wellpressure’) is not found. Here’s what I see on the terminal:
    Starting main loop
    http://0.0.0.0:8080/
    192.168.1.18:58721 – – [22/Jul/2013 20:56:31] “HTTP/1.1 GET /” – 200 OK
    Traceback (most recent call last):
    File “/home/pi/OSPi/web/application.py”, line 239, in process
    return self.handle()
    File “/home/pi/OSPi/web/application.py”, line 230, in handle
    return self._delegate(fn, self.fvars, args)
    File “/home/pi/OSPi/web/application.py”, line 419, in _delegate
    cls = fvars[f]
    KeyError: u’view_wellpressure’

    I think my custom class is not found in fvars[]

    For completeness, here is the content of ospi_addon.py


    #!/usr/bin/python
    import ospi
    from smbus import SMBus

    #### Add any new page urls here ####
    ospi.urls.extend() # example: ()

    #### add new functions and classes here ####

    class view_wellpressure:
    """open well page"""
    def GET(self):
    wellpg = '< !DOCTYPE html>n'
    wellpg += data('meta')+'n'
    wellpg += 'n'
    wellpg += 'n'
    wellpg += ''
    return wellpg

    print "initializing sensor variables"

    bus = SMBus(1)
    SENSOR_ADDRESS = 0x48
    CH_PRESSURE = 0x01
    CH_WELLPOWER = 0x00

    def readPressure():
    bus.write_byte(SENSOR_ADDRESS,CH_PRESSURE) #set the channel
    time.sleep(0.01)
    result = bus.read_byte(SENSOR_ADDRESS) #throw away first byte
    result = bus.read_byte(SENSOR_ADDRESS)
    result = (0.388*result) - 9.32 #calculate pressure using slope .388
    return int(result)

    def readWellPower():
    bus.write_byte(SENSOR_ADDRESS,CH_WELLPOWER) #set the channel
    time.sleep(0.01)
    result = bus.read_byte(SENSOR_ADDRESS) #throw away first byte
    result = bus.read_byte(SENSOR_ADDRESS)

    if result > 100:
    result = "ON"
    else:
    result = "OFF"
    return result

    I appreciate any advice, as I’m relatively new to Python and Javascript. Learning alot from this project and this forum!

    #24903

    paintycan
    Participant

    It was missing from the examples, but you need to include the file name in the ospi.urls.extend statement. It should look like this:

    ospi.urls.extend()

    That worked for me, at least.

    #24904

    djagerif
    Participant

    Also, if you want to reference something back in the ospi.py script then do the following:

    custpg += ‘n’

    #24905

    LLMoon
    Member

    Thanks very much, that resolved the errors and page is loading properly. Seems quite obvious now. I was treating python import like a C “include” statement, and forgot that objects need to be referenced to their source module.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

OpenSprinkler Forums Hardware Questions OpenSprinkler Pi (OSPi) OSPi interval program – ospi_addon problems