Help with creating a HTTPs poll plugin (unifi)

Python and python framework

Moderator: leecollings

Post Reply
jammiejammie
Posts: 21
Joined: Thursday 09 October 2014 16:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Help with creating a HTTPs poll plugin (unifi)

Post 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 ?
User avatar
Dnpwwo
Posts: 820
Joined: Sunday 23 March 2014 9:00
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Melbourne, Australia
Contact:

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

Post by Dnpwwo »

@jammiejammie,

Not yet I'm afraid, it is on the list though
The reasonable man adapts himself to the world; the unreasonable one persists to adapt the world to himself. Therefore all progress depends on the unreasonable man. George Bernard Shaw
jammiejammie
Posts: 21
Joined: Thursday 09 October 2014 16:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by jammiejammie »

allright, thanx!

I will put this one in the fridge for now, will pick it up as soon as HTTPS is added.
jammiejammie
Posts: 21
Joined: Thursday 09 October 2014 16:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by jammiejammie »

I'm wondering if there is an update regarding https compatibility of the python plugin.
edwin
Posts: 11
Joined: Wednesday 30 November 2016 15:21
Target OS: Linux
Domoticz version:
Contact:

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

Post 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
Recent beta (git) on Arch Linux | Dashticz v2 (git) | RFLink 46.0 | Ikea Trådfri | P1 Smart Meter
jammiejammie
Posts: 21
Joined: Thursday 09 October 2014 16:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post 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.
mivo
Posts: 80
Joined: Friday 21 April 2017 8:58
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Czechia
Contact:

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

Post 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
My toys:
Raspberry Pi 3 + UPS PIco HV3.0 A Stack
Minibian (Raspbian Jessie) + Domoticz beta
RFLink 433 Gateway, 1wire DS18B20 temp sensors (GPIO)
RaZberry module + 2x Comet Z-Wave + Z-wave socket
---
Plugins: WeMo Switch, UPS PIco HV3.0A on GitHub
jammiejammie
Posts: 21
Joined: Thursday 09 October 2014 16:35
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

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

Post by jammiejammie »

Well....
I want to use the python plugin framework for this, so i can't use the python https requests for this.
mivo
Posts: 80
Joined: Friday 21 April 2017 8:58
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Czechia
Contact:

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

Post 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 ;)
My toys:
Raspberry Pi 3 + UPS PIco HV3.0 A Stack
Minibian (Raspbian Jessie) + Domoticz beta
RFLink 433 Gateway, 1wire DS18B20 temp sensors (GPIO)
RaZberry module + 2x Comet Z-Wave + Z-wave socket
---
Plugins: WeMo Switch, UPS PIco HV3.0A on GitHub
Paint
Posts: 10
Joined: Tuesday 11 July 2017 15:47
Target OS: -
Domoticz version:
Contact:

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

Post 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....
mivo
Posts: 80
Joined: Friday 21 April 2017 8:58
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Czechia
Contact:

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

Post 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
 
My toys:
Raspberry Pi 3 + UPS PIco HV3.0 A Stack
Minibian (Raspbian Jessie) + Domoticz beta
RFLink 433 Gateway, 1wire DS18B20 temp sensors (GPIO)
RaZberry module + 2x Comet Z-Wave + Z-wave socket
---
Plugins: WeMo Switch, UPS PIco HV3.0A on GitHub
Paint
Posts: 10
Joined: Tuesday 11 July 2017 15:47
Target OS: -
Domoticz version:
Contact:

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

Post 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
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest