Page 1 of 1

Help with creating a HTTPs poll plugin (unifi)

Posted: Tuesday 02 May 2017 16:43
by jammiejammie
Hi Guys,

I'm trying to get a python plugin going. I need to poll a webpage that returns a JSON string that i need to parse.
I'm polling the status page of an Unifi controller and need to parse te json status page.

I used the http template from the wiki. But changing the URL to the unificontroller page results in status -1.
Does this framework support HTTPS ?

Re: Help with creating a HTTPs poll plugin (unifi)

Posted: Monday 08 May 2017 2:48
by Dnpwwo
@jammiejammie,

Not yet I'm afraid, it is on the list though

Re: Help with creating a HTTPs poll plugin (unifi)

Posted: Monday 08 May 2017 8:14
by jammiejammie
allright, thanx!

I will put this one in the fridge for now, will pick it up as soon as HTTPS is added.

Re: Help with creating a HTTPs poll plugin (unifi)

Posted: Monday 26 June 2017 20:11
by jammiejammie
I'm wondering if there is an update regarding https compatibility of the python plugin.

Re: Help with creating a HTTPs poll plugin (unifi)

Posted: Thursday 29 June 2017 10:09
by edwin
Hi @jammiejammie,

If you have node-red installed, you can easily create a very crude proxy by tying together a http input, request and response. You would expose a local link like http://localhost:1880/myproxydata to data gathered from a https server.

Cheers,

Edwin

Re: Help with creating a HTTPs poll plugin (unifi)

Posted: Sunday 09 July 2017 18:51
by jammiejammie
Well all i would need is a little work around that handles the ssl offloading.

Or... would it be possible to use the tcp socket plugin type and build the ssl layer inside the plugin? I'm not sure if the ssl is in the tcp layer or not.

Re: Help with creating a HTTPs poll plugin (unifi)

Posted: Monday 10 July 2017 8:42
by mivo
Hi,

for simple HTTPS requests you can sure use standard Python module like urllib.request:
https://docs.python.org/3.4/library/url ... ib.request

Re: Help with creating a HTTPs poll plugin (unifi)

Posted: Tuesday 11 July 2017 11:14
by jammiejammie
Well....
I want to use the python plugin framework for this, so i can't use the python https requests for this.

Re: Help with creating a HTTPs poll plugin (unifi)

Posted: Wednesday 12 July 2017 8:39
by mivo
I am using urllib.request in my plugin for WeMo switch, becasue plugin framework Connection method is not suitable for WeMo - WeMo drops connection few seconds after HTTP request.

So you can wait until HTTPS will be developed, develop yourself, or use workaround ;)

Re: Help with creating a HTTPs poll plugin (unifi)

Posted: Wednesday 12 July 2017 18:06
by Paint
I too have tried to create an HTTPs plugin in Python for ThinkEco's (mymodlet.com) interface to control my AC units. I have the 3 versions of the python script working with their API for status and control of the units, using urllib.request, Requests, and http (urllib2 for python3). All of the scripts work fine standalone, but dont work in the Domoticz plugin framework (Requests, as most of you know wont even load).

I think we sadly need to wait for HTTPs to be supported by Domoticz before we can move ahead. Otherwise, I need to create external LUA/Python scripts that control virtual switches....

Re: Help with creating a HTTPs poll plugin (unifi)

Posted: Thursday 13 July 2017 16:13
by mivo
Just to be sure - created simple plugin. Only opens page in onStart function and parse <title> element from it. Runs also from command line.

Code: Select all

#!/usr/bin/python3
#
# HTTPS test Python Plugin Example
#
# Author: mivo
#
"""
<plugin key="test-web" name="Test SSL web Python Plugin">
    <params>
        <param field="Address" label="Address" width="200px" required="true" default="www.google.com" />
        <param field="Mode6" label="Debug" width="75px">
            <options>
                <option label="True" value="Debug" />
                <option label="False" value="Normal" default="true" />
            </options>
        </param>
    </params>
</plugin>
"""

#import Domoticz - imported on end of file - if not started from command line
import urllib.request
from urllib.parse import quote

def onStart():

    Domoticz.Heartbeat(60)
    if Parameters["Mode6"] == "Debug":
        Domoticz.Debugging(1)

    url = Parameters["Address"]

    with urllib.request.urlopen('https://' + url) as f:
        output = f.read(500).decode("utf-8")

        Domoticz.Log("HTTPS " + url + " page TITLE: " + _extract(output, "title"))

# Generic helper functions

def _extract(XML, tagName):
    startTag = '<%s>' % (tagName)
    endTag = '</%s>' % (tagName)
    startPos = XML.find(startTag)
    endPos = XML.find(endTag, startPos+1)
    if ((startPos == -1) or (endPos == -1)):
        return "'"+tagName+"' not found in supplied XML"
    return XML[startPos+len(startTag):endPos]

# Command line function

def main():
    print("Started from command line")
    print("*" * 30 + "\n")

    url = "www.google.com"

    with urllib.request.urlopen('https://' + url) as f:
        output = f.read(500).decode("utf-8")
        print("output Quoted:\n", quote(output))
        print("*" * 30 + "\n")
        print("output:\n", output)
        print("*" * 30 + "\n")

        print("HTTPS " + url + " page TITLE: ", _extract(output, "title"))

if __name__ == '__main__':
    main()
else:
    #import Domoticz - if not started from command line
    import Domoticz
 

Re: Help with creating a HTTPs poll plugin (unifi)

Posted: Friday 14 July 2017 15:37
by Paint
Yes, urllib.request seems to work but I can't get my Domoticz version of my script to properly grab the CookieJar from a login. I have a standalone py3 that leverages the same code from the command line and works fine.

Sent from my SM-G955U using Tapatalk