Esempio n. 1
0
from openstuder import SIAsyncGatewayClient, SIProtocolError, SIDeviceMessage


def on_error(error: SIProtocolError):
    print(f'Unable to connect: {error.reason()}')


def on_connected(access_level: str, gateway_version: str):
    print(
        f'Connected, access level = {access_level}, gateway runs version {client.gateway_version()}'
    )


def on_device_message(message: SIDeviceMessage):
    print(
        f'{message.timestamp}: [{message.access_id}.{message.device_id}] {message.message} ({message.message_id})'
    )


client = SIAsyncGatewayClient()
client.on_error = on_error
client.on_connected = on_connected
client.on_device_message = on_device_message
client.connect('localhost', background=False)

def on_connected(access_level: str, gateway_version: str):
    client.subscribe_to_properties(['demo.sol.11004', 'demo.inv.3136'])


def on_properties_subscribed(statuses: List[SIPropertySubscriptionResult]):
    for status in statuses:
        print(f'Subscribed to {status.id}, status = {status.status}')


def on_property_updated(id_: str, value: any):
    print(f'Property {id_} updated, value = {value}')


def on_properties_unsubscribed(statuses: List[SIPropertySubscriptionResult]):
    for status in statuses:
        print(f'Unsubscribed from {status.id}, status = {status.status}')


client = SIAsyncGatewayClient()
client.on_error = on_error
client.on_connected = on_connected
client.on_properties_subscribed = on_properties_subscribed
client.on_property_updated = on_property_updated
client.on_properties_unsubscribed = on_properties_unsubscribed
client.connect('localhost')
time.sleep(10)
client.unsubscribe_from_properties(['demo.sol.11004', 'demo.inv.3136'])
time.sleep(2)
from typing import List
from openstuder import SIAsyncGatewayClient, SIProtocolError, SIStatus, SIPropertyReadResult


def on_error(error: SIProtocolError):
    print(f'Unable to connect: {error.reason()}')


def on_connected(access_level: str, gateway_version: str):
    client.read_properties(['demo.sol.11004', "demo.inv.3136"])


def on_properties_read(results: List[SIPropertyReadResult]):
    for result in results:
        print(
            f'Property read, status = {result.status}, id = {result.id}, value = {result.value}'
        )
    client.disconnect()


client = SIAsyncGatewayClient()
client.on_error = on_error
client.on_connected = on_connected
client.on_properties_read = on_properties_read
client.connect('localhost', background=False)
def on_error(error: SIProtocolError):
    print(f'Unable to connect: {error.reason()}')


def on_connected(access_level: str, gateway_version: str):
    client.subscribe_to_property('demo.sol.11004')


def on_property_subscribed(status: SIStatus, id_: str):
    print(f'Subscribed to {id_}, status = {status}')


def on_property_updated(id_: str, value: any):
    print(f'Property {id_} updated, value = {value}')


def on_property_unsubscribed(status: SIStatus, id_: str):
    print(f'Unsubscribed from {id_}, status = {status}')


client = SIAsyncGatewayClient()
client.on_error = on_error
client.on_connected = on_connected
client.on_property_subscribed = on_property_subscribed
client.on_property_updated = on_property_updated
client.on_property_unsubscribed = on_property_unsubscribed
client.connect('localhost')
time.sleep(10)
client.unsubscribe_from_property('demo.sol.11004')
time.sleep(2)
Esempio n. 5
0
from openstuder import SIAsyncGatewayClient, SIAsyncGatewayClientCallbacks
import time

client = SIAsyncGatewayClient()


class MyAsyncCallbacks(SIAsyncGatewayClientCallbacks):
    def on_connected(self, access_level, gateway_version):
        client.subscribe_to_properties(['demo.inv.3136', 'demo.inv.3137'])
        print(f'CONNECTED, access_level={access_level}')

    def on_disconnected(self):
        print('DISCONNECTED')

    def on_error(self, reason):
        print(f'ERROR reason={reason}')

    def on_enumerated(self, status, device_count):
        print(f'ENUMERATED status={status}, count={device_count}')

    def on_description(self, status, id_, description):
        pass

    def on_property_read(self, status, property_id, value):
        print(
            f'PROPERTY READ status={status}, id={property_id}, value={value}')

    def on_properties_read(self, results):
        print(f'PROPERTIES READ')
        for result in results:
            print(
Esempio n. 6
0
from openstuder import SIAsyncGatewayClient, SIProtocolError


def on_error(error: SIProtocolError):
    print(f'Unable to connect: {error.reason()}')


def on_connected(access_level: str, gateway_version: str):
    print(
        f'Connected, access level = {access_level}, gateway runs version {client.gateway_version()}'
    )


host = 'localhost'
user = '******'
password = '******'

client = SIAsyncGatewayClient()
client.on_error = on_error
client.on_connected = on_connected
client.connect(host, user=user, password=password, background=False)
from openstuder import SIAsyncGatewayClient, SIProtocolError, SIStatus, SIDescriptionFlags


def on_error(error: SIProtocolError):
    print(f'Unable to connect: {error.reason()}')


def on_connected(access_level: str, gateway_version: str):
    client.describe('demo',
                    flags=SIDescriptionFlags.INCLUDE_DEVICE_INFORMATION
                    | SIDescriptionFlags.INCLUDE_PROPERTY_INFORMATION)


def on_description(status: SIStatus, id_: str, description: object):
    print(f'Description for {id_}, status = {status}')
    print(description)
    client.disconnect()


client = SIAsyncGatewayClient()
client.on_error = on_error
client.on_connected = on_connected
client.on_description = on_description
client.connect('localhost', background=False)
from openstuder import SIAsyncGatewayClient, SIProtocolError, SIStatus


def on_error(error: SIProtocolError):
    print(f'Unable to connect: {error.reason()}')


def on_connected(access_level: str, gateway_version: str):
    client.read_datalog('demo.inv.3136', limit=50)


def on_datalog_read_csv(status: SIStatus, id_: str, entries: int, csv: str):
    print(f'Read datalog for {id_}, status = {status}, entries = {entries}')
    with open('demo.inv.3136.csv', 'w') as file:
        file.write(csv)
    client.disconnect()


client = SIAsyncGatewayClient()
client.on_error = on_error
client.on_connected = on_connected
client.on_datalog_read_csv = on_datalog_read_csv
client.connect('localhost', background=False)
Esempio n. 9
0
from openstuder import SIAsyncGatewayClient, SIProtocolError, SIStatus


def on_error(error: SIProtocolError):
    print(f'Unable to connect: {error.reason()}')


def on_connected(access_level: str, gateway_version: str):
    client.enumerate()


def on_enumerated(status: SIStatus, device_count: int):
    print(f'Enumerated, status = {status}, device count = {device_count}')
    client.disconnect()


client = SIAsyncGatewayClient()
client.on_error = on_error
client.on_connected = on_connected
client.on_enumerated = on_enumerated
client.connect('localhost', background=False)
Esempio n. 10
0
from openstuder import SIAsyncGatewayClient, SIProtocolError


def on_error(error: SIProtocolError):
    print(f'Unable to connect: {error.reason()}')


def on_connected(access_level: str, gateway_version: str):
    print(
        f'Connected, access level = {access_level}, gateway runs version {client.gateway_version()}'
    )


host = 'localhost'

client = SIAsyncGatewayClient()
client.on_error = on_error
client.on_connected = on_connected
client.connect(host, background=False)