TEA5767 FM radio digital tuner with Raspberry Pi 2 (part 3 of 3)

Previous: part 2 of 3

The Pi GPIO provides flexible mechanism of communicating with external digital device. I2C communication pins enables the bytecode read and write capabilities. By having several class functions in TEA5767 driver file, one can instantiate an object an create different type of user interfaces including a web page.

Several methods can be used to facilitate communication between python 3 file and a web interface. The simplest method is to utilise the built-in Python3 SimpleHttpServer module.

Open up a terminal and type:

$ cd /home/pi/Projects
$ python3 -m SimpleHTTPServer

By default your http server will start in port 8000. You will get the message:

Serving HTTP on 0.0.0.0 port 8000 ...

From a locally networked machine, open a browser and type the following address:

http://IPADDRESSOFYOURPI:8000

This will open index.html. This is the web page that serves communications with other Python 3 classes. You could use simple button with jquery and Ajax to send GET / POST requests to the corresponding Python file.

The barebone program look like this. You need to modify it so it calls the different class functions of the radio driver.

sudo nano radio_server.py

import sys
import BaseHTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
HandlerClass = SimpleHTTPRequestHandler
ServerClass = BaseHTTPServer.HTTPServer
Protocol = "HTTP/1.0"

if sys.argv[1:]:
port = int(sys.argv[1])
else:
port = 8000
server_address = ('127.0.0.1', port)

HandlerClass.protocol_version = Protocol
httpd = ServerClass(server_address, HandlerClass)

sa = httpd.socket.getsockname()
print "Serving HTTP on", sa[0], "port", sa[1], "..."
httpd.serve_forever()

For complete code listing, clone the following Github repository: https://github.com/LinuxCircle/tea5767.git

Where you can find rtea5767_tornado_server.py and the corresponding tea5767_tornado.html files.

Then run it with:

sudo python3 tea5767_tornado_server.py

And open the program via web browser: http://192.168.1.2:8888.

tea5767
 

(Visited 5,379 times, 1 visits today)

2 thoughts on “TEA5767 FM radio digital tuner with Raspberry Pi 2 (part 3 of 3)”

  1. Mike says:

    Hi. Thanks for publishing your work. It’s a fun project. I have the command console working, but I’m having trouble with the Web Interface. The web page will load but it’s not functional. I get the following error at the server end (see below). I was hoping you might be able help.

    Thanks,
    Mike.

    ERROR:tornado.application:Uncaught exception GET /favicon.ico (192.168.45.12)
    HTTPServerRequest(protocol=’http’, host=’192.168.45.125:8888′, method=’GET’, uri=’/favicon.ico’, version=’HTTP/1.1′, remote_ip=’192.168.45.12′, headers={‘Host’: ‘192.168.45.125:8888’, ‘Connection’: ‘keep-alive’, ‘Referer’: ‘http://192.168.45.125:8888/’, ‘Cache-Control’: ‘no-cache’, ‘User-Agent’: ‘Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36’, ‘Pragma’: ‘no-cache’, ‘Accept-Language’: ‘en-US,en;q=0.8’, ‘Accept-Encoding’: ‘gzip, deflate, sdch’, ‘Accept’: ‘*/*’})
    Traceback (most recent call last):
    File “/usr/local/lib/python3.4/dist-packages/tornado/web.py”, line 1445, in _execute
    result = yield result
    File “/usr/local/lib/python3.4/dist-packages/tornado/gen.py”, line 1008, in run
    value = future.result()
    File “/usr/local/lib/python3.4/dist-packages/tornado/concurrent.py”, line 232, in result
    raise_exc_info(self._exc_info)
    File “”, line 3, in raise_exc_info
    File “/usr/local/lib/python3.4/dist-packages/tornado/gen.py”, line 267, in wrapper
    result = func(*args, **kwargs)
    TypeError: get() missing 1 required positional argument: ‘path’
    ERROR:tornado.access:500 GET /favicon.ico (192.168.45.12) 43.82ms

  2. Mike says:

    Oops… Never mind. I just realized that your sample IP was in the various python scripts. After updating the IP everything works great. Thanks again for the fun project!

Comments are closed.