#WSGI server partial pages

1 messages · Page 1 of 1 (latest)

rugged mural
karmic mountain
#

OK, what does your heartbeat loop look like?

rugged mural
#
# Here we setup our server, passing in our web_app as the application
server.set_interface(eth)
print(eth.chip)
wsgiServer = server.WSGIServer(80, application=web_app)

print("Open this IP in your browser: ", eth.pretty_ip(eth.ip_address))

# Start the server
wsgiServer.start()

while True:
    # Our main loop where we have the server poll for incoming requests
    wsgiServer.update_poll()
    # Maintain DHCP lease
    eth.maintain_dhcp_lease()
    # Could do any other background tasks here, like reading sensors
#

sorry, discord was fighting me

karmic mountain
#

no worries

#

Is that your full while True loop? Or do you have more stuff in it in your real app?

rugged mural
#

that is it. i'm mostly wondering it it's the individual response methods causing issues

karmic mountain
#

have you narrowed it down to a specific response method?

rugged mural
#

no, i think i've had it happen on every page, but i'll have to keep closer notes

karmic mountain
#

ok

#

What's the average response body size you're delivering? Also, what are you using to call the server with?

rugged mural
#

I'd say 30-40 lines of HTML. No styles, css, or js. Calling from Google Chrome on linux. I figured I was well within the limits of what it could handle

karmic mountain
#

should be, yeah

#

have you tried with other browsers, curl/wget, Python, or maybe Postman?

rugged mural
#

i have not, but i can add that to the list of things to try

karmic mountain
#

yeah, I would try that too, it might be that you get a bit more insight into how/why it's failing than you would just requesting with Chrome

rugged mural
#

ah, so i've just tried with wget, and it's served me a mangled page on the root, which is minimal code to share

#
def html_doc(title, body):
    return f'''
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{title}</title>
    </head>
    <body>
    {body}
    </body>
    </html>
    '''


@web_app.route("/")
def root(request):  # pylint: disable=unused-argument
    print("Root WSGI handler")
    mac = ":".join("%02X" % _ for _ in eth.mac_address)
    ip = eth.pretty_ip(eth.ip_address)
    temp = microcontroller.cpu.temperature * (9 / 5) + 32
    return ("200 OK", [], [html_doc("WIZnet W5100S-EVB-Pico web UI", f'''
    <div align="center">
    <H1>WIZnet W5100S-EVB-Pico web server</H1>
    <h2>Hardware Information</h2>
    <p>
    Chip Version: {eth.chip}<br>
    MAC Address: {mac}<br>
    IP Address: {ip}<br>
    CPU Temperature: {temp} F<br>
    </p>
    <h2>Services</h2>
    <p>
    <a href="/led/" id="led">/led/ - Control the green user LED</a><br>
    </p>
    <p>
    <a href="/serial/" id="w_uart">/serial/ - write to serial</a><br>
    </p>
    </div>
    ''')])
#

perhaps i'm asking too much of f-string interpolation

karmic mountain
#

that might be it

#

Can you use some kind of IO Stream or similar?

#

Or perhaps just add lines to a list and then join that with \n or something?

rugged mural
#

no doubt i could, i am very rusty at python. i'll have to look into how to do that

karmic mountain
#

io.StringIO

rugged mural
#

well, i noticed from working with wget that the server wasn't sending content-length, so i tried setting that myself, and it didn't help.
i added a gc.mem_free() to the top of my root method, so i can see free memory on the start of each request. doesn't look like i'm anywhere near stressing the memory.
i also started printing my whole html document to the console, which lets me see that even when i get a corrupted page, the string i sent from my method ... is not corrupted. So there may be some WSGI server issue still

rugged mural
karmic mountain
#

weird... so maybe it's the loop that somehow causes it to skip? I wonder if there's some kind of explicit end or flush command to make sure the whole buffer is sent?

rugged mural
#

perhaps, but whatever the cause, it's weird that the start of the document gets sent again at the end

karmic mountain
#

ooh I didn't even notice that... so, why don't you try to add a pause after the first send? and see if that does anything?

rugged mural
#

hmm, like a sleep in the main event loop?

#
--2022-03-09 22:16:35--  http://192.168.1.195/
Connecting to 192.168.1.195:80... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 200 OK
  Server: w5kWSGIServer
Length: unspecified
Saving to: ‘STDOUT’

-                                                     [<=>                                                                                                           ]       0  --.-KB/s               
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>WIZnet W5100S-EVB-Pico web UI</title>
    </head>
    <body>
    <div align="center">
    <H1>WIZnet W5100S-EVB-Pico web ser
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
-                                                     [ <=>                                                                                                          ]     485  --.-KB/s    in 0.1s    

2022-03-09 22:16:39 (3.78 KB/s) - written to stdout [485]

#

looks like i'm gonna have to study the wsgi server code and start hacking in there

karmic mountain
#

yeah something's definitely up with that code

#

I don't have the device myself so I can't help debug there