from openstuder import SIGatewayClient, SIDescriptionFlags if __name__ == "__main__": # Establish connection. client = SIGatewayClient() client.connect('localhost') # Client/gateway information. print(f'CONNECTED: access_level = {client.access_level()}, gateway_version = {client.gateway_version()}') # Enumerate devices. status, count = client.enumerate() print(f'ENUMERATE -> ENUMERATED: status = {status}, count = {count}') # Retrieve description. status, id_, desc = client.describe(flags=SIDescriptionFlags.INCLUDE_ACCESS_INFORMATION | SIDescriptionFlags.INCLUDE_DEVICE_INFORMATION | SIDescriptionFlags.INCLUDE_PROPERTY_INFORMATION) print(f'DESCRIBE -> DESCRIPTION: status = {status}, id = {id_}, description={desc}') # Read property. status, id_, value = client.read_property('demo.inv.3136') print(f'READ PROPERTY -> PROPERTY READ: status = {status}, id = {id_}, value={value}') # Read properties. results = client.read_properties(['demo.inv.3136', 'demo.inv.3137']) for result in results: print(f'READ PROPERTIES -> PROPERTIES READ: status = {result.status}, id = {result.id}, value={result.value}') # Write property. status, id_ = client.write_property('demo.inv.1399') print(f'WRITE PROPERTY -> PROPERTY WRITTEN: status = {status}, id = {id_}')
from openstuder import SIGatewayClient, SIProtocolError host = 'localhost' client = SIGatewayClient() try: access_level = client.connect(host) except SIProtocolError as error: print(f'Unable to connect: {error.reason()}') quit(1) print( f'Connected, access level = {access_level}, gateway runs version {client.gateway_version()}' )
from openstuder import SIGatewayClient, SIProtocolError try: client = SIGatewayClient() client.connect('localhost') results = client.read_properties(['demo.sol.11004', 'demo.inv.3136']) for result in results: print( f'Read property {result.id}, status = {result.status}, value = {result.value}' ) except SIProtocolError as error: print(f'Error: {error.reason()}')
from openstuder import SIGatewayClient, SIProtocolError try: client = SIGatewayClient() client.connect('localhost') status, id_ = client.write_property('demo.inv.1399') print(f'Wrote property {id_}, status = {status}') except SIProtocolError as error: print(f'Error: {error.reason()}')
from openstuder import SIGatewayClient, SIProtocolError try: client = SIGatewayClient() client.connect('localhost') status, id_, entries, csv = client.read_datalog_csv('demo.inv.3136', limit=50) print(f'Read datalog for {id_}, status = {status}, entries = {entries}') with open('demo.inv.3136.csv', 'w') as file: file.write(csv) except SIProtocolError as error: print(f'Error: {error.reason()}')
from openstuder import SIGatewayClient, SIProtocolError host = 'localhost' user = '******' password = '******' client = SIGatewayClient() try: access_level = client.connect(host, user=user, password=password) except SIProtocolError as error: print(f'Unable to connect: {error.reason()}') quit(1) print( f'Connected, access level = {access_level}, gateway runs version {client.gateway_version()}' )
from openstuder import SIGatewayClient, SIProtocolError try: client = SIGatewayClient() client.connect('localhost') status, device_count = client.enumerate() print( f'Enumeration complete, status = {status}, device count = {device_count}' ) except SIProtocolError as error: print(f'Error: {error.reason()}')
type=int, default=None, help='Maximal number of value entries to query.') parser.add_argument( '-f', '--file', type=str, default=None, help='Filename to use, defaults to the property ID with .csv postfix.') parser.add_argument('property_id', type=str, help='ID of the property to download the data for.') args = parser.parse_args() # Create connection to gateway. client = SIGatewayClient() client.connect(args.host, args.port, args.user, args.password) # Query datalog values. status, property_id, count, data = client.read_datalog_csv( args.property_id, args.start, args.end, args.limit) # Check if the datalog could be retrieved. if status == SIStatus.SUCCESS: if count > 0: filename = args.file or f'{property_id}.csv' print( f'Received {count} values, writing them to file "{filename}"...' ) with open(filename, 'w') as file: file.write(data)
from openstuder import SIGatewayClient, SIProtocolError, SIDescriptionFlags try: client = SIGatewayClient() client.connect('localhost') status, id_, description = client.describe( 'demo', flags=SIDescriptionFlags.INCLUDE_DEVICE_INFORMATION | SIDescriptionFlags.INCLUDE_PROPERTY_INFORMATION) print(f'Description for {id_}, status = {status}') print(description) except SIProtocolError as error: print(f'Error: {error.reason()}')
from openstuder import SIGatewayClient, SIProtocolError try: client = SIGatewayClient() client.connect('localhost') status, properties = client.read_datalog_properties() print(f'Read datalog properties, status = {status}:') for property in properties: print(f' - {property}') client.disconnect() except SIProtocolError as error: print(f'Error: {error.reason()}')
default=None, help='End point to which to query for data.') parser.add_argument('-l', '--limit', type=int, default=None, help='Maximal number of value entries to query.') parser.add_argument('-f', '--file', type=str, default=None, help='Filename to use, defaults to messages.csv.') args = parser.parse_args() # Create connection to gateway. client = SIGatewayClient() client.connect(args.host, args.port, args.user, args.password) # Query messages. status, count, messages = client.read_messages(args.start, args.end, args.limit) # Check if the datalog could be retrieved. if status == SIStatus.SUCCESS: if count > 0: filename = args.file or 'messages.csv' print( f'Received {count} messages, writing them to file "{filename}"...' ) with open(filename, 'w') as file: for message in messages:
from openstuder import SIGatewayClient, SIProtocolError try: client = SIGatewayClient() client.connect('localhost') status, count, messages = client.read_messages() print(f'Read messages, status = {status}, count = {count}') for message in messages: print( f'{message.timestamp}: [{message.access_id}.{message.device_id}] {message.message} ({message.message_id})' ) except SIProtocolError as error: print(f'Error: {error.reason()}')
from openstuder import SIGatewayClient, SIProtocolError try: client = SIGatewayClient() client.connect('localhost') status, id_, count, properties = client.find_properties('*.*.3136') print( f'Found properties for {id_}, status = {status}, count = {count} : {properties}' ) except SIProtocolError as error: print(f'Error: {error.reason()}')