1

我有这个服务器和客户端('Raspberry pis')。现在我必须从 redis db 读取服务器和客户端并获取消息并在前端 UI 中显示它。我正在使用 DASH 框架工作。如何实现应用程序服务器并阅读实时更新在此处输入图像描述 类似于这张图片的内容,我没有使用芹菜和烧瓶。

服务器.py

import time

from mmnet.server import Server

BROKER = {"address": "10.0.10.1",
          "port": 6379,
          "db": 0}

# Create a new server instance. Pass it a dictionary with the connection details.
server = Server(BROKER)

# Tell the server which devices to expect. A combination of module + device is unique.
server.expect('Module1', 'Device1')

# The server waits for all expected devices to connect and calls their initialization function.
server.init()

# Execute a remote function in the given device with the given parameters. The result of
# this query will be returned by the function. This call is BLOCKING, so it will stop on the server
# until the function call finishes on the client
result = server.execute_function('Module1', 'Device1', 'move_to', 10, 50, 100, value=True, test="yes please")

# The server runs with a daemon thread, so make sure your program does not terminate!
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    pass

# Always close the server at the end!
server.close()

客户端.py

import time

from mmnet.client import Client

BROKER = {"address": "10.0.10.1",
          "port": 6379,
          "db": 0}


def move_to(x, y, z, value="abc", test="def"):
    return str(x) + str(y) + str(z) + value + test


def init_device():
    pass


# Create a new client instance
client = Client(BROKER, 'Module1', 'Device1')

# Register your available functions
client.register_action('move_to', move_to)

# Notify the server we are ready to be initialized
client.init(init_device)

# The clients runs with a daemon thread, so make sure your program does not terminate!
try:
    while True:
        time.sleep(1)
except KeyboardInterrupt:
    pass

# Always close the client at the end!
client.close()
4

0 回答 0