Skip to content

Commit

Permalink
added server
Browse files Browse the repository at this point in the history
local service discovery test server

local service discovery
  • Loading branch information
Lucas-D20 authored and XdoctorwhoZ committed Mar 12, 2024
1 parent 0dbe25c commit 3843d93
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
18 changes: 18 additions & 0 deletions panduza_platform/core/local_discovery_server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# UPD server listening for a client broadcast and responding by giving its IP and name

import asyncio
import socket
import json

class Server:
def connection_made(self, transport):
self.transport = transport

def datagram_received(self, data, addr):
message = data.decode()
json_message = json.loads(message)
print('received : %r from %s' % (json_message, addr))

json_reply = '{"name": "panduza_platform","version": 1.0}'
self.transport.sendto(json_reply.encode(), addr)
print('send : %r to %s' % (json_reply, addr))
15 changes: 15 additions & 0 deletions panduza_platform/core/platform.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

from .mqtt_async_client import MqttAsyncClient

from .local_discovery_server import Server

# from .platform_driver_factory import PlatformDriverFactory
from .platform_device_factory import PlatformDeviceFactory

Expand Down Expand Up @@ -127,6 +129,16 @@ def load_worker(self, worker):
self.load_task( worker.task(), name=f"WORKER>{worker.PZA_WORKER_name()}" )

# ---

async def local_service_discovery(self):
"""Start the discovery of local clients
"""

transport, protocol = await self.event_loop.create_datagram_endpoint(
lambda: Server(),
local_addr=('0.0.0.0', 53035))

# ---

async def mount_client(self, name, host_addr, host_port):
"""Mount a mqtt client
Expand Down Expand Up @@ -282,6 +294,9 @@ async def __idle_task(self):
# Start the global task group
async with asyncio.TaskGroup() as self.task_group:

# Connect the local discovery server
await self.local_service_discovery()

# Connect to primary broker
await self.mount_client("primary", "localhost", 1883)

Expand Down
18 changes: 0 additions & 18 deletions panduza_platform/core/udp_server.py

This file was deleted.

0 comments on commit 3843d93

Please sign in to comment.