Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. import asyncio
  2. import websockets
  3. import subprocess
  4.  
  5.  
  6. async def client():
  7. async with websockets.connect('ws://localhost:8765') as websocket:
  8. id = input("Enter id:")
  9. id = "connect " + id
  10. await websocket.send(id)
  11. while True:
  12. rcvd_data = await websocket.recv()
  13.  
  14. if rcvd_data == "take-off":
  15. # command to execute
  16. cmd_command = "type A:\\Desktop\\test.txt"
  17. cmd_command = "rosservice call /dji_sdk/drone_task_control \"task: 4\""
  18. elif rcvd_data == "land":
  19. cmd_command = "rosservice call /dji_sdk/drone_task_control \"task: 6\""
  20.  
  21. process = subprocess.Popen(cmd_command.split(), shell=True, stdout=subprocess.PIPE)
  22. output, error = process.communicate()
  23. print(output.decode('utf-8'))
  24.  
  25. # data = input()
  26. # await websocket.send(data)
  27.  
  28. asyncio.get_event_loop().run_until_complete(client())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement