Giter VIP home page Giter VIP logo

Comments (7)

jrrickerson avatar jrrickerson commented on September 4, 2024

I'm going to try working on this one at PyCon US 2023 sprints

from adafruit_circuitpython_httpserver.

michalpokusa avatar michalpokusa commented on September 4, 2024

I am not entirely sure what you mean, but there is already a very simple example:
https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer/blob/main/examples/httpserver_simple_serve.py

If you delete all docstrings, prints etc. it is only 4-5 lines long, not considering connecting to WiFi. If you want it without a handler for "/", it is 2 lines long.

One could for sure save some characters but this would not be a realistic scenario for using this lib.
Correct me if I understood this Issue incorrectly.

from adafruit_circuitpython_httpserver.

michalpokusa avatar michalpokusa commented on September 4, 2024

The minified version of the example would be something like this:

import os, socketpool, wifi
from adafruit_httpserver.server import HTTPServer


ssid, password = os.getenv("WIFI_SSID"), os.getenv("WIFI_PASSWORD")
wifi.radio.connect(ssid, password)
HTTPServer(socketpool.SocketPool(wifi.radio), "/").serve_forever(str(wifi.radio.ipv4_address))

I believe it should be possible to omit manually connecting to WiFi by using special env vars, making the example even shorter:

import socketpool, wifi
from adafruit_httpserver.server import HTTPServer

HTTPServer(socketpool.SocketPool(wifi.radio), "/").serve_forever(str(wifi.radio.ipv4_address))

but at this stage it kind of misses the point of being an example.

from adafruit_circuitpython_httpserver.

jrrickerson avatar jrrickerson commented on September 4, 2024

I did see the simple server example, but I thought I could provide another that required a bit less work by the end user, and fit the library standard of having a "_simpletest.py" module in the examples folder. I've submitted a PR for it but let me know if you think it's redundant.

Kinda going for less setup steps rather than less lines of code, if that makes sense

from adafruit_circuitpython_httpserver.

michalpokusa avatar michalpokusa commented on September 4, 2024

Ok, I see. To be honest I believe it would make more sense to modify existing one, and replace response.send_file("index.html") with response.send("Hello World").

Creating a separate example with only one line modified seems like a overkill for me.

from adafruit_circuitpython_httpserver.

jrrickerson avatar jrrickerson commented on September 4, 2024

@michalpokusa Thanks, I appreciate the feedback. I can make adjustments to the PR to merge the two examples then.

from adafruit_circuitpython_httpserver.

jrrickerson avatar jrrickerson commented on September 4, 2024

@michalpokusa I've merged the two examples, and renamed the "simple_serve" example to "simpletest" to adhere to the convention which appears to be in the other CircuitPython libraries and this contributing guide:
https://circuitpython.org/contributing/library-infrastructure-issues

Please let me know if you see any other areas for improvement.

from adafruit_circuitpython_httpserver.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.