Accessing serial port via CGI script

Prerequisites:

1. Install pyserial on RaspberryPi

2.Testing

    Saving following python CGI scripts to your CGI folder.

    Filename: shows.py

    #!/usr/bin/python
    import os
    ser = os.popen("sudo python stest.py").readlines() 
    # print "Content-Type: text/html"
    # print
    print ser[0]
    print ser[2]

    Filename: stest.py

    #!/usr/bin/python
    import serial
    serialport = serial.Serial("/dev/ttyAMA0",9600,timeout=0.5)
    serialport.write("\r")
    response = serialport.readlines(None)
    serialport.write("version\r")
    response = serialport.readlines(None)
    
    print response[1]
    print response[2]
    

    The python CGI script shows.py will acquire and return the Version Information of the Shell(This shell is a part of my real time operating system) which runs on the serial port of the STM32 MCU.
    CGIwithSerilPort