コード例 #1
0
def on_message(ws, message):

    def publish_operation_step_response(content, device_id, name, result, close_operation):
        step_response = operation_step_response(content, name, result, close_operation)
        step_response_as_json = json.dumps(step_response, indent=2)
        print 'Publishing {0} step status {1}...'.format(name, result)
        print step_response_as_json
        ws.send(step_response_as_json)
        print '...done'

    content = json.loads(message)
    print '===================================='
    print 'Request received with for device {0} with the following content'.format(device_id)
    print json.dumps(content, indent=2)
    operation_name = content['operation']['request']['name']
    print 'Operation name got: {0}'.format(operation_name)

    print 'Response:'
    response_as_json = ''
    if operation_name == 'REBOOT_EQUIPMENT':
        response_as_json = json.dumps(reboot(content), indent=2)
    elif operation_name == 'UPDATE':
        response_as_json = json.dumps(update(content, device_id, publish_operation_step_response), indent=2)
    elif operation_name == 'FIELD_DIAGNOSTIC':
        response_as_json = json.dumps(field_diagnostic(content), indent=2)
    elif operation_name == 'CONFIGREPORT':
        response_as_json = json.dumps(configreport(content), indent=2)

    print response_as_json
    # Message reception ACK
    ws.send(response_as_json)
def on_message(ws, message):

    def publish_operation_step_response(content, device_id, name, result, close_operation):
        step_response = operation_step_response(content, name, result, close_operation)
        step_response_as_json = json.dumps(step_response, indent=2)
        print 'Publishing {0} step status {1}...'.format(name, result)
        print step_response_as_json
        ws.send(step_response_as_json)
        print '...done'

    content = json.loads(message)
    print '===================================='
    print 'Request received with for device {0} with the following content'.format(device_id)
    print json.dumps(content, indent=2)
    operation_name = content['operation']['request']['name']
    print 'Operation name got: {0}'.format(operation_name)

    print 'Response:'
    response_as_json = ''
    if operation_name == 'REBOOT_EQUIPMENT':
        response_as_json = json.dumps(reboot(content), indent=2)
    elif operation_name == 'UPDATE':
        response_as_json = json.dumps(update(content, device_id, publish_operation_step_response), indent=2)

    print response_as_json
    # Message reception ACK
    ws.send(response_as_json)
コード例 #3
0
    def on_message(self, caller_mqtt_client, userdata, message):
        '''`on_message` callback implementation'''

        print(message.topic + ' ' + str(message.payload))

        def publish_operation_step_response(content, device_id, name, result, close_operation):
            '''MQTT specific callback function to publish responses asynchronously'''
            step_response = operation_step_response(
                content, name, result, close_operation)
            step_response_as_json = json.dumps(step_response, indent=2)
            print('Publishing {0} step status {1}...'.format(name, result))
            print(step_response_as_json)
            caller_mqtt_client.publish(ODM_PUBLISH_RESPONSE_TOPIC.format(
                device_id), step_response_as_json, qos=1)
            print('...done')

        content = json.loads(message.payload)
        print('====================================')
        print('Request received with for device {0} with the following content'.format(
            self._user))
        print(json.dumps(content, indent=2))
        operation_name = content['operation']['request']['name']
        print('Operation name got: {0}'.format(operation_name))

        print('Response:')
        response_as_json = ''
        if operation_name == 'REBOOT_EQUIPMENT':
            response_as_json = json.dumps(
                reboot(content, self._user), indent=2)
        elif operation_name == 'REFRESH_INFO':
            response_as_json = json.dumps(
                refresh_info(content, self._user), indent=2)
        elif operation_name == 'SET_DEVICE_PARAMETERS':
            response_as_json = json.dumps(
                set_device_parameters(content, self._user), indent=2)
        elif operation_name == 'UPDATE':
            response_as_json = json.dumps(
                update(content, self._user, publish_operation_step_response), indent=2)

        print(response_as_json)
        # Message reception ACK
        caller_mqtt_client.publish(self.ODM_PUBLISH_RESPONSE_TOPIC.format(
            self._user), response_as_json, qos=1)
def opengate_operations_handler(device_id):
    content = request.get_json(force=True)
    print "===================================="
    print "Request received with for device {0} with the following content".format(device_id)
    print json.dumps(content, indent=2)
    operation_name = content["operation"]["request"]["name"]
    print "Operation name got: {0}".format(operation_name)

    print "Response:"
    response_as_json = ""
    response_status = 201
    if operation_name == "REBOOT_EQUIPMENT":
        response_as_json = json.dumps(reboot(content), indent=2)
    elif operation_name == "UPDATE":
        response_as_json = json.dumps(update(content, device_id, publish_operation_step_response), indent=2)
    else:
        response_status = 400

    print response_as_json
    return response_as_json, response_status
コード例 #5
0
def on_message(caller_mqtt_client, userdata, message):
    '''`on_message` callback implementation'''

    print message.topic + ' ' + str(message.payload)

    def publish_operation_step_response(content, device_id, name, result,
                                        close_operation):
        '''MQTT specific callback function to publish responses asynchronously'''
        step_response = operation_step_response(content, name, result,
                                                close_operation)
        step_response_as_json = json.dumps(step_response, indent=2)
        print 'Publishing {0} step status {1}...'.format(name, result)
        print step_response_as_json
        caller_mqtt_client.publish(
            ODM_PUBLISH_RESPONSE_TOPIC.format(device_id),
            step_response_as_json,
            qos=1)
        print '...done'

    content = json.loads(message.payload)
    print '===================================='
    print 'Request received with for device {0} with the following content'.format(
        device_id)
    print json.dumps(content, indent=2)
    operation_name = content['operation']['request']['name']
    print 'Operation name got: {0}'.format(operation_name)

    print 'Response:'
    response_as_json = ''
    if operation_name == 'REBOOT_EQUIPMENT':
        response_as_json = json.dumps(reboot(content, device_id), indent=2)
    elif operation_name == 'UPDATE':
        response_as_json = json.dumps(update(content, device_id,
                                             publish_operation_step_response),
                                      indent=2)

    print response_as_json
    # Message reception ACK
    caller_mqtt_client.publish(ODM_PUBLISH_RESPONSE_TOPIC.format(device_id),
                               response_as_json,
                               qos=1)
コード例 #6
0
def opengate_operations_handler(device_id):
    content = request.get_json(force=True)
    print '===================================='
    print 'Request received with for device {0} with the following content'.format(
        device_id)
    print json.dumps(content, indent=2)
    operation_name = content['operation']['request']['name']
    print 'Operation name got: {0}'.format(operation_name)

    print 'Response:'
    response_as_json = ''
    response_status = 201
    if operation_name == 'REBOOT_EQUIPMENT':
        response_as_json = json.dumps(reboot(content), indent=2)
    elif operation_name == 'UPDATE':
        response_as_json = json.dumps(update(content, device_id,
                                             publish_operation_step_response),
                                      indent=2)
    else:
        response_status = 400

    print response_as_json
    return response_as_json, response_status