1

I started developing with the Raspberry Pi and it is so much fun!

As a learning project I want to build a ticket system.

So I bought some small LEDs and stuff to connect it and a 2D barcode scanner on eBay.

I'm planning to run the interface on the Raspberry Pi in Chrome, because I can easy handle a local database and sync it to an external one.

That does work, so I'm scanning a ticket, the scanner also performs an "enter", the ticket gets validated in the browser.

Now I want to control 2 LEDs, a green one if the ticket is valid and a red if the ticket isn't valid.

I can write a python script which triggers them, but how can execute the python script?

For understanding:

Chrome is running on the Raspberry Pi with Ubuntu, the webpage is also locally (it's just some HTML, CSS and JavaScript). So I have to trigger the python script locally not remotely.

Does somebody got a solution for that?

Maybe this question is easy... But I'm a totally Raspberry noob.

  • Are you running a web server, and if yes, which one? – Bex May 13 '16 at 9:20
  • I'm running a webserver for the external DB, which is hosted by Google. But for the local Database & interface i'm not running a webserver, because i'm just using some html, js & css @Bex – Leitwerk May 13 '16 at 9:25
  • So how does the Pi interface with the client? You state that the Pi is not the web server, so how does the Pi communicate with said web server? Can you please post some example code? – Mohammad Ali May 13 '16 at 20:59
  • The Pi is the Client. I'm running Ubuntu on the PI. There I have chrome opened. The barcode scanner is pasting the ticket code in a input field and javascript does the validating. Just true or false. At this point in code I want to trigger a local python script which changes the LED to green or red. – Leitwerk May 14 '16 at 12:32
0

If you need to run a script on your machine as a part of a web transaction to that machine, the easiest way to achieve that is probably to set up a web server, and use a technique called CGI, which makes the web server execute a script (or a binary) and send the resulting output to the client, rather than serving the content of the script itself.

Have a look at ngnix or apache for commonly used web servers that you can run on your pi.

2

As mentioned in the previous answer, some sort of web server software is needed.

As it's python I can recommand 'bottle' and 'flask' addons for python, these are python based web servers so play nice with python code.

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.