是否可以将 ThingsBoard 与虚拟 I2C 一起使用?
Is it possible to use ThingsBoard with virtual I2C?
我看到 Thingsboard 可以发送 RPC 请求 (https://thingsboard.io/docs/user-guide/rule-engine-2-0/action-nodes/#rpc-call-request-node)。此示例显示将值发送到 GPIO。
我想知道我是否可以将值发送到连接到 Raspberry Pi 的 I2C 物理设备。
如果我使用 i2c-stub 来创建虚拟 I2C 设备,我该如何将它们连接到 Thingsboard?
到目前为止,我在 RPi 上使用 i2cset 和 i2cset 来读写虚拟传感器。
谢谢,
费利佩
您可以使用本指南:
https://thingsboard.io/docs/samples/raspberry/gpio/
核心要点:
def on_message(client, userdata, msg):
...
if data['method'] == 'getGpioStatus':
client.publish(msg.topic.replace('request', 'response'), get_gpio_status(), 1)
elif data['method'] == 'setGpioStatus':
set_gpio_status(data['params']['pin'], data['params']['enabled'])
client.publish(msg.topic.replace('request', 'response'), get_gpio_status(), 1)
client.publish('v1/devices/me/attributes', get_gpio_status(), 1)
您可以为 I2C 定义自己的函数和 RPC 方法名称(而不是使用 get_gpio_status 和 set_gpio_status)
我看到 Thingsboard 可以发送 RPC 请求 (https://thingsboard.io/docs/user-guide/rule-engine-2-0/action-nodes/#rpc-call-request-node)。此示例显示将值发送到 GPIO。
我想知道我是否可以将值发送到连接到 Raspberry Pi 的 I2C 物理设备。
如果我使用 i2c-stub 来创建虚拟 I2C 设备,我该如何将它们连接到 Thingsboard? 到目前为止,我在 RPi 上使用 i2cset 和 i2cset 来读写虚拟传感器。
谢谢, 费利佩
您可以使用本指南: https://thingsboard.io/docs/samples/raspberry/gpio/
核心要点:
def on_message(client, userdata, msg):
...
if data['method'] == 'getGpioStatus':
client.publish(msg.topic.replace('request', 'response'), get_gpio_status(), 1)
elif data['method'] == 'setGpioStatus':
set_gpio_status(data['params']['pin'], data['params']['enabled'])
client.publish(msg.topic.replace('request', 'response'), get_gpio_status(), 1)
client.publish('v1/devices/me/attributes', get_gpio_status(), 1)
您可以为 I2C 定义自己的函数和 RPC 方法名称(而不是使用 get_gpio_status 和 set_gpio_status)