Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPC polling for 'switch' widget in 'RPC request persistent ' looks like doesn't work #211

Closed
AndriiRukhmakov opened this issue Jul 31, 2024 · 4 comments · Fixed by #223
Closed

Comments

@AndriiRukhmakov
Copy link

On ThingsBoard website for 'switch' widget - if feature 'RPC request persistent' enabled it doesn't poll client side with the GET method. Please check it on your side. Client can be polled with the GET method just once - in the case if you'll reload ThingsBoard web page.

Screenshot from 2024-07-31 18-02-01

@AndriiRukhmakov
Copy link
Author

If you need more information about this issue, please let me know, and I'll send movie with example.

@MathewHDYT
Copy link
Contributor

MathewHDYT commented Jul 31, 2024

Actively polling the RPC client side is not what the RPC request persistent feature does.

The behaviour is exactly like expected, the only thing that this feature changes is that if the device is not connected the request is saved in the database instead and sent as soon as the device is connected. The 2000ms in that case is the time in that the widget expects a response, and if it gets one everything is good, if it doesn't the RPC expires is deleted from the database and the widget times out.

I hope this clears any misunderstanding.

@AndriiRukhmakov
Copy link
Author

Ok. Thank you for explanation.

Mathew, I have open question - how to poll remote device state from widget side?

Example of possible case:

  1. ESP32 has one LED and one button.
  2. From web side we can control state of LED using switch widget. State of LED will be always stored in some static VAR.
  3. We are pressed REAL button on ESP32 and LED changes state from ON to OFF and static variable also will be changed.

The question - how to poll ESP32 from web side in some time interval for status static VAR for LED, because if we push real button then web widget button should change state too. (if WEB page will be reloaded widget will send GET RPC request, and will get properly LED state. But it is not convinient to reload page permanently from user side )

@MathewHDYT
Copy link
Contributor

MathewHDYT commented Aug 1, 2024

I don't think that can be directly done with an RPC widget, because it is not meant for that use case. RPC is meant for methods that are called by the cloud and "can" return a value. Either you change the underlying JavaScript code so that it sends the Get Request repeadetly, implementing your wanted polling, but that doesn't seem really efficient.


Or alternatively you use Shared Attributes, which are meant for your use case. These are attributes that the device can send and change, and the server read, but the server can also change them and the device can be informed if they change on the server side.

To do that you need to first change the rule chain so that it transforms some attributes into shared attributes. Then the device can simply subscribe to changes for those attributes if the server changes them and send these attributes like it would any other client side attributes.

Afterwards the server can display that shared attribute in a widget, there are already preexisting widgets for that. Now if you change the value from the cloud the value on the device should be updated as well and if you change the value on the device, and then upload the changed value as an attribute it will also be shown on the cloud.

I hope this explanations helps somewhat. Alternatively I would recommend asking in the main repository as this is not an issue or feature request with the MQTT SDK.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants