-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: correct name length package generation
Fixed an issue with name length generation for domain names which resulted into micropython-mdns creating wrongly formatted dns packages which couldn't be parsed by certain implementations of mdns like avahi. Fixes #6
- Loading branch information
Christoph Brand
committed
Oct 3, 2022
1 parent
e8de880
commit 9a9ddae
Showing
6 changed files
with
72 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Empty file.
This file contains 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,23 @@ | ||
from zeroconf import ServiceBrowser, ServiceListener, Zeroconf | ||
|
||
|
||
class MyListener(ServiceListener): | ||
|
||
def update_service(self, zc: Zeroconf, type_: str, name: str) -> None: | ||
print(f"Service {name} updated") | ||
|
||
def remove_service(self, zc: Zeroconf, type_: str, name: str) -> None: | ||
print(f"Service {name} removed") | ||
|
||
def add_service(self, zc: Zeroconf, type_: str, name: str) -> None: | ||
info = zc.get_service_info(type_, name) | ||
print(f"Service {name} added, service info: {info}") | ||
|
||
|
||
zeroconf = Zeroconf() | ||
listener = MyListener() | ||
browser = ServiceBrowser(zeroconf, "_myawesomeservice._tcp.local.", listener) | ||
try: | ||
input("Press enter to exit...\n\n") | ||
finally: | ||
zeroconf.close() |
This file contains 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,40 @@ | ||
import uasyncio as asyncio | ||
|
||
from mdns_client import Client | ||
from mdns_client.responder import Responder, generate_random_postfix | ||
|
||
print("Connected to WIFI!") | ||
|
||
|
||
async def serve_client(reader, writer): | ||
writer.write("HTTP/1.0 200 OK\r\nContent-type: text/html\r\n\r\n") | ||
writer.write("<h1>test response</h1>") | ||
await writer.drain() | ||
await writer.wait_closed() | ||
print("disconnected") | ||
|
||
|
||
async def setup_mdns(): | ||
local_ip = "0.0.0.0" | ||
print(f"Setting up MDNS on local ip: {local_ip}") | ||
client = Client(local_ip) | ||
host = "pico-{}".format(generate_random_postfix()) | ||
responder = Responder( | ||
client, | ||
own_ip=lambda: local_ip, | ||
host=lambda: host, | ||
) | ||
responder.debug = True | ||
responder.advertise("_myawesomeservice", "_tcp", port=1234) | ||
|
||
|
||
|
||
async def run(): | ||
await setup_mdns() | ||
await asyncio.create_task(asyncio.start_server(serve_client, "0.0.0.0", 1234)) # open port 1234 | ||
|
||
while True: | ||
await asyncio.sleep(3) | ||
|
||
|
||
asyncio.run(run()) |