Skip to content
This repository has been archived by the owner on May 18, 2022. It is now read-only.

[Q] Writing a HTML/Javascript to control the car from a browser #6

Open
ghost opened this issue Sep 11, 2014 · 5 comments
Open

[Q] Writing a HTML/Javascript to control the car from a browser #6

ghost opened this issue Sep 11, 2014 · 5 comments

Comments

@ghost
Copy link

ghost commented Sep 11, 2014

Hi again,

Now that I have PI-RC working, is it possible to send UDP packets to the pi_pcm server from a web browser using Javascript? If so, what contents does the UDP packet contain exactly? Can you provide an example? Is it also possible for you to provide a simple Javascript that sends the packet?

I'm asking because I've written a web page for my current project which allows me to control a robot from my Nintendo 3DS and I think it would be awesome to create a page that works with Pi-RC too.

Thanks again!

@bskari
Copy link
Owner

bskari commented Sep 12, 2014

That's a good idea, I like it! I'm pretty sure it's not possible to send UDP packets from JavaScript, but you should be able to send TCP packets using WebSockets. I have some time this weekend so I'll try to add TCP support to the server and add a sample page to the repository that you can use to send messages to the server to drive the var.

I have an example of what messages that you send should look like in the README. I think for your car, you'll want to do something similar to this (I've left out the web socket setup stuff though, I'll get a full example done this weekend. Also, I haven't tested any of this code.):

var forward = [
    // Synchronization burst
    {
        "frequency": 40.0,
        "dead_frequency": 26.995,
        "burst_us": 1200,
        "spacing_us": 400,
        "repeats": 4
    },
    // Command burst
    {
        "frequency": 40.0,
        "dead_frequency": 26.995,
        "burst_us": 400,
        "spacing_us": 400,
        "repeats": 11
    }
];
var message = JSON.stringify(forward);
socket.send(message);

@ghost
Copy link
Author

ghost commented Sep 13, 2014

Cool! Thanks!

@ghost
Copy link
Author

ghost commented Sep 13, 2014

Managed to create a PHP script that does it, fixed a issue with pi_pcm crashing after a few commands, too - it'd crash after receiving a specific .json command. Here's the script

@bskari
Copy link
Owner

bskari commented Sep 17, 2014

Okay, I added WebSocket support to the server. If you start it with ./pi_pcm --tcp, then you should be able to connect to the server by opening the control.html page with a browser (I tested Firefox and Chrome), entering in the control values or loading a JSON control file, and connecting to the server. Then just use the arrow keys.

There is a bug where occasionally the decoding of the message from the browser will fail and the server will ignore the message. I have no idea what's going on with that, but I'll try to fix it later. I'll leave this issue open in the mean time.

@ghost
Copy link
Author

ghost commented Sep 18, 2014

Oh wow! Thanks! I'll surely have fun with this nifty piece of html.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant