deckerego / ampule Goto Github PK
View Code? Open in Web Editor NEWA tiny HTTP server made for CircuitPython WiFi devices (like the ESP32)
License: MIT License
A tiny HTTP server made for CircuitPython WiFi devices (like the ESP32)
License: MIT License
I've been using Ampule with CircuitPython and love it, trying to get it to work with MicroPython and I'm stumped on the server configuration piece due to socketpool as I get ImportError: no module named 'socketpool'
. Can you provide any guidance on how to configure the startup of Ampule with MicroPython?
Thanks.
return (200, headers, '{"enabled": false}'}")
should be:
return (200, headers, '{"enabled": true}')
I was trying ampule to replace adafruit httpserver as have been seeing some issues with reliability.
I got the code working to host the html page and respond to button presses on that page - so long as running in blocking mode. However I need to run in non-blocking mode (I was polling the server instance formed with httpserver, as the hardware checks for a physical button press too).
I can't get the non-blocking examples to work - whenever I try to connect to the IP address I get:
"Error reading from socket [Errno 11] EAGAIN
Error with request: need more than 0 values to unpack"
And the device trying to connect to the IP address reports it can't connect and the connection is being reset. I see this same behaviour with my code as well when set socket.setblocking(False) too.
I've seen your advice in [(https://github.com//pull/26)] however I can't determine how to manually override the setting on the accept() socket (I assume this is what I need to do). I've tried setting the timeout on the socket created (i.e. the listening socket) that the accept socket should then inherit the timeout from, but it doesn't make any difference to the behaviour.
Any ideas why I can't get your non-blocking example to work? I'm using a pi pico running circuitpython 8.1.0.
Many thanks.
I'm trying to send an HTML file converted to a string as a response, like this:
def getHTML(filepath):
f = open(filepath,'r', encoding="utf-8")
html = f.read()
f.close()
return html
@ampule.route("/")
def light_set(request):
return (200, {}, getHTML('cat.html'))
When I exceed about 50 lines, I get "Error with request: name 'bytes_sent' is not defined"
It looks like it's referring to this line:
while True:
try:
bytes_sent_total += client.send(response)
if bytes_sent_total >= response_length:
return bytes_sent_total
else:
response = response[bytes_sent:]
continue
except OSError as e:
if e.errno == 11: # EAGAIN: no bytes have been transfered
continue
else:
return bytes_sent_total
I can't seem to send a file over a certain size without tripping this.
Error reading from socket [Errno 116] ETIMEDOUT
Error with request: need more than 0 values to unpack
Error reading from socket [Errno 116] ETIMEDOUT
Error with request: need more than 0 values to unpack
I am getting this Error after running the example webserver code for a while what does this mean?
Rather than just sending a string response to an http request I would like to send a file from an ESP32S2 board that I am running CircuitPython and ampule on. If it is possible to do this, can you tell me how? Thanks.
When serving responses longer than 2572 chars, a ERR_CONTENT_LENGTH_MISMATCH
is caught by the browser:
@ampule.route("/")
def light_set(request):
headersCss = {
"Content-Type": "text/css; charset=UTF-8",
"Access-Control-Allow-Origin": '*',
"Access-Control-Allow-Methods": 'GET, POST',
"Access-Control-Allow-Headers": 'Origin, Accept, Content-Type, X-Requested-With, X-CSRF-Token'
}
content = readFile("test.txt")
return (200, headersCss, content)
By sending an empty header instead this increases from 2572 to 2776 chars:
@ampule.route("/")
def light_set(request):
content = readFile("test.txt")
return (200, {}, content)
Here's a test endpoint evaluating this behaviour. While requesting /test/2776
works and returns a string of 2776 "x", /test/2777
will result in a ERR_CONTENT_LENGTH_MISMATCH
.
@ampule.route("/test/<length>")
def light_set(request, length):
output = "X" + "x"*(int(length)-2) + "X"
return (200, {}, output)
is it possible to set it to serve plain html files from a '\static' directory say?
Is the library compatible with Adafruit AirLift WiFi coprocessor like the Metro M4 Express AirLift?
I embedded a link into the HTML page from example to download a file from the circuit python webserver but after downloading it there was a ERROR NO FILE from chrome how do I fix this ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.