Closed Lin-jun-xiang closed 2 months ago
@abizovnuralem Maybe the data send not correctly complete event loop in first time call fun?
Hi, there is no problem controlling the dog in real-time with the joystick from PC, something is wrong with the data that you are sending to it.
Also if you don't provide a conn token to fun1 and fun2 , you only will have 1 connection running at the same time.
@abizovnuralem
Thanks your reply.
Is the conn token
can be any like the following?
conn = Go2Connection(
robot_ip=ROBOT_IP,
robot_num="0",
token="Go2",
on_open=lambda: logger.info("Data channel opened"),
on_validated=lambda _: logger.info("Robot validated"),
on_message=lambda msg, _, __: logger.info(f"Message received: {msg}")
)
async def go2_scrape():
conn.data_channel.send(
gen_command(ROBOT_CMD['Scrape'])
)
Obtaining security token Connecting to your device without a security token is possible and might allow a connection to be established. However, this method limits you to a single active connection at any time. To simultaneously use multiple clients, such as a WebRTC-based application and a phone app, a valid security token is necessary. This ensures secure, multi-client access to your device.
One way is to sniff the traffic between the dog and your phone. Assuming that you have Linux or Mac:
Run tinyproxy or any other HTTP proxy on your computer Set your computer's IP and port as HTTP proxy on your phone Run wireshark or ngrep on your box sniffing port 8081 like ngrep port 8081. Look for the token in the TCP stream after you connect your phone to the dog via the app The token looks like this in the request payload:
{ "token": "eyJ0eXAiOizI1NiJtlbiI[..]CI6MTcwODAxMzUwOX0.hiWOd9tNCIPzOOLNA", "sdp": "v=0\r\no=- ", "id": "STA_localNetwork", "type": "offer" } Another option is to obtain token via the /login/email endpoint.
curl -vX POST https://global-robot-api.unitree.com/login/email -d "email=
I extracted the
WebRTC
part for controllingGo2
(without ROS) but encountered the following issues:webrtc_driver.py
asyncio.run(connect())
finishes, the connection automatically closes:INFO:scripts.webrtc_driver:Connection state is closed
.nest_async()
, which resolved the automatic disconnection issue, but found that although fun1 and fun2 are executed correctly, Go2 has no response.What might be causing this issue? How can I ensure that different functions are called correctly without placing all commands in the same coroutine?