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))
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))
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
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 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