RVR and Bottle / Flask, Only Works Once

So I’m trying to understand why this code doesn’t work. I’m using a Raspberry Pi with Python SDK and trying to create a web-based interface so someone can control the RVR from a web browser. I’ve tried this using both Flask and Bottle and it works, but only one time. In other words, the first time I load the web page, it drives the RVR, but no more times after that. If I start and restop the script, it may or may not work until I reboot the Pi.

This makes no sense at all.

from bottle import Bottle, run
from sphero_sdk import SpheroRvrObserver
from time import sleep
robot = SpheroRvrObserver()
app = Bottle()
left = 270
right = 90
forward = 0
backward = 180
def move(seconds, myspeed, myheading):
        speed = myspeed,
def forward():
    move(2, 10, 0)
    return 'Moving forward'

run(app, host='', port=8080)

The call to robot.close() at the end of your move() function closes the serial port. It only gets opened once, on line 4 with the initialization of robot.

I think that’s probably it.


SPHERO Email Marketing -