test.py 953 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. # import mywifi
  2. from machine import Timer
  3. # import esp_mqtt
  4. import struct
  5. import os
  6. import time
  7. class Client():
  8. def __init__(self):
  9. self.data = os.urandom(1)
  10. def push(self):
  11. self.data=os.urandom(1)
  12. print("upload:", self.data)
  13. class Test():
  14. def __init__(self) -> None:
  15. temp = struct.unpack('!BBBB', os.urandom(4))
  16. print(temp)
  17. self.timer = Timer(-1)
  18. print("self", self)
  19. self.client = Client()
  20. # # 每 2000ms 定时回调一次 self.upload_data()
  21. self.timer.init(period=2000, mode=Timer.PERIODIC, callback=self.publish_timer_callback)
  22. self.count = 0
  23. def publish_timer_callback(self, timer):
  24. self.count += 1
  25. print("upload:", self.count)
  26. print("self", self.client)
  27. self.client.push()
  28. print("self.client")
  29. print("self.timer:", self.timer)
  30. test_ob = Test()