Beispiel #1
0
 def reset_node(self, node, default_resources={}):
     """Reset a node: clear the current resource and reinitialize them."""
     node.clear_resources()
     node.set_resource_value('protocol', self.PROTOCOL)
     for resource, value in default_resources.items():
         node.set_resource_value(resource, value)
     self.send_to_broker(Message.reset_node(node.uid))
     self.discover_node(node)
Beispiel #2
0
 def handle_coap_check(self, address, reset=False):
     """Handle check message received from coap node."""
     node = CoapNode(address)
     node.check_time = time.time()
     if node not in self.nodes:
         # This is a totally new node: create uid, initialized cached node
         # send 'new' node notification, 'update' notification.
         node_uid = str(uuid.uuid4())
         self.nodes.update({
             node: {
                 'uid': node_uid,
                 'data': {
                     'ip': address,
                     'protocol': PROTOCOL
                 }
             }
         })
         self._on_message_cb(Msg.new_node(node_uid))
         self._on_message_cb(Msg.update_node(node_uid, "ip", address))
         self._on_message_cb(Msg.update_node(node_uid, "protocol",
                                             PROTOCOL))
         self.discover_node(node, node_uid)
     elif reset:
         # The data of the node need to be reset without removing it. This
         # is particularly the case after a reboot of the node or a
         # firmware update of the node that triggered the reboot.
         node_uid = self.nodes[node]['uid']
         self.nodes[node]['data'] = {}
         self.nodes[node]['data'].update({
             'ip': address,
             'protocol': PROTOCOL
         })
         self._on_message_cb(Msg.reset_node(node_uid))
         self.discover_node(node, node_uid)
     else:
         # The node simply sent a check message to notify that it's still
         # online.
         data = self.nodes.pop(node)
         self.nodes.update({node: data})
Beispiel #3
0
def test_reset_node():
    serialized = Message.reset_node('1234')

    assert serialized == Message.serialize({'type': 'reset', 'uid': '1234'})