1

I want to do the following. I want to have a button on a HTML page that once It gets pressed a message is sent to some python script I'm running.

For example, once the button is pressed some boolean will turn true, we will call the boolean bool_1. Then that boolean is sent to my python code, or written to a text file. Then in my python code I want to do something depending on that value. Is there a way to do this? Ive been looking at many thing but they haven't worked. I know that in javascript you can't write a text files because of security issues. My python code is constantly running, computing live values from sensors.

2
  • Are you going to run this code on the raspberry pi, or on the computer connected to the raspberry pi? Commented Oct 11, 2015 at 0:15
  • both the web server ( mini-httpd) and the python code are running on the pi. Commented Oct 11, 2015 at 0:44

3 Answers 3

1

The easiest way I can think of is to run a web server, maybe something simple like Flask. If the python script is running on your machine, you should run flask on your machine as well. The flask backend will receive the button press, and you can either put your sensor reading code inside one of the web server handlers, or you can choose some other method for your webserver to communicate with the running script (eg. sockets, text files, etc.).

Sign up to request clarification or add additional context in comments.

1 Comment

Ive tried flask. But I'm really new to this and need a lot of help
0

it's a web page, why don't you use php code? from index.php you can write your data on a txt file by pressing an html button (form or ajax code), sending everything you want with GET or POST and read it in the same file or in a -receiver.php- with:

<?php
$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = $_REQUEST['get_or_post_var'];
fwrite($myfile, $txt);
fclose($myfile);
?>

Your python code can read it line by line with readlines() function.

Comments

0

Maybe you can try to create a nodejs script that create a websocket. You ca connect to the websocket with python and so, you are able to send data from your website to nodejs and from nodejs to python in real-time.

Have a nice day

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.