0

I'd like to know whether or not it is possible to send data from JavaScript to a Python script that is running and if anyone has any concrete examples. This all on the same host.

More specific:

All on RPi:

  • Python script listening for keys/input which it then responds to (sending it to Arduino via serial connection).

  • Web page listening for key presses, key releases, a slider, ... JS has to send this data to python.

Is it possible to send small things like a symbol (WASD) or a key code? It's also important that this doesn't have a lot of delay.

The only thing I found so far is this: Return data from html/js to python

4
  • 2
    Sure this is possible, with AJAX plus serverside Python, e.g. Flask or bottle.py. You can send arbitrary data from and to the website, delay should be unnoticeable if everything is running on one host. Commented Apr 22, 2015 at 12:39
  • You can create a connection and send/receive ajax requests, as @L3viathan said. Since you have dictionaries and JSON in both technologies, it is easier to write/read them. Commented Apr 22, 2015 at 12:46
  • Read up on REST services. Alternatively if you need to send very small pieces of information very often, it may be preferable to use websockets as this keeps the connection open. Commented Apr 22, 2015 at 13:08
  • I would prefer to make a small web app and use the broweser's JS engine. Check out flask+ajax for a quickstart. Commented Apr 22, 2015 at 13:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.