Exemplo n.º 1
0
def _start_ssdp():
    ssdp = SSDPServer()
    thread_ssdp = threading.Thread(target=ssdp.run, args=())
    thread_ssdp.daemon = True  # Daemonize thread
    thread_ssdp.start()
    ssdp.register(
        'local', 'uuid:{}::upnp:rootdevice'.format(discoverData['DeviceID']),
        'upnp:rootdevice',
        'http://{}:{}/device.xml'.format(config['tvhProxyHost'],
                                         config['tvhProxyPort']),
        'SSDP Server for tvhProxy')
Exemplo n.º 2
0
def startssdp(dvbtype):
	discover = getdeviceinfo.discoverdata(dvbtype)
	device_uuid = discover['DeviceUUID']
	if config.hrtunerproxy.debug.value:
		logger.info('Starting SSDP for %s, device_uuid: %s' % (dvbtype,device_uuid))
	local_ip_address = getIP()
	ssdp = SSDPServer()
	ssdp.register('local',
				  'uuid:{}::upnp:rootdevice'.format(device_uuid),
				  'upnp:rootdevice',
				  'http://{}:{}/device.xml'.format(local_ip_address,tunerports[dvbtype]))
	thread_ssdp = threading.Thread(target=ssdp.run, args=())
	thread_ssdp.daemon = True # Daemonize thread
	thread_ssdp.start()
Exemplo n.º 3
0
def startssdp(dvbtype):
    discover = getdeviceinfo.deviceinfo(dvbtype)
    device_uuid = discover[dvbtype]['DeviceUUID']
    print '[Plex DVR API] Starting SSDP for %s, device_uuid: %s' % (
        dvbtype, device_uuid)
    local_ip_address = getIP()
    ssdp = SSDPServer()
    ssdp.register(
        'local', 'uuid:{}::upnp:rootdevice'.format(device_uuid),
        'upnp:rootdevice',
        'http://{}:{}/device.xml'.format(local_ip_address,
                                         tunerports[dvbtype]))
    thread_ssdp = threading.Thread(target=ssdp.run, args=())
    thread_ssdp.daemon = True  # Daemonize thread
    thread_ssdp.start()
Exemplo n.º 4
0
    def __getattr__(self, attr):
        if attr is 'ssdp':
            from ssdp import SSDPServer
            self.ssdp = SSDPServer(self)
            return self.ssdp

        elif attr is 'http':
            from http import HTTPServer
            self.http = HTTPServer(self)
            return self.http

        elif attr is 'https':
            from http import HTTPServer
            self.https = HTTPServer(self, True)
            return self.https

        else:
            raise AttributeError("'%s' has no attribute %r" %
                                 (self.__class__.__name__, attr))
Exemplo n.º 5
0
def main():
    device_uuid = uuid.uuid4()
    local_ip_address = get_ip_address()
    web_server_port = 8088
    http_server = UPNPHTTPServer(web_server_port,
                                 friendly_name="Xeleum Xi-Fi Gateway",
                                 manufacturer="Xeleum Lighting",
                                 manufacturer_url='http://www.xeleum.com/',
                                 model_description='Xi-Fi Gateway',
                                 model_name="Xi-F Gateway",
                                 model_number="XRF001",
                                 model_url="http://www.xeleum.com",
                                 serial_number="XRF1234",
                                 uuid=device_uuid,
                                 presentation_url="index.html")
    http_server.start()

    ssdp_server = SSDPServer()
    ssdp_server.register(
        'local', 'uuid:{}::upnp:rootdevice'.format(device_uuid),
        'upnp:rootdevice',
        'http://{}:{}/description.xml'.format(local_ip_address,
                                              web_server_port))
    ssdp_server.start()

    XrfAPI.getInstance().start()
    app.run(debug=True, host='0.0.0.0', port=port, use_reloader=False)
Exemplo n.º 6
0
    def __init__(self, connection_type, mqtt_port):
        self.network_interface = connection_type
        self.device_uuid = uuid.uuid4()
        self.local_ip_address = self.__get_network_interface_ip_address(
            self.network_interface)
        self.http_server = UPNPHTTPServer(
            8088,
            friendly_name="Camera Test",
            manufacturer="L-IoT-ning",
            manufacturer_url='http://liotningshop.azurewebsites.net/',
            model_description='Pi Camera Test',
            model_name="PiCamera",
            model_number="3000",
            model_url="",
            serial_number="JBN425133",
            uuid=self.device_uuid,
            presentation_url=("tcp://{}:" + mqtt_port).format(
                self.local_ip_address))

        self.ssdp = SSDPServer()
        self.ssdp.register(
            'local', 'uuid:{}::upnp:rootdevice'.format(self.device_uuid),
            'upnp:rootdevice',
            'http://{}:8088/jambon-3000.xml'.format(self.local_ip_address))
Exemplo n.º 7
0
class SSDPGenerator:
    def __init__(self, connection_type, mqtt_port):
        self.network_interface = connection_type
        self.device_uuid = uuid.uuid4()
        self.local_ip_address = self.__get_network_interface_ip_address(
            self.network_interface)
        self.http_server = UPNPHTTPServer(
            8088,
            friendly_name="Camera Test",
            manufacturer="L-IoT-ning",
            manufacturer_url='http://liotningshop.azurewebsites.net/',
            model_description='Pi Camera Test',
            model_name="PiCamera",
            model_number="3000",
            model_url="",
            serial_number="JBN425133",
            uuid=self.device_uuid,
            presentation_url=("tcp://{}:" + mqtt_port).format(
                self.local_ip_address))

        self.ssdp = SSDPServer()
        self.ssdp.register(
            'local', 'uuid:{}::upnp:rootdevice'.format(self.device_uuid),
            'upnp:rootdevice',
            'http://{}:8088/jambon-3000.xml'.format(self.local_ip_address))

    def __get_network_interface_ip_address(self, interface='eth0'):
        """
        Get the first IP address of a network interface.
        :param interface: The name of the interface.
        :return: The IP address.
        """
        while True:
            if interface not in ni.interfaces():
                print('Could not find interface %s.' % (interface, ))
                exit(1)
            interface = ni.ifaddresses(interface)
            if (2 not in interface) or (len(interface[2]) == 0):
                print('Could not find IP of interface %s. Sleeping.' %
                      (interface, ))
                sleep(60)
                continue
            return interface[2][0]['addr']

    def server_start(self):
        thread.start_new_thread(self.http_server.start, ())
        thread.start_new_thread(self.ssdp.run, ())

    def server_close(self):
        self.http_server.shutdown()
        self.ssdp.shutdown()
        self.ssdp.unregister('uuid:{}::upnp:rootdevice'.format(
            self.device_uuid))
Exemplo n.º 8
0
    def __getattr__(self, attr):
        if attr is "ssdp":
            from ssdp import SSDPServer

            self.ssdp = SSDPServer(self)
            return self.ssdp

        elif attr is "http":
            from http import HTTPServer

            self.http = HTTPServer(self)
            return self.http

        elif attr is "https":
            from http import HTTPServer

            self.https = HTTPServer(self, True)
            return self.https

        else:
            raise AttributeError("'%s' has no attribute %r" % (self.__class__.__name__, attr))
Exemplo n.º 9
0
from ssdp import SSDPServer
from upnp_http_server import UPNPHTTPServer
import uuid
import logging

logger = logging.getLogger()
logger.setLevel(logging.DEBUG)

device_uuid = uuid.uuid4()

http_server = UPNPHTTPServer(
    8088,
    friendly_name="Bigfoot device",
    manufacturer="Yeti SL",
    manufacturer_url='https://getyeti.co/',
    model_description='Yeti Python appliance V1',
    model_name="Python",
    model_number="1",
    model_url="https://github.com/netbeast/bigfoot/python",
    serial_number="v1",
    uuid=device_uuid,
    presentation_url="http://localhost:5000/")
http_server.start()

ssdp = SSDPServer()
ssdp.register('local', 'uuid:{}::upnp:rootdevice'.format(device_uuid),
              'bigfoot:all', 'http://localhost:8088/python-v1.xml')
ssdp.run()
Exemplo n.º 10
0
class Upnpy(object):
    """A upnpy controller working either as a control-point or as devices root list
    Can be used to search remote device (get, search)
    Can be used to declare new devices devices['example']=Device(...)
    """

    def __init__(self, server_address=""):
        """Initialize Upnpy
        server_address (tring) : an optionnal address to bind connection to"""

        self.server_address = server_address

        import weakref

        self._subscriptions = weakref.WeakValueDictionary()
        self.devices = _RootList(self)

        self._stop = False
        import atexit

        atexit.register(self.clean)

    def __getattr__(self, attr):
        if attr is "ssdp":
            from ssdp import SSDPServer

            self.ssdp = SSDPServer(self)
            return self.ssdp

        elif attr is "http":
            from http import HTTPServer

            self.http = HTTPServer(self)
            return self.http

        elif attr is "https":
            from http import HTTPServer

            self.https = HTTPServer(self, True)
            return self.https

        else:
            raise AttributeError("'%s' has no attribute %r" % (self.__class__.__name__, attr))

    def search(self, target, timeout=2.0):
        """search for devices/services
        Returns a list of device/service when at least one matching is found
        
        Args:
          target (string) : a UPnP defined search target :
            - ssdp:all (or *) : for all devices and services
            - upnp:rootdevice : for all root devices
            - uuid:[uuid]     : for a particular device
            - [urn:domain:]{device,service}:type[:version] : for a device or service with the given type
                                domain default to schemas-upnp-org,
                                version to 1

          timeout (number, optionnal) : timeout for search (default to 5 seconds)"""

        from control import SearchHandler

        h = SearchHandler(self, target, timeout)
        self.add_handler(h)
        if not len(h.matches) and timeout:
            gevent.sleep(timeout)
        return h.matches

    def get(self, target, timeout=2.0):
        """search a device/service
        Returns when at least one matching devices is found

        target (string) : a UPnP defined search target or "*" for ssdp:all
        timeout (number) : an optionnal timeout (default to 5 seconds)"""

        matches = self.search(target, timeout / 2)
        if len(matches):
            return matches[0]
        else:
            raise KeyError("UPnP '%s' not found" % target)

    def serve_forever(self):
        gevent.wait()

    def add_handler(self, handler):
        self.ssdp.add_handler(handler)

    def stop(self):
        self.clean()
        self._stop = True

    def clean(self):
        for i in self.devices.keys():
            del self.devices[i]

        for s in self._subscriptions.values():
            s.unsubscribe()

        self.ssdp.clean()
