According to some posts, through the extension we could make the laptop a websocket server so that a robot can send data to it, for probably a real-time graph or something. What code should I write (in C++) to let the robot send data? Should I use something like the serial_link class to send requests in certain formats with the radio plugged? (Some said we should use HTTP POST but I couldn’t figure out how to do it on VEXos in C++.) It’s said that there’ll be an official project template but it doesn’t seem to be around.
And is there a more detailed documentation of the V5 API? I found the one foe VEXcode V5 Pro too brief.
Thank you in advance!
Yeah you should not have to worry about making post requests.
The websocket server takes any data the VEX Extension receives from the brain’s user port via a usb connection and forwards the data to any client websocket connections. So really any data that gets logged to the integrated terminal when you use printf()
or fwrite()
for example also gets sent to your client connection.
-
You’ll need to connect a controller or a brain to your computer via usb.
You can check your device connection by looking at the Interactive Terminal.
-
Open up a websocket connection in your external app. Some vanilla typescript code might look something like this, but really it just depends on what language/runtime you decide to use for your external app.
const PORT = '7071'; const HOST = 'localhost'; const deviceUrl = `ws://${HOST}:${PORT}/vexrobotics.vexcode/device`; let deviceWS = new WebSocket(deviceUrl);
Don’t forget to setup an event handler for received data.
deviceWS.onmessage = async (ev){ // Log data console.log(await ev.data.text()) };
If you were able to successfully open a websocket connection, you should see a similar message in the integrated terminal
-
In your c/c++ user program I would start out with something simple like printing “hello world” on loop:
while(1) { printf("Hello World\r\n"); vex::this_thread::sleep_for(1000); }
Once you start the program on the brain, you should see something like this in the integrated terminal:
The purple text tells you which connected VEX device is sending data to the Websocket Server. -
Check the data received event handler for you client websocket to verify your external application is receiving data from the Websocket server.
In my case, since I’m console logging the data , I checked the console log in the browser.
I do plan on releasing dual workspace example project with the next version of the VEX Extension, 0.6.0.
Currently VEX Command Help is the only additional documentation that is included with the VEX Extension.
The only other option is to look at the header file for a particular method
Thanks, that helps a lot! We would have a try when we have time.
We tested this several days ago. We created an HTML file attached a JS file containing the scripts above. We opened up the HTML file in Microsoft Edge and we got similar results, though the the purple “V5 Brain ( VEX )” only appeared once every time we run the program. Thanks for helping!
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.