0

I'm trying to do this (seemingly) simple little project on my raspberry pi. I have a 16x2 LCD display, and I want to be able to input some text from a webpage and have it show up on the LCD.

I have this simple html webpage where I'm trying to get the input from a user:

<!DOCTYPE html>
<head>
    <title>Text Input</title>
</head>

<body>
    <form action="index.php">
        Line One:<br>
        <input type="text" name="line1"><br>
        Line Two:<br>
        <input type="text" name="line2"><br>
        <input type="submit" value="Submit">
    </form>

    <?php
    // runs script and inputs 2 lines
    ?>

</body>

And the python is fairly simple, where line1 and line2 would be replaced by whatever is input.

#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import os

line1 = "Line One"
line2 = "Line Two"

os.chdir('/home/pi/lcd')
import lcd
lcd.lcd_init()
lcd.lcd_byte(lcd.LCD_LINE_1, lcd.LCD_CMD)
lcd.lcd_string(line1,2)
lcd.lcd_byte(lcd.LCD_LINE_2, lcd.LCD_CMD)
lcd.lcd_string(line2,2)
lcd.GPIO.cleanup()

I just don't know how to get the information from the webpage to the python script. I know that from php, you can use exec() to do commands, but even then, I'm not sure how you would get the data from the command line into the python script.

  • Standard unix way: use command line arguments. See https://docs.python.org/2/library/sys.html#sys.argv for accessing command line args in python. – Stefano M Jun 07 '15 at 22:56

1 Answers1

0

I would suggest you look into how post and get values are retrieved in Python. I am not sure why you would even use PHP with this since the HTML form could post to your Python script and have it handle parsing the get/post parameters.

You can see how the get/post values are retrieved at this SO question: How are POST and GET variables handled in Python?

Whether you are using get or post is determined by the method in your form tag.

<form method="post" action="url/to/python/script.py">
Line One:<br/>
<input type="text" name="line1"><br>
Line Two:<br/>
<input type="text" name="line2"><br>
<input type="submit" value="Submit">
Community
  • 1
  • 1
Joseph Crawford
  • 1,470
  • 1
  • 15
  • 29
  • I know it's super late, but thank you very much for the info. I ended up using a text file as a middle man for the data between php and python. Maybe not the best solution, but a lot less complicated than anything I could find. – user3220404 Jul 08 '15 at 23:08