Exemplo n.º 11
0
                             model_number="HPA250B",

                             model_url="https://www.honeywellpluggedin.com/air-purifiers/shop/honeywell-air-purifier-bluetooth-smart-controls",

                             serial_number="N/A",

                             uuid=device_uuid,

                             presentation_url="http://{}:5000/".format(local_ip_address))

http_server.start()

print "Server started"

ssdp = SSDPServer()

print "SSDP started"

ssdp.register('local',

              'uuid:{}::urn:schemas-upnp-org:device:hpa250b:1'.format(device_uuid),

              'urn:schemas-upnp-org:device:hpa250b:1',

              'http://{}:8090/hpa250b.xml'.format(local_ip_address))

print "SSDP registered"

ssdp.run()
Exemplo n.º 12
0
class Upnpy(object):
    """A upnpy controller working either as a control-point or as devices root list
    Can be used to search remote device (get, search)
    Can be used to declare new devices devices['example']=Device(...)
    """
    def __init__(self, server_address=''):
        """Initialize Upnpy
        server_address (tring) : an optionnal address to bind connection to"""

        self.server_address = server_address

        import weakref
        self._subscriptions = weakref.WeakValueDictionary()
        self.devices = _RootList(self)

        self._stop = False
        import atexit
        atexit.register(self.clean)

    def __getattr__(self, attr):
        if attr is 'ssdp':
            from ssdp import SSDPServer
            self.ssdp = SSDPServer(self)
            return self.ssdp

        elif attr is 'http':
            from http import HTTPServer
            self.http = HTTPServer(self)
            return self.http

        elif attr is 'https':
            from http import HTTPServer
            self.https = HTTPServer(self, True)
            return self.https

        else:
            raise AttributeError("'%s' has no attribute %r" %
                                 (self.__class__.__name__, attr))

    def search(self, target, timeout=2.0):
        """search for devices/services
        Returns a list of device/service when at least one matching is found
        
        Args:
          target (string) : a UPnP defined search target :
            - ssdp:all (or *) : for all devices and services
            - upnp:rootdevice : for all root devices
            - uuid:[uuid]     : for a particular device
            - [urn:domain:]{device,service}:type[:version] : for a device or service with the given type
                                domain default to schemas-upnp-org,
                                version to 1

          timeout (number, optionnal) : timeout for search (default to 5 seconds)"""

        from control import SearchHandler
        h = SearchHandler(self, target, timeout)
        self.add_handler(h)
        if not len(h.matches) and timeout:
            gevent.sleep(timeout)
        return h.matches

    def get(self, target, timeout=2.0):
        """search a device/service
        Returns when at least one matching devices is found

        target (string) : a UPnP defined search target or "*" for ssdp:all
        timeout (number) : an optionnal timeout (default to 5 seconds)"""

        matches = self.search(target, timeout / 2)
        if len(matches):
            return matches[0]
        else:
            raise KeyError("UPnP '%s' not found" % target)

    def serve_forever(self):
        gevent.wait()

    def add_handler(self, handler):
        self.ssdp.add_handler(handler)

    def stop(self):
        self.clean()
        self._stop = True

    def clean(self):
        for i in self.devices.keys():
            del self.devices[i]

        for s in self._subscriptions.values():
            s.unsubscribe()

        self.ssdp.clean()
Exemplo n.º 13
0
http_server = UPNPHTTPServer(
    8090,
    friendly_name="Air Mentor Pro 2",
    manufacturer="Air Mentor",
    manufacturer_url='https://www.air-mentor.com/web2017/?lang=en',
    model_description='Air Mentor Pro 2',
    model_name="Air Mentor",
    model_number="Air Mentor Pro 2",
    model_url="https://www.air-mentor.com/web2017/product/air_mentor_8096ap",
    serial_number="N/A",
    uuid=device_uuid,
    presentation_url="http://{}:5000/".format(local_ip_address))

http_server.start()

print "Server started"

ssdp = SSDPServer()

print "SSDP started"

ssdp.register(
    'local',
    'uuid:{}::urn:schemas-upnp-org:device:AirMentorPro2:1'.format(device_uuid),
    'urn:schemas-upnp-org:device:AirMentorPro2:1',
    'http://{}:8090/airmentorpro2.xml'.format(local_ip_address))

print "SSDP registered"

ssdp.run()