如何将UI连接到连接到redis的网络库?

时间:2018-02-21 16:28:34

标签: redis redis-py plotly-dash

我有这个服务器和客户端('Raspberry pis')。现在我必须从redis db读取服务器和客户端并获取消息并在前端UI中显示它。我正在使用DASH框架工作。如何实现应用程序服务器并阅读实时更新enter image description here 像这张照片中的东西,我没有使用芹菜和烧瓶。

Server.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()

Client.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()

0 个答案:

没有答案