bskari / pi-rc

Turn your Raspberry Pi into a radio controller for RC toys.
GNU General Public License v2.0
139 stars 38 forks source link

Errors when running the control.html-site. #15

Open JensHendar opened 9 years ago

JensHendar commented 9 years ago

Been trying to get a car running through the control.html-site, but getting all kinds of errors (see attached image). Sometimes it works, sometimes it doesn't. I am running the control.html-file using a Tornado web server and visiting the site using my Mac. Maybe there is something with the encoding?

My json looks like this: { "name": "Driftin Cars 27 mhz", "description": "Bought for 99 crowns at Teknikmagasinet. 27.145 mhz.", "frequency": 27.145, "synchronization_burst_us": 1200, "synchronization_spacing_us": 400, "total_synchronizations": 4, "signal_burst_us": 400, "signal_spacing_us": 400,

"forward": 10,
"forward_left": 27,
"forward_right": 35,
"left": 57,
"reverse": 40,
"reverse_left": 51,
"reverse_right": 45,
"right": 65

}

screen shot 2015-05-08 at 13 26 31

bskari commented 9 years ago

Hi! And greetings from Reddit :smile:

I spent most of yesterday looking at this. I think the problem is related to continuation frames with WebSockets. I spent quite a while looking at the WebSocket RFC but got pretty lost. Then I figured I could try to implement a minimal webserver that only accepted POST requests, but that has the disadvantage of needing to use JSON-P to get around the same-site origin policy on the client end, and the server would need to negotiate a new TCP connection for every message, which seemed wasteful. It's also a lot different from my UDP version of the code.

I'm not sure what the best course of action now is. I think I might copy a more complete implementation of the WebSocket protocol into here, but that will probably increase the file size of pi_pcm.c a lot.

In the meantime, the interactive_control.py with Python and PyGame should be working. The pi_pcm program just listens for JSON formatted messages over UDP, so you could copy some of the example code from the interactive control to see what the JSON messages look like, and then manually send your own messages.

I saw you mentioned on Reddit taking the RC car apart; for cheap vehicles, I think hacking the H-bridge is probably the easiest route.

I'll try to look at this more this week. Thanks for the detailed report though! It helped a lot in figuring out what was happening.

JensHendar commented 9 years ago

And greetings to you!

Thanks for taking the time to answer my question. I'll take a look at the interactive_control.py and see if I can't implement something that works. If I have any luck I'll post back here to help others.