You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.1KB

  1. from csms12 import CSMS12
  2. import network
  3. import socket
  4. import time
  5. def printloop():
  6. csms12 = CSMS12()
  7. while True:
  8. print(csms12.getInterval())
  9. time.sleep_ms(500)
  10. def connect():
  11. sta_if = network.WLAN(network.STA_IF)
  12. if not sta_if.isconnected():
  13. print('connecting to network...')
  14. sta_if.active(True)
  15. sta_if.connect('<ssid>', '<psk>')
  16. while not sta_if.isconnected():
  17. pass
  18. print('network config:', sta_if.ifconfig())
  19. def disableAP():
  20. ap_if = network.WLAN(network.AP_IF)
  21. ap_if.active(False)
  22. def server():
  23. addr = socket.getaddrinfo('0.0.0.0', 80)[0][-1]
  24. sensor = CSMS12()
  25. s = socket.socket()
  26. s.bind(addr)
  27. s.listen(1)
  28. print('listening on', addr)
  29. while True:
  30. cl, addr = s.accept()
  31. print('client connected from', addr)
  32. cl_file = cl.makefile('rwb', 0)
  33. while True:
  34. line = cl_file.readline()
  35. if not line or line == b'\r\n':
  36. break
  37. cl.send(sensor.getInterval())
  38. cl.close()