-
Notifications
You must be signed in to change notification settings - Fork 5
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
pi zeugs, db zeugs und aiocoap server #13
base: main
Are you sure you want to change the base?
Changes from all commits
4b06bc5
1289478
cce2152
a876187
7a9bfde
aedc502
f2f1932
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import asyncio | ||
import aiocoap.resource as resource | ||
from aiocoap import * | ||
|
||
|
||
class WhoAmI(resource.Resource): | ||
async def render_get(self, request): | ||
text = ["Used protocol: %s." % request.remote.scheme] | ||
|
||
text.append("Request came from %s." % request.remote.hostinfo) | ||
text.append("The server address used %s." % request.remote.hostinfo_local) | ||
|
||
claims = list(request.remote.authenticated_claims) | ||
if claims: | ||
text.append("Authenticated claims of the client: %s." % ", ".join(repr(c) for c in claims)) | ||
else: | ||
text.append("No claims authenticated.") | ||
|
||
return Message(content_format=0, | ||
payload="\n".join(text).encode('utf8')) | ||
|
||
|
||
async def main(): | ||
root = resource.Site() | ||
|
||
root.add_resource(['.well-known', 'core'], | ||
resource.WKCResource(root.get_resources_as_linkheader)) | ||
root.add_resource(['whoami'], WhoAmI()) | ||
|
||
con = await Context.create_server_context(root,bind=("0.0.0.0",5555)) | ||
|
||
request = Message(code=GET, uri="coap://127.0.0.1:5683/resource-lookup/", observe=0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Move host/port into a configuration or as constant at the top of the file |
||
req = con.request(request) | ||
res = await req.response | ||
print(res.payload) | ||
print("start async loop") | ||
async for r in req.observation: | ||
print(r.payload) | ||
# Run forever | ||
print("server running now") | ||
await asyncio.get_running_loop().create_future() | ||
|
||
|
||
if __name__ == '__main__': | ||
asyncio.run(main()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Misses newline at EOF |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
from coapthon.client.helperclient import HelperClient | ||
host = "127.0.0.1" | ||
host = "2001:db8::814c:35fc:fd31:5fde" | ||
port = 5683 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Configuration constants are usually all uppercase, reference pep8 or use a linter.
|
||
|
||
|
||
def get_led(led): | ||
path = "led{}".format(led) | ||
path = "led/{}".format(led) | ||
|
||
client = HelperClient(server=(host, port)) | ||
response = client.get(path) | ||
|
@@ -14,7 +14,7 @@ def get_led(led): | |
|
||
|
||
def set_led(led, value): | ||
path = "led{}".format(led) | ||
path = "led/{}".format(led) | ||
|
||
client = HelperClient(server=(host, port)) | ||
response = client.put(path, payload=value) | ||
|
This file was deleted.
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.
Top of the Readme is outdated (not touched in this PR)