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

Community
  • 1
  • 1
ArthurP
  • 117
  • 1
  • 2
  • 10
  • 2
    Sure this is possible, with AJAX plus serverside Python, e.g. [Flask](http://flask.pocoo.org) or [bottle.py](http://bottlepy.org). You can send arbitrary data from and to the website, delay should be unnoticeable if everything is running on one host. – L3viathan Apr 22 '15 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. – Hugo Sousa Apr 22 '15 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. – liamness Apr 22 '15 at 13:08
  • I would prefer to make a small web app and use the broweser's JS engine. Check out [flask+ajax](http://flask.pocoo.org/docs/0.10/patterns/jquery) for a quickstart. – shaunakde Apr 22 '15 at 13:30

0 Answers0