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.

43 lines
1.4 KiB

6 years ago
  1. #!/usr/bin/env python3
  2. print("[INFO]: Interpreter started")
  3. from ev3dev.core import *
  4. print("[INFO]: Imported ev3dev.ev3")
  5. import socket
  6. print("[INFO]: Imported socket")
  7. import os
  8. print("[INFO]: Imported os")
  9. import json
  10. print("[INFO]: Imported json")
  11. HOST = '0.0.0.0'
  12. PORT = 3131
  13. mjpeg_loc = "/home/robot/mjpeg-streamer/mjpeg-streamer-experimantal/mjpeg-streamer"
  14. os.spawnl(os.P_DETACH, ' -i "./input_uvc.so -f 15 -r 640x480" -o "./output_http.so -w ./www"')
  15. power = PowerSupply()
  16. with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
  17. try:
  18. s.bind((HOST, PORT))
  19. while True:
  20. s.listen()
  21. print("[INFO]: Listening...")
  22. conn, addr = s.accept()
  23. with conn:
  24. print('[INFO]: Connected by', addr)
  25. while True:
  26. try:
  27. data = {
  28. "battery_voltage":power.measured_volts,
  29. "current_drawn":power.measured_amps,
  30. "lat":31,
  31. "lng":39
  32. }
  33. conn.send((json.dumps(data, ensure_ascii=False)+"\n").encode('gbk'))
  34. except BrokenPipeError:
  35. print("[INFO]: Client disconnected")
  36. break
  37. except KeyboardInterrupt:
  38. s.close()