예제 #1
0
    def __init__(self, db=INFLUXDB_DBNAME):
        self.state = ObjState.ON
        self.connect_influxdb(db)
        self.sensor_sub = MQTTSubscriber(SENSOR_DETECTIONS)
        self.sensor_sub.subscribe_topic(self.handle_sensor_data)

        self.last_known_desired_pose = Pose()
        self.controller_sub = MQTTSubscriber(ROBOT_MOVE)
        self.controller_sub.subscribe_topic(self.handle_controller_data)
def test_sendJSON():
    """
    Tests subscriber and publisher wrapper with JSON messages
    """
    def assert_rx_message(client, userdata, message):
        global JSON_MSG_COUNT
        JSON_MSG_COUNT += 1
        jsonifyed = json.loads(message.payload.decode("utf-8")) 
        assert(jsonifyed == DATA)
        assert(ObjState(jsonifyed["state"]) == ObjState.ON)

    global JSON_MSG_COUNT
    TOPIC = 'test/json'
    DATA = {"sensor": "basic sensor", "id": 4, "state": ObjState.ON.value}

    pub = MQTTPublisher(TOPIC)
    pub.start_publish()
    
    sub = MQTTSubscriber(TOPIC)
    sub.subscribe_topic(assert_rx_message)
    time.sleep(0.025)

    rc = pub.publish_topic(json.dumps(DATA))
    assert(rc == MQTTPahoRC.SUCCESS)
    time.sleep(0.025)

    pub.disconnect()
    sub.disconnect()    
    assert(JSON_MSG_COUNT == 1)
예제 #3
0
    def __init__(self, robot, placement_pose, ID):
        super().__init__(robot, placement_pose, ID, SensorType.BASIC)
        self.state = ObjState.ON
        self.detection_topic = SENSOR_PREFIX + str(self.id) + DETECTION_SUFFIX
        self.detection_pub = MQTTPublisher(self.detection_topic)

        self.state_topic = SENSOR_PREFIX + str(self.id) + STATE_SUFFIX
        self.state_sub = MQTTSubscriber(self.state_topic)
        self.state_sub.subscribe_topic(self.control_state)

        self.disabled = False
    def __init__(self, robot, print_design):
        self.state = ObjState.ON

        self.sensor_sub = MQTTSubscriber(SENSOR_DETECTIONS)
        self.sensor_sub.subscribe_topic(self.handle_sensor_data)
        self.move_pub = MQTTPublisher(ROBOT_MOVE)
        self.state_sub = MQTTSubscriber(CONTROLLER_PREFIX + STATE_SUFFIX)
        self.state_sub.subscribe_topic(self.control_state)
        self.sensor_msg_count = 0
        self.sensor_msg_count_prev = 0

        self.closed_loop = True
        self.disabled = False

        self.print_design = print_design
        self.pattern_seq = 0
        self.print_completed = False

        self.robot_actual_pose = Pose()
        self.robot_previous_pose = Pose()
        self.robot_desired_pose = Pose()
        self.relative_move = Pose()
def test_simpleSubscriber():
    """
    Tests subscriber wrapper with mqtt publishers
    """
    def assert_rx_message(client, userdata, message):
        global SUB_MSG_COUNT
        SUB_MSG_COUNT += 1
        assert(message.payload.decode("utf-8") == DATA)

    global SUB_MSG_COUNT
    TOPIC = 'test/data'
    DATA = 'my message data here'
    simple_pub = mqtt.Client()
    simple_pub.connect(MOSQUITTO_SERVER, MOSQUITTO_PORT, MOSQUITTO_TIMEOUT)

    sub = MQTTSubscriber(TOPIC)
    assert(sub._connected == False)
    assert(sub._subscribed == False)
    sub.subscribe_topic(assert_rx_message)
    assert(sub._connected == True)
    assert(sub._subscribed == True)
    time.sleep(0.05)
    simple_pub.publish(TOPIC, DATA)

    sub.unsubscribe()
    assert(sub._connected == True)
    assert(sub._subscribed == False)
    simple_pub.publish(TOPIC, DATA)
    sub.resubscribe()
    assert(sub._connected == True)
    assert(sub._subscribed == True)

    sub.disconnect()
    time.sleep(0.01)
    assert(sub._connected == False)
    assert(sub._subscribed == False)
    simple_pub.disconnect()
    assert(SUB_MSG_COUNT == 1)
예제 #6
0
 def __init__(self):
     self.state = ObjState.ON
     self.move_sub = MQTTSubscriber(ROBOT_MOVE)
     self.move_sub.subscribe_topic(self.move)
     self.pose = Pose()