liveBook · Manning

Web application

As explained in Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi

A web application is software that provides interactive functionality through web technologies and network communication.

A web application can give a robot a browser-based control surface over a wired or Wi-Fi network. It lets a desktop or mobile operator send commands and view robot-provided information. section 6.0 section 6.1

Build the server in Python with Tornado: route a URL to a RequestHandler, listen on a port, and run the IOLoop. A handler can answer an HTTP GET request with JSON, or render an HTML template for the browser. section 5.5.1 section 6.3.1

Time service and page

Start with a handler that reads the robot server time. One version writes a timestamp dictionary as JSON; another renders basic.html with the timestamp, using a template directory and optional debug logging. Test the running service with curl. section 5.5.1 section 6.3.1

Listing 5.3 datews.py: Creating web service to report time on the robot server
#!/usr/bin/env python3
from datetime import datetime
from tornado.ioloop import IOLoop
from tornado.web import RequestHandler, Application
 
class MainHandler(RequestHandler):
    def get(self):
        stamp = datetime.now().isoformat()
        self.write(dict(stamp=stamp))
 
app = Application([('/', MainHandler)])
app.listen(8888)
IOLoop.current().start()

This complete Python service maps the root path to a GET handler, returns the current timestamp as JSON, listens on port 8888, and starts Tornado's event loop. section 5.5.1

Expand a control application incrementally:

  • Provide forward, backward, left, right, and spin actions, plus a no-operation action for browser-based network-performance measurement. section 6.4
  • Design large, spaced movement buttons that work with desktop mice and mobile touch screens without scrolling. section 6.4.2
  • Combine selectable snack buttons, a live camera stream, and robot actions that drive, push an item, and return to the start. section 11.4 section 11.5

Debug mode can be selected through the ROBO_DEBUG environment variable, enabling automatic reloading and generated error pages during development. Enhanced logging supports finding web-request failures. section 6.3.1 section 6.0

How Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi covers it

How deep it goes
Builds Tornado handlers, routing, templates, debug settings, logging, and responsive controls through runnable applications.
Examples
Demonstrates a timestamp service, a rendered time page, movement buttons, and a snack-selection interface with live video.
What you can do after
Build it from scratch: create Python web interfaces that control robot movements, display data, and incorporate live video.
How it connects
Connects Tornado, HTTP GET, JSON, HTML5 templates, logging, video streaming, and network performance measurement.

Also explained in

Compare how 8 books explain web application →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Your Own Robot: Using Python, CRICKIT, and Raspberry Pi. The section links point to the parts of the book it draws on.