# import mywifi from machine import Timer # import esp_mqtt import struct import os import time class Client(): def __init__(self): self.data = os.urandom(1) def push(self): self.data=os.urandom(1) print("upload:", self.data) class Test(): def __init__(self) -> None: temp = struct.unpack('!BBBB', os.urandom(4)) print(temp) self.timer = Timer(-1) print("self", self) self.client = Client() # # 每 2000ms 定时回调一次 self.upload_data() self.timer.init(period=2000, mode=Timer.PERIODIC, callback=self.publish_timer_callback) self.count = 0 def publish_timer_callback(self, timer): self.count += 1 print("upload:", self.count) print("self", self.client) self.client.push() print("self.client") print("self.timer:", self.timer) test_ob = Test()