Example #1
0
class IoT_Device(TaskSet):
    def on_start(self):
        self.device_id = random.randint(1, 101)
        self.client_mqtt = MQTT_Client()

        self.client_mqtt.connect()

    @seq_task(1)
    @task(2)
    def loop(self):
        self.client_mqtt.loop()

    @seq_task(2)
    @task(1)
    def publish(self):
        self.client_mqtt.publishing()
Example #2
0
class IoT_Device(TaskSet):

    def on_start(self):
        self.device_id = cache.next_device_id()
        self.client_mqtt = MQTT_Client(self.device_id, filename_dir)
        self.client_mqtt.connect()

        self.init_time = 0.0

    @task
    def publish(self):
        if time.time() - self.init_time >= 30.0:
            self.init_time = time.time()
            self.client_mqtt.publishing(self.device_id)
            
        self.client_mqtt.loop(0.05)