thingsboard / thingsboard-gateway

Open-source IoT Gateway - integrates devices connected to legacy and third-party systems with ThingsBoard IoT Platform using Modbus, CAN bus, BACnet, BLE, OPC-UA, MQTT, ODBC and REST protocols
https://thingsboard.io/docs/iot-gateway/what-is-iot-gateway/
Apache License 2.0
1.75k stars 844 forks source link

[HELP] Gateway RPC commands #1516

Open StanislavSerdiuk opened 2 months ago

StanislavSerdiuk commented 2 months ago

Hello!

I new in Thingboards and have few question.

  1. I couldn't figured out how to publish to /v1/gateway/rpc the rpc command from dashboards (e.g rpc debug terminal) Is it possible? I subscribe to /v1/gateway/rpcandv1/devices/me/rpc/request/+` topics but there are messages only in the second one if I try to use rpc debug dashboard.

  2. Is it possible connect to gateway existing devices in thingsboard and propagate rpc command by publishing messages to /v1/gateway/rpc and expected one on device side in v1/devices/me/rpc/request/+

I mean that we can update telemetries for many devices by publishing to one gateway topic and having one connection. I'm expecting that same result for rpc command. We should publish to gateway topic the command and each devices will receive the command to 'v1/devices/me/rpc/request/+'

Thanks.

imbeacon commented 2 months ago

Hi @StanislavSerdiuk,

Thank you for your interest in ThingsBoard IoT Gateway. The possible reason is that you have two sessions, one of them connects device and another tries to receive rpc, e.g. using mosquitto_pub and mosuitto_sub commands, it won’t work, because ThingsBoard can only push to the same session, where device was connected. Also, please notice that you need to send command to connect device before getting RPC for it. You can check the following example of our Python SDK to understand how it works: https://github.com/thingsboard/thingsboard-python-client-sdk/blob/master/examples/gateway/respond_to_rpc.py

StanislavSerdiuk commented 2 months ago

@imbeacon Very thanks. But i am still misunderstand. I sent gif file what I tried to do. I expect that some command should receive to my gateway(response_to_rpc). Is it true? As you can see no one message did't received by gateway and "RPC debug terminal" returned time out exception. I restarted my computer before to be sure that no session are opened.

rpc_command

imbeacon commented 2 months ago

Oh, I understood. RPC that you are trying to use are sends to gateway device itself, not to devices, connected through it. You can just create a new dashboard, add RPC debug terminal to it, set connected device as a source entity and try there just by sending getCPULoad. ThingsBoard will automatically send this RPC to device, connected through the gateway to the gateway session to topic v1/gateway/rpc and with deviceName.

StanislavSerdiuk commented 2 months ago

@imbeacon Very thankful. It works! But I still have one more question. There are two cases in gif. In first case I did connect device to gateway. And the rpc received as expected. In second case I didn't do connect to device and comment the corresponding line. But the device is still in table "Devices" for my gateway in dashboard and I expect that rpc would received as it should be. But It didn't. The question is do we always do "connect" for all devices during restart my gateway service?

rpc_command_2