Hi I just bought raspberry pi since I found it very interesting.I want to know how from a circuitry (push button to print 1,2,3 or 4) can be displayed to the web server or somewhere in the computer to store.
For the video of circuitry and codes is getting form here: http://www.youtube.com/watch?v=q_NvDTZIaS4 but I edited a little bit to the code to print 1 or 2 respectively for each button if I have 2 for example.
Then I use putty to connect to the raspberry pi wirelessly then running the program in root so putty black screen would show 1 or 0 if I press the respective push button.
Now I was wondering how to send these output datas to the web server or some where to store in the pc.
So in conclusion when I press the button that suppose to display a 4, it will display in the webserver for e.g. Then press another button to display 3 so it will display 4 3 in the webserver and so on and so forth.
I did see a tut from How do I send data from the Raspberry Pi to the PC about webpy but its manual and send like"hello woorld" which was typed and not from the output of python scripts. I'm not really good with codes it'll be a great help if the tut is specific,easy example/video.TY
2 Answers
One way to do it might be to use install LAMP on your Pi to use it as a webserver. Then, write a Python script to listen for button presses. When it detects a button press, it could edit /var/www/index.html
(the default homepage),or any other file you want it to. To edit html, check this StackOverflow post.
To make this accessible over the Web, the best way is to plug in to your router with Ethernet, give it a static IP (as detailed here), and then set up port forwarding on your router to your Pi. Then, to access it, go to your network's public IP from any device not on the network. It should display index.html
.
Good Luck!
Edit: Here's a link to the tutorial I used to set up LAMP; http://www.instructables.com/id/Turning-your-Raspberry-Pi-into-a-personal-web-serv/
Edit2: Working on the python script, in the meantime run these in a terminal to install the Python GPIO control (I'm not sure if you already have this installed, but I'm just being on the safe side).
$sudo apt-get update
$sudo apt-get install python-dev
$sudo apt-get install python-rpi.gpio
Edit3:
from time import sleep
import RPi.GPIO as GPIO
from sys import exit
GPIO.setmode(GPIO.BCM)
GPIO.setup(22, GPIO.IN)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.IN)
while True:
try:
if (GPIO.input(22) == True):
index = open('/var/www/index.html','a')
index.write('<br>1')
index.close()
if (GPIO.input(23) == True):
index = open('/var/www/index.html','a')
index.write('<br>2')
index.close()
if (GPIO.input(24) == True):
index = open('/var/www/index.html','a')
index.write('<br>3')
index.close()
if (GPIO.input(25) == True):
index = open('var/www/index.html','a')
index.write('<br>4')
index.close()
sleep(.01)
except KeyboardInterrupt:
exit()
This assumes the 4 buttons are on pins 22, 23, 24, and 25 respectively, and that the file where you want this to show up is at /var/www/index.html
.
In theory, every time one of the buttons is pressed, it will print the number of the button along with a <br>
tag to the document. There's lots of different things you can do with this basic code, like making it wipe the document when the script starts, or making it run at startup.
Disclaimer:
Part 1: I borrowed some code from here and here. I also used the pinout diagram here.
Part 2: I haven't done much Python coding in a while, so if you catch any errors in my code, please edit this answer or leave a comment!
Again, Good Luck!
-
-
I can give you a tutorial right now on setting up LAMP; If I have time later I'll go into more detail on the necessary Python.– evamvidFeb 18, 2014 at 22:39
It sounds like you're 80% of the way there, you just need to link the bits together.
Instead of just outputting a "3" or a "4", you need to remember the previous button numbers. One way would be to hold a string (and append to it), another would be to hold a list of integers and add integers to the list.
Then in your webpy script you wouldn't return the same fixed string each time, but you'd return either the string you've remembered, or a string made from your integer list. Try doing this bit first, before you link it up to the GPIO pins, just return a string which is different each time.