Esempio n. 1
0
    def post_input(self):

        # retrieve the dev instance
        dev_id = Util.get_id(self, "dev")
        if dev_id in device_instance:
            dev = device_instance[dev_id]
        else:
            dev = Util.get_diminishing_random_sensor_data(init_value=100,
                                                          half_life_time=30,
                                                          restart_time=120,
                                                          error_rate=0.01)
            dev.set_failure_rate(3600, 60)
            device_instance[dev_id] = dev

        # Send requests at Xth second of every minute.
#        Util.wait_until_xth_second(10)

        message = {
            "id": Util.get_id(self, "dev"),  # "dev-xxxxx-n"
            "value": dev.next_value(),
            "seq": dev.get_message_seq(),
            "time": Util.get_current_time()
        }
        json = Util.get_json_with_size(message, 1000)

        response = self.client.post(
            path="/api/v1/resources/topics//locust/input9/3",
            data=Util.get_json_with_size(message, 1000),
            auth=None,
            headers={
                "Authorization": "Bearer {}".format(Util.get_access_token()),
                "Content-Type": "application/json"
            },
            name=Util.get_class_name(self))
Esempio n. 2
0
    def post_input(self):

        # retrieve the dev instance
        dev_id = Util.get_id(self, "dev")
        if dev_id in device_instance:
            dev = device_instance[dev_id]
        else:
            dev = Util.get_cyclic_random_sensor_data(init_elapsed_time=0,
                                                     period=300,
                                                     min=-10,
                                                     max=45,
                                                     error_rate=0.1)
            device_instance[dev_id] = dev

        json_data = {
            "id": Util.get_id(self, "dev"),
            "value": dev.next_value(),
            "seq": dev.get_message_seq(),
            "time": Util.get_current_time()
        }

        response = self.client.post(
            path="/api/v1/resources/topics//locust/input10/2",
            data=Util.get_json_with_size(json_data, 1000),
            auth=None,
            headers={
                "Authorization": "Bearer {}".format(Util.get_access_token()),
                "Content-Type": "application/json"
            },
            name=Util.get_class_name(self))
Esempio n. 3
0
    def post_input(self):

        # retrieve the dev instance
        dev_id = Util.get_id(self, "dev")
        if dev_id in device_instance:
            dev = device_instance[dev_id]
        else:
            dev = Util.get_diminishing_random_sensor_data(init_value=100,
                                                          half_life_time=30,
                                                          restart_time=120,
                                                          error_rate=0.01)
            device_instance[dev_id] = dev

        json_data = {
            "id": Util.get_id(self, "dev"),
            "value": dev.next_int(),
            "op": "UPSERT",
            "seq": dev.get_message_seq(),
            "time": Util.get_current_time()
        }

        response = self.client.post(
            path="/api/v1/resources/topics//locust/input2",
            data=Util.get_json_with_size(json_data, 1000),
            auth=None,
            headers={
                "Authorization": "Bearer {}".format(Util.get_access_token()),
                "Content-Type": "application/json"
            },
            name=Util.get_class_name(self))
Esempio n. 4
0
    def post_input(self):

        # retrieve the dev instance
        dev_id = Util.get_id(self, "dev")
        if dev_id in device_instance:
            dev = device_instance[dev_id]
        else:
            dev = Util.get_simple_random_sensor_data(init_value=20,
                                                     min=0,
                                                     max=50,
                                                     increment=10,
                                                     error_rate=0.1)
            device_instance[dev_id] = dev

        # create json data
        json_data = {
            "id": dev_id,
            "value": dev.next_int(),
            "seq": dev.get_message_seq(),
            "time": Util.get_current_time()
        }

        # send data to target
        response = self.client.post(
            path="/api/v1/resources/topics//locust/input10/1",
            data=Util.get_json_with_size(json_data, 1000),
            auth=None,
            headers={
                "Authorization": "Bearer {}".format(Util.get_access_token()),
                "Content-Type": "application/json"
            },
            name=Util.get_class_name(self))
Esempio n. 5
0
    def pub(self):

        # retrieve the dev instance
        dev_id = Util.get_id(self.parent, "dev", Util.get_class_name(self))
        if dev_id in device_instance:
            dev = device_instance[dev_id]
        else:
            dev = Util.get_diminishing_random_sensor_data(init_value=100,
                                                          half_life_time=30,
                                                          restart_time=120,
                                                          error_rate=0.01)
            device_instance[dev_id] = dev

        # create json data
        json_data = {
            "id": dev_id,
            "value": dev.next_int(),
            "seq": dev.get_message_seq(),
            "time": Util.get_current_time()
        }

        # send data to target
        Util.publish_to_eventhubs("batterysensor",
                                  Util.get_json_with_size(json_data, 1000))

        events.request_success.fire(request_type='publish',
                                    name=Util.get_class_name(self),
                                    response_time=0,
                                    exception=None,
                                    response_length=1000)

        return
Esempio n. 6
0
 def on_start(self):
     # retrieve the dev instance
     dev_id = Util.get_id(self, "dev")
     if dev_id in device_instance:
         dev = device_instance[dev_id]
     else:
         dev = Util.get_simple_random_sensor_data(init_value=200, min=100, max=300, increment=10, error_rate=0.1)
         dev.set_failure_rate(20, 10)
         device_instance[dev_id] = dev
Esempio n. 7
0
    def pub(self):

        # retrieve the dev instance
        dev_id = Util.get_id(self.parent, "dev", Util.get_class_name(self))
        if dev_id in device_instance:
            dev = device_instance[dev_id]
        else:
            dev = Util.get_cyclic_random_sensor_data(init_elapsed_time=0, period=300, min=-10, max=45, error_rate=0.1)
            device_instance[dev_id] = dev

        # create json data
        json_data = {
            "id": dev_id,
            "value": dev.next_int(),
            "seq": dev.get_message_seq(),
            "time": Util.get_current_time()
        }

        # send data to target
        rc, mid = self.parent.client.publish("/locust/mqtt/1",
                                             Util.get_json_with_size(json_data, 1000),
                                             qos=0, retain=True)

        if rc:
            events.request_failure.fire(
                request_type='publish',
                name=Util.get_class_name(self),
                response_time=0,
                exception=rc,
                response_length=1000
            )
        else:
            events.request_success.fire(
                request_type='publish',
                name=Util.get_class_name(self),
                response_time=0,
                response_length=1000,
            )
        return
Esempio n. 8
0
        def delete(self):

            dev_id = Util.get_id(self.parent, "dev")
            dev = device_instance[dev_id]

            # create json data
            json_data = {
                "id": dev_id,
                "value": dev.next_int(),
                "seq": dev.get_message_seq(),
                "op" : "DELETE",
                "Time": Util.get_current_time()
            }

            # send data to target
            response = self.client.post(
                path="/api/v1/resources/topics//locust/input1",
                data=Util.get_json_with_size(json_data, 1000),
                auth=None,
                headers={"Authorization": "Bearer {}".format(Util.get_access_token()),
                         "Content-Type": "application/json"},
                name=Util.get_class_name(self)
            )