-
Notifications
You must be signed in to change notification settings - Fork 31
Add httpserver simpletest with connection manager #91
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# SPDX-FileCopyrightText: 2024 DJDevon3 | ||
# SPDX-License-Identifier: MIT | ||
# Coded for Circuit Python 9. | ||
"""HTTP Server Simpletest with Connection Manager""" | ||
# pylint: disable=import-error | ||
|
||
import os | ||
|
||
import adafruit_connection_manager | ||
import wifi | ||
|
||
from adafruit_httpserver import Server, Request, Response | ||
|
||
# Get WiFi details, ensure these are setup in settings.toml | ||
ssid = os.getenv("WIFI_SSID") | ||
password = os.getenv("WIFI_PASSWORD") | ||
|
||
print("Connecting to WiFi...") | ||
wifi.radio.connect(ssid, password) | ||
print("✅ Wifi!") | ||
|
||
# Initalize Wifi, Socket Pool, Request Session | ||
pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio) | ||
server = Server(pool, "/static", debug=True) | ||
|
||
|
||
@server.route("/") | ||
def base(request: Request): | ||
"""Serve a default static plain text message""" | ||
return Response(request, "Hello from the CircuitPython HTTP Server!") | ||
|
||
|
||
server.serve_forever(str(wifi.radio.ipv4_address)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@michalpokusa, which env names do you want for examples in this repo? Should it not use the
CIRCUITPY_*
ones so it doesn't auto connect?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only the
httpserver_simpletest_manual.py
example uses env names at runtime, other examples utilizesettings.toml
withCIRCUITPY_*
envs and auto connect feature.Either way, if something is not consistent with other examples I will correct it in my PR, e.g. missing emphasised lines or description of example in docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would probably use
CIRCUITPY_*
, where possible, since people playing with different things would most likely already have those on their devices...There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are only used in one example that clearly states that this is a manual approach. Every other example uses
settings.toml
, it is just to show there are multiple possibilities.If I am correct, setting the
CIRCUITPY_*
envs also turns on the web workflow, which might not be desired.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh. Yeah and that was my thought, if the general ones are used, it auto connects, and thus it can be used for web workflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I did the right thing by setting it back to how the manual example has it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure how I will order the examples. IMO right now it can stay like that and if it becomes necessary I will change that in my PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me 👍