Closed ahmed-1a closed 1 year ago
I changed the RPC_Response type from Telemetry to String and added getGpioStatus Pls see : https://wokwi.com/projects/328082930673910354
@forGGe @ferchinas
Looks like a bug either in ThingsBoard.h or ArduinoJson.h. Thingsboard is ignoring the pin data from data["pin"] which is supposed to be in const char type. An easy work around is to use array of const char and use pin data to select the item from array and pass to the RPC_Response.
const char * pinarray[]={"0","1","2","3","4"}; // Numbers corresponds to GPIO pin number in ThingsBoard dashboard GPIO widget
RPC_Response processSetGpioState(const RPC_Data &data){
int pin = data["pin"];
bool enabled = data["enabled"];
digitalWrite(leds_control[pin], enabled);
return RPC_Response( pinarray[pin] ,(bool)data["enabled"]); //pinarray[pin] is a workaround to send const char key as telemetry
}
Tôi đã thay đổi loại RPC_Response từ Từ xa thành Chuỗi và thêm getGpioStatus. Vui lòng xem: https://wokwi.com/projects/328082930673910354
wow i find that bug when i try run you code could not convert 'String(led_delay, 10)' from 'String' to 'RPC_Response {aka Telemetry}'
@imbeacon Can be marked as enhancement as well refers to the same underlying feature request as #79
Hi,
The following code is from ESP32 Example https://thingsboard.io/docs/samples/esp32/gpio-control-pico-kit-dht22-sensor/
When the GPIO control widget is used on the dashboard, it send the setGpioStatus RPC call, but the response contains the value for the pin switched only. This response cannot be interpreted by the widget and the pin control on the widget stays at the default position.
How to send the proper response which includes the status of all pins using ThingsBoard library? This can help in implementing a getGpioStatus callback as well.
The following example for ESP8266 works perfectly because the response to the RPC call contains all the pins, however, this example does not use the the ThingsBoard library. https://thingsboard.io/docs/samples/esp8266/gpio/
Thank you.
@forGGe @ferchinas