max4260 / webiopi

Automatically exported from code.google.com/p/webiopi
0 stars 0 forks source link

[Server] Config file #4

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Add a config file :
- Login/Password
- Startup script
- Default state with default server

Original issue reported on code.google.com by tro...@trouch.com on 23 Nov 2012 at 3:46

GoogleCodeExporter commented 9 years ago
/etc/webiopi/passwd added that contains sha256(base64("user:password"))

Original comment by tro...@trouch.com on 29 Dec 2012 at 9:20

GoogleCodeExporter commented 9 years ago
Here is a config and server extension proposal

/etc/webiopi/webiopi.conf:
{{{
port = 8000
share_gpio = true

<apps>
    <header>
        <enabled>true</enabled>
        <auth-file>/etc/webiopi/passwd</script>
        <export>*</export>
    </header>

    <expert>
        <enabled>true</enabled>
        <auth-file>/etc/webiopi/passwd</script>
        <export>*</export>
    </expert>

    <custom>
        <context>myapp1</context>
        <docroot>/home/pi/webiopi/myapp1/htdocs</docroot>
        <welcome-file>index.html</welcome-file>
        <script>/home/pi/webiopi/myapp1/script.py</script>
        <auth-file>/home/pi/webiopi/myapp1/passwd</script>
    </custom>

    <custom>
        <context>myapp2</context>
        <docroot>/home/pi/webiopi/myapp2/htdocs</docroot>
        <welcome>myapp2.html</welcome>
        <export>0, 1, 3, 4</export>
        <values>0, 0, 0, 0</values>
    </custom>
</apps>
}}}

/home/pi/webiopi/myapp1/script.py:
{{{
def setup(): # called at server start, optional
    ...

def loop(): # called in webiopi loop, optional
    ...

def destroy(): # called at server stop, optional
    ...

def myMacro(): # automatically registered macro
    ...

def __myFunction__(): # __ denotes private functions
    ...
}}}

then, access with
Header : http://ip:port/(webiopi/)
MyApp1 : http://ip:port/(webiopi/)myapp1/
MyApp2 : http://ip:port/(webiopi/)myapp2/

Macro registering can be automated, using __ pre/suffix or decorators to denote 
privates functions.
Or it can be manual, using declarations in the config file.
I'm not sure about the syntax to sure, XML, JSON, something else...

Need advice

Original comment by tro...@trouch.com on 11 Jan 2013 at 7:44

GoogleCodeExporter commented 9 years ago
example script.py with decorator to denote macros :

def setup(): # called at server start, optional
    ...

def loop(): # called in webiopi loop, optional
    ...

def destroy(): # called at server stop, optional
    ...

@macro
def myMacro(): # automatically registered macro
    ...

def myFunction(): #  private functions
    ...

Original comment by tro...@trouch.com on 11 Jan 2013 at 8:02

GoogleCodeExporter commented 9 years ago
key/value pair based config file:

port = 8000
share_gpio = true

apps.header.enabled = true
apps.header.auth-file = /etc/webiopi/passwd
apps.header.export = *

apps.expert.enabled = true
apps.expert.auth-file = /etc/webiopi/passwd
apps.expert.export = *

apps.custom.1.context = myapp1
apps.custom.1.docroot = /home/pi/webiopi/myapp1/htdocs
apps.custom.1.welcome-file = index.html
apps.custom.1.script = /home/pi/webiopi/myapp1/script.py
apps.custom.1.auth-file = /home/pi/webiopi/myapp1/passwd

apps.custom.2.context = myapp2
apps.custom.2.docroot = /home/pi/webiopi/myapp2/htdocs
apps.custom.2.welcome-file = myapp2.html
apps.custom.2.export = 0, 1, 3, 4
apps.custom.2.values = 0, 0, 0, 0

Original comment by tro...@trouch.com on 11 Jan 2013 at 11:30

GoogleCodeExporter commented 9 years ago
Finally use INI file format, custom app support will be added later

[HTTP]
enabled = true
port = 8000
passwd-file = /etc/webiopi/passwd

[COAP]
enabled = true
port = 5683
multicast = true

Original comment by tro...@trouch.com on 20 Jan 2013 at 3:11

GoogleCodeExporter commented 9 years ago

Original comment by tro...@trouch.com on 26 Jan 2013 at 9:31