Web Server with XRP Version 1

Having trouble getting a webserver going on Version 1 of the XRP using the webserver_example.py I suspect I’m just doing something stupid. Is there a tutorial or video out there that walks through it? I tried both running it as is, and running it with my home wifi name and password. The former finished but nothing happened? The latter hangs and never finishes.

I don’t have a solution, but I can say that I ran it a couple of days ago and it definitely worked. I connected to the XRPs access point. I did try connecting it to my local wifi - having set up the secrets.json file - but that didn’t seem to work.

I did notice that I had to run the server a couple of times, i.e. I would run it, and it would exit, and then I would run it again and it would work. Not sure what was going on there at all.

Just looking at the traceback, is there any possibility you accidentally edited the file before you uploaded it? I am just wondering if there are some odd characters that were inserted.

1 Like

Maybe @Fgrossman can help?

1 Like

I will try running it multiple times. I made changes to attempt to change it to my house WiFi but I don’t think I did anything out of line and I took it back out. I’ll also post the code here when I’m back at the computer tonight

Have you modified the secrets.json file (if so what are the contents?)? Are you using this documentation?

this is the webserver_example.py from the XRP Code Editor Files


from XRPLib.defaults import *
import time
from machine import Timer

# Binding functions to the arrow buttons
webserver.registerForwardButton(lambda: drivetrain.set_effort(0.5, 0.5))
webserver.registerLeftButton(lambda: drivetrain.set_effort(-0.5, 0.5))
webserver.registerRightButton(lambda: drivetrain.set_effort(0.5, -0.5))
webserver.registerBackwardButton(lambda: drivetrain.set_effort(-0.5, -0.5))
webserver.registerStopButton(lambda: drivetrain.set_effort(0, 0))

# Binding functions to custom buttons
webserver.add_button("Close Server", lambda: webserver.stop_server())
webserver.add_button("Blink", lambda: board.led_blink(2))
webserver.add_button("LED Off", lambda: board.led_off())
webserver.add_button("Servo Up", lambda: servo_one.set_angle(90))
webserver.add_button("Servo Down", lambda: servo_one.set_angle(0))

# Logging static data to the webserver
# webserver.log_data("test", "test")
# webserver.log_data("List", [1,2,3])
# webserver.log_data("Dict", {"a":1,"b":2,"c":3})
# webserver.log_data("Tuple", (1,2,3))

def log_time_and_range():
    # This function is called every second to update the data on the webserver
    webserver.log_data("Time", time.time())
    webserver.log_data("Range", rangefinder.distance())
    webserver.log_data("Left Motor", left_motor.get_position())
    webserver.log_data("Right Motor", right_motor.get_position())
    webserver.log_data("Button State", board.is_button_pressed())

timer = Timer(-1)
timer.init(freq=4, mode=Timer.PERIODIC, callback=lambda t: log_time_and_range())

def connect_and_start_webserver():
    # Connect to the network and start the webserver in bridge mode
    # Network ssid and password are stored in root/secrets.json
    webserver.connect_to_network()
    webserver.start_server()

def start_network_and_webserver():
    # Start the webserver in access point mode
    # Network ssid and password are stored in root/secrets.json
    webserver.start_network()
    webserver.start_server()

start_network_and_webserver()

I was not able to find the secrets.json file to modify it…

I have a beta version so I don’t really know what may be different for version 1, just trying to keep you going with suggestions.

update for those following - I was able to upload the secrets.json file and upload it link here

Expected results when you run it is that it appears to “hang” and the last line is an OS error “EADDRINUSE” which made me assume it had failed. However, the program is waiting for you to go to your wifi setting and select the wifi you named in secrets.json.

Thanks to Jdaming for helping me with that step.

At that point the XRP control page didn’t appear but after back and forth several times, it finally did. Now I am able, using access point connection, to get the control page to come up, mostly by typing the IP in the URL. The IP is listed in the shell area if you scroll up.

FYI I’m using the XRP Example code for the web server as the starting point.