thingsboard-client-sdk
thingsboard-client-sdk copied to clipboard
Running example code for ESP32 with RPC creates build error
/Users/rami/Documents/Arduino/libraries/ThingsBoard/src/ThingsBoard.h: In instantiation of 'void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::process_message(char*, uint8_t*, unsigned int) [with unsigned int PayloadSize = 64u; unsigned int MaxFieldsAmt = 8u; Logger = ThingsBoardDefaultLogger; uint8_t = unsigned char]': /Users/rami/Documents/Arduino/libraries/ThingsBoard/src/ThingsBoard.h:387:5: required from 'static void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::on_message(char*, uint8_t*, unsigned int) [with unsigned int PayloadSize = 64u; unsigned int MaxFieldsAmt = 8u; Logger = ThingsBoardDefaultLogger; uint8_t = unsigned char]' /Users/rami/Documents/Arduino/libraries/ThingsBoard/src/ThingsBoard.h:247:5: required from 'bool ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::RPC_Subscribe(const RPC_Callback*, size_t) [with unsigned int PayloadSize = 64u; unsigned int MaxFieldsAmt = 8u; Logger = ThingsBoardDefaultLogger; size_t = unsigned int]' /Users/rami/Documents/Arduino/portalneli/portalneli.ino:176:57: required from here /Users/rami/Documents/Arduino/libraries/ThingsBoard/src/ThingsBoard.h:329:16: error: return-statement with a value, in function returning 'void' [-fpermissive] return false;
When I took the all the code related to RPC and only kept the sending part. Then the code compiled and worked. So it is related somehow to RPC code.
I can confirm this. Used the example code 0002-arduino_rpc and made it run on esp32. WiFi upload of telemetry data works. Enabling the rpc section throws the compilation error described above.
#include "ThingsBoard.h" #include <WiFi.h>
#define WIFI_AP "YOUR_WIFI_AP" #define WIFI_PASSWORD "YOUR_WIFI_PASSWORD"
#define TOKEN "YOUR_ACCESS_TOKEN" #define THINGSBOARD_SERVER "demo.thingsboard.io"
WiFiClient espClient; ThingsBoard tb(espClient);
void setup() { int wifi_connection_tries = 10;
Serial.begin(9600);
WiFi.begin(WIFI_AP, WIFI_PASSWORD); Serial.print("Connecting to " + String(WIFI_AP)); for (wifi_connection_tries; wifi_connection_tries < 1; wifi_connection_tries--) { if (WiFi.isConnected() != true) { Serial.println("\nConnected to AP"); break; } Serial.print("."); delay(500); } }
RPC_Response processTemperatureChange(const RPC_Data &data) { Serial.println("Received the set temperature RPC method");
float example_temperature = data["temp"];
Serial.print("Example temperature: "); Serial.println(example_temperature);
return RPC_Response("example_response", 42); }
RPC_Response processSwitchChange(const RPC_Data &data) { Serial.println("Received the set switch method");
bool switch_state = data["switch"];
Serial.print("Example switch state: "); Serial.println(switch_state);
return RPC_Response("example_response", 22.02); }
const size_t callbacks_size = 2; RPC_Callback callbacks[callbacks_size] = { { "example_set_temperature", processTemperatureChange }, { "example_set_switch", processSwitchChange } };
bool subscribed = false;
void loop() { delay(100);
if (WiFi.status() == WL_IDLE_STATUS) { return; }
if (WiFi.status() != WL_CONNECTED) { Serial.println("Connecting to AP ..."); Serial.print("Attempting to connect to WPA SSID: "); Serial.println(WIFI_AP); WiFi.begin(WIFI_AP, WIFI_PASSWORD); return; }
if (!tb.connected()) { subscribed = false;
Serial.print("Connecting to: "); Serial.print(THINGSBOARD_SERVER); Serial.print(" with token "); Serial.println(TOKEN); if (!tb.connect(THINGSBOARD_SERVER, TOKEN)) { Serial.println("Failed to connect, retrying ..."); return; }}
Serial.println("Sending data...");
/*
- upload telemetry data each by each */ tb.sendTelemetryInt("temperature", 22); tb.sendTelemetryFloat("humidity", 42.5);
/* uncommenting RPC subscription return compilation error * if (!subscribed) { Serial.println("Subscribing for RPC...");
// Perform a subscription. All consequent data processing will happen in // processTemperatureChange() and processSwitchChange() functions, // as denoted by callbacks[] array. if (!tb.RPC_Subscribe(callbacks, callbacks_size)) { Serial.println("Failed to subscribe for RPC"); return; } Serial.println("Subscribe done"); subscribed = true;} */ Serial.println("Waiting for data..."); tb.loop(); }
Found a workaround by removing the two bool return statements from the void function. I have no idea if this brakes something but it works for mow.
Here is a patch: ThingsBoard_arduino-esp32.zip
I confirm daniauri's fix. I work in Arduino IDE and can get rid of the problem by downgrading ThingsBoard library to 0.2.0 and ArduinoJson library to 5.13.5. This is clearly not the preferred method and keeps me from using the ThingsBoardSized<128, 32> tb(espClient); line which gives more fields.
After a bit more investigation, the current version of thingsboard.h DOES have the two bool return statements updated to daniauri's version (just return; and not return false;). On June 13, 2019, the version went from 0.4 to 0.5.
If using Arduino IDE, it appears they currently have 0.4 as the latest version. I'm assuming the Arduino IDE ThingsBoard library uses the same release version as the Github version.
@daniauri: Thanks, that fix seems to work for me as well. @abferguson: Good to know. Your assumption about the release version seems correct from the relevant section on new releases in the Library Manager FAQ. Their Arduino Library Manager indexer, which runs hourly, seems to check for either tags or new releases. I suppose I'll use 0.5 once it is tagged here and picked up by their indexer.