ABotelho23 / aacdnProject

This repository has been archived on GitHub and moved to GitLab. Please see the project on GitLab.com: https://gitlab.com/ABotelho23/aacdnProject
GNU Lesser General Public License v3.0
4 stars 3 forks source link

First voice command #49

Open ABotelho23 opened 6 years ago

ABotelho23 commented 6 years ago
async def createRequest(request_type, node_address, node_resource, userPayload):

    protocol = await Context.create_client_context()

    if (request_type == 'GET'):
        print("SENDING GET REQUEST")
        targetURI = 'coap://' + node_address + node_resource

        request = Message(code=GET, uri=targetURI)

        try:
            response = await protocol.request(request).response
        except Exception as e:
            return e
        else:
            return response.payload
    else:
        print("SENDING PUT REQUEST START")
        targetURI = 'coap://' + node_address + node_resource
        payloadEnc = userPayload.encode()

        request = Message(code=PUT, uri=targetURI, payload=payloadEnc)

        try:
            response = await protocol.request(request).response
        except Exception as e:
            return e
        else:
            return response.payload