async def request_events(ace_session): protocol = await Context.create_client_context() client = CoAPClient(client_id = CLIENT_ID, client_secret = CLIENT_SECRET, protocol = protocol ) events_response = await client.access_resource(session = ace_session, rs_url = self.url, endpoint = '/events') return multi_loads(events_response)
async def request(ace_session): protocol = await Context.create_client_context() client = CoAPClient(client_id = CLIENT_ID, client_secret = CLIENT_SECRET, protocol = protocol ) await client.upload_access_token(session = ace_session, rs_url = self.url, endpoint = '/authz-info')
async def request(ace_session, url): protocol = await Context.create_client_context() client = CoAPClient(client_id = CLIENT_ID, client_secret = CLIENT_SECRET, protocol = protocol ) data = cbor2.dumps({action.name: {'input': action.input}}) response = await client.post_resource(session = ace_session, rs_url = url, endpoint = '/actions/' + action.name, data = data) return response
async def request(ace_session, url): protocol = await Context.create_client_context() client = CoAPClient(client_id = CLIENT_ID, client_secret = CLIENT_SECRET, protocol = protocol ) data = cbor2.dumps({property_name: value}) response = await client.post_resource(session = ace_session, rs_url = url, endpoint = '/properties/' + property_name, data = data) return response
async def request(): protocol = await Context.create_client_context() client = CoAPClient(client_id = CLIENT_ID, client_secret = CLIENT_SECRET, protocol = protocol ) ace_session = await client.request_access_token(as_url = AS_URL, audience = AUDIENCE, scopes = SCOPES ) return ace_session
async def initialize(): protocol = await Context.create_client_context() client = CoAPClient(client_id=CLIENT_ID, client_secret=CLIENT_SECRET, protocol=protocol) # Request access token ace_session = await client.request_access_token(as_url=AS_URL, audience=AUDIENCE, scopes=SCOPES) # Upload token to RS await client.upload_access_token(session=ace_session, rs_url=RS_URL, endpoint='/authz-info') print(GREEN + 'POST /authz-info -> DONE.' + ENDC) return (client, ace_session)
async def main(): protocol = await Context.create_client_context() client = CoAPClient( client_id='ace_client_1', client_secret=b'ace_client_1_secret_123456', protocol=protocol ) # Request access token session = await client.request_access_token( as_url=AS_URL, audience="tempSensor0", scopes=["read_temperature", "post_led"] ) # Upload token to RS await client.upload_access_token(session, RS_URL, '/authz-info') # Access temperature resource response = await client.access_resource(session, RS_URL, '/temperature') print(f"Response: {response}")