Posts: 1
Joined: Fri May 03, 2019 10:03 am

Sending data from a website

Fri May 03, 2019 10:10 am

I am currently working on a project using e-ink displays for indoor positioning.
Lets say a user enters the desired destination on a website or an app, what would be the best way to send this data to raspberry pi so it can start navigating which direction the user goes in.
thank you

Posts: 103
Joined: Mon Mar 25, 2019 11:08 am
Location: Earth
Contact: Website

Re: Sending data from a website

Sat May 04, 2019 5:19 am

Welcome to the forums.
I have a solution to what you want, but this is not the most efficient method.

Also i am assuming your raspberry pi is hosting the webpage through apache.
You will also need php.

If not, understand my methods and change the codes to suite your needs. You could always clear your queries here in the forums.

This is how i did it:

1) I am using python to read from the web and get data
You have to install requests module and time module(installed by default)

2) Copy the python code below and save it to any file

Code: Select all

import requests
import time
while True:
    link = requests.get("http://localhost:80/hello/text.txt")
    data = link.text

    if data == "on":

3)Now in your root directory of apache, create a folder called 'hello''(if you are using my code, exactly follow the names)
Create two files namely "index.php" and "text.txt"
Copy this code onto index.php

Code: Select all

if ( isset( $_POST["button"] ) ) {
$button = $_POST['button'];
echo "the button is $button";
$myfile = fopen('text.txt', 'w') or die("Unable to open file!");;
fwrite($myfile, $button);

<title>testing of control</title>
<form name="myform" method="post" action="index.php">
 <input type="radio" name="button" value="on"><label for="on"> ON</label><br>
 <input type="radio" name="button" value="off" checked><label for="off"> OFF</label><br>
 <input type="submit" value="Submit">
You will also want to edit the "text.txt". Open it and type one word that is "off"(without spaces or hitting enter)
4) Give php access to edit your file do this by entering this in your command line

Code: Select all

sudo chown -R www-data /var/www/html/hello/text.txt
(this will work if php user is www-data and your file path matches)
Check out this link from another forum ... -directory
The reply from Grant Miller helped me( the one which says '3 step solution')

5)Nearly done. Now open http://localhost/hello/...
you will see a webpage with on/off option. Choose your option and submit

Make sure that your python file be running this while and you see its response from server.

This is my own way of sending small data (really small) through internet. I do not know whether it exactly suits your needs
My website is at
Hope it runs (which it wont)

Return to “Networking and servers”