Connecting MKR IoT to thingsboard - ThingsBoardHttp error

I am trying to connect MKR IOT to thingsboard.

I set up a server but when I try to run sketch I have this error.

How should I initialize ThingsBoard instance?

1 Like

Post code as CODE, not pictures! It's not hard!

Not sure if this is easier to follow here is code:

/*
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/5ac01a8c-77c0-4ab7-8b84-742054dbbb56

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  CloudSwitch lEDswitch;
  CloudColoredLight colorLightSwitch;
  String weather_report;
  CloudPressure pressure;
  CloudTemperatureSensor temperature;
  CloudRelativeHumidity humidity;
  CloudIlluminance illuminance;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

//#include <SoftwareSerial.h>
#include "thingProperties.h"
#include <Arduino_MKRIoTCarrier.h>
#include <WiFiNINA.h>
//#include "HttpClient.h"

MKRIoTCarrier carrier;

//2021-05-03 my issues
// Illuminance is not wroking
// Error pressure sensor disconnected
// Unable to display degree symbol
//maange to sove OLED off :)


//Trying to get solution to siplay degree symbol but it does not work for me
const char DegreeSymbol[] = {0xA7, '\0'};

//Serial.println(colorLightSwitch.getHue());
//Serial.println(colorLightSwitch.getSaturation());
//Serial.println(colorLightSwitch.getBrightness());
//Serial.println(colorLightSwitch.getSwitch());


int modeSelect = 0;
int previousMode = 0;
int refreshCount = 0;
uint32_t myCustomColor = carrier.leds.Color(255, 100, 50);
uint32_t rgbcolor = carrier.leds.ColorHSV(colorLightSwitch.getHue(), colorLightSwitch.getSaturation(), colorLightSwitch.getBrightness());
uint32_t rgbcolor1 = carrier.leds.ColorHSV(colorLightSwitch.getHue());
uint32_t rgbcolor2 = carrier.leds.gamma32(carrier.leds.ColorHSV(colorLightSwitch.getHue()));


// See https://thingsboard.io/docs/getting-started-guides/helloworld/
// to understand how to obtain an access token
#define TOKEN               "YOUR_ACCESS_TOKEN"
#define THINGSBOARD_SERVER  "vps4135s5.ovh.net"
#define THINGSBOARD_PORT    8080

// Baud rate for debug serial
#define SERIAL_DEBUG_BAUD   115200

// Initialize ThingsBoard instance
ThingsBoardHttp tb(client,TOKEN, THINGSBOARD_SERVER, THINGSBOARD_PORT);
//hingsBoardHttp tb(espClient);

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);
  //pinMode(LED_BUILTIN, OUTPUT);
  pinMode(TFT_BACKLIGHT, OUTPUT);



  //while (!Serial);  //comment to this like to start code
  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {

    Serial.println(fv);
    Serial.println("Please upgrade the firmware to ");
    Serial.println(WIFI_FIRMWARE_LATEST_VERSION);
  }



  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);


  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
  */
  setDebugMessageLevel(4);
  ArduinoCloud.printDebugInfo();
  //string printDebugInfo = ArduinoCloud.printDebugInfo();


  //Wait to get cloud connection to init the carrier
  while (ArduinoCloud.connected() != 1) {
    ArduinoCloud.update();
    delay(500);

  }
  delay(500);
  CARRIER_CASE = false;
  carrier.begin();
  carrier.display.setRotation(0);    //start up screen code here



  carrier.display.fillScreen(ST77XX_BLACK); //set background
  carrier.display.setTextColor(ST77XX_WHITE); //white text
  carrier.display.setTextSize(3); //medium sized text

  carrier.display.setCursor(60, 80); //sets position for printing (x and y)
  carrier.display.print("Weather");
  carrier.display.setCursor(60, 120); //sets position for printing (x and y)
  carrier.display.print("Station");
  delay(2000);

  carrier.display.fillScreen(ST77XX_BLACK); //set background
  carrier.display.setTextColor(ST77XX_WHITE); //white text
  carrier.display.setTextSize(2); //medium sized text

  carrier.display.setCursor(70, 80); //sets position for printing (x and y)
  carrier.display.print("Connected");
  carrier.display.setCursor(50, 110); //sets position for printing (x and y)
  carrier.display.print("To IoT Cloud");
  delay(2000);

  carrier.display.fillScreen(ST77XX_BLACK); //set background
  carrier.display.setTextColor(ST77XX_WHITE); //white text
  carrier.display.setTextSize(2); //medium sized text

  carrier.display.setCursor(70, 80); //sets position for printing (x and y)
  carrier.display.print("Firmware");
  carrier.display.setCursor(50, 110); //sets position for printing (x and y)
  carrier.display.print(fv);
  delay(1000);

}

void loop() {
  ArduinoCloud.update();
  // Your code here
  carrier.Buttons.update();

  //rgbcolor1 = carrier.leds.ColorHSV(colorLightSwitch.getHue());
  //rgbcolor = carrier.leds.ColorHSV(colorLightSwitch.getHue(), colorLightSwitch.getSaturation(), colorLightSwitch.getBrightness());
  rgbcolor2 = carrier.leds.gamma32(carrier.leds.ColorHSV(colorLightSwitch.getHue()));

  Serial.println(rgbcolor1);
  //lEDswitch
  if (colorLightSwitch.getSwitch() == 1) {
    modeSelect = 6;
  }
  else {
    modeSelect = 4;
  }

  while (!carrier.Light.colorAvailable()) {
    delay(5);
  }




  int none;
  int illuminance;
  carrier.Light.readColor(none, none, none, illuminance);

  temperature = carrier.Env.readTemperature();
  humidity = carrier.Env.readHumidity();
  //pressure = carrier.Pressure.readPressure();

  //Error detected!
  //Pressure sensor is not connected!




  if (carrier.Button0.onTouchDown()) {
    modeSelect = 0;
  }

  /*
    if (carrier.Button0.getTouch() and carrier.Button1.onTouchDown()) {
      modeSelect = 5;
    }
  */


  if (carrier.Button1.onTouchDown()) {
    //configuring display, setting background color, text size and text color
    modeSelect = 1;
  }

  if (carrier.Button2.onTouchDown()) {
    modeSelect = 2;
  }


  if (carrier.Button3.onTouchDown()) {
    modeSelect = 3;
  }

  if (carrier.Button4.onTouchDown()) {
    modeSelect = 4;
  }





  if (modeSelect != previousMode) {
    updateDisplay();
    previousMode = modeSelect;
    refreshCount = 0;
  }
  else if (refreshCount >= 500) {
    updateDisplay();
    refreshCount = 0;
    //modeSelect = 4;

  }

  /*

    if (carrier.Button3.onTouchDown()) {
      carrier.display.fillScreen(ST77XX_WHITE);
      carrier.display.setTextColor(ST77XX_RED);
      carrier.display.setTextSize(2);

      carrier.display.setCursor(30, 110);
      carrier.display.print("Pressure: "); //kPa
      carrier.display.print(pressure);
      carrier.display.println(" kPa");



    if (carrier.Button3.onTouchDown()) {


  */


  if (humidity >= 60 && temperature >= 15  && temperature < 20) {
    weather_report = "It is very humid ";

  } else if (temperature >= 20 && humidity < 60) {
    weather_report = "Warm and comfortable";

  } else if (temperature <= 16 ) {
    weather_report = "A little cold";
  }

  else {
    weather_report = "Weather is normal";
  }
  
  // Uploads new telemetry to ThingsBoard using HTTP.
  // See https://thingsboard.io/docs/reference/http-api/#telemetry-upload-api
  // for more details

  Serial.println("Sending temperature data...");
  tb.sendTelemetryFloat("temperature",temperature);

  Serial.println("Sending humidity data...");
  tb.sendTelemetryFloat("humidity",humidity);
  

  //carrier.display.print(weather_report);
  carrier.Buttons.update();
  refreshCount++;
}

void updateDisplay () {
  if (modeSelect == 0) {
    //configuring display, setting background color, text size and text color
    digitalWrite(TFT_BACKLIGHT, HIGH);
    carrier.display.fillScreen(ST77XX_RED); //red background
    carrier.display.setTextColor(ST77XX_WHITE); //white text
    carrier.display.setTextSize(4); //medium sized text

    carrier.display.setCursor(70, 50); //sets position for printing (x and y)
    carrier.display.print("Temp: ");
    carrier.display.setCursor(40, 110); //sets position for printing (x and y)
    carrier.display.print(temperature);
    //carrier.display.drawUTF8(60, 35, DegreeSymbol);
    //carrier.display.println(DEGREE_SYMBOL);
    carrier.display.println(" C");
  }
  else if (modeSelect == 1) {

    digitalWrite(TFT_BACKLIGHT, HIGH);
    carrier.display.fillScreen(ST77XX_BLUE); //red background
    carrier.display.setTextColor(ST77XX_WHITE); //white text
    carrier.display.setTextSize(4); //medium sized text

    carrier.display.setCursor(70, 50); //sets new position for printing (x and y)
    carrier.display.print("Humi: ");
    carrier.display.setCursor(40, 110); //sets position for printing (x and y)
    carrier.display.print(humidity);
    carrier.display.println(" %");
  }
  else if (modeSelect == 2) {

    digitalWrite(TFT_BACKLIGHT, HIGH);
    carrier.display.fillScreen(ST77XX_YELLOW);
    carrier.display.setTextColor(ST77XX_RED);
    carrier.display.setTextSize(4);

    carrier.display.setCursor(60, 60);
    carrier.display.print("Light: ");
    carrier.display.setCursor(20, 110); //sets position for printing (x and y)
    carrier.display.print(illuminance);
    carrier.display.println(" lux");
  }
  else if (modeSelect == 3) {

    digitalWrite(TFT_BACKLIGHT, HIGH);
    carrier.display.fillScreen(ST77XX_CYAN);
    carrier.display.setTextColor(ST77XX_BLACK);
    carrier.display.setTextSize(4);

    carrier.display.setCursor(60, 60);
    carrier.display.print("Press: ");
    carrier.display.setCursor(20, 110); //sets position for printing (x and y)
    carrier.display.print(illuminance); //Pressure gives error is disconnected so I use some other variable
    carrier.display.println(" Pa");
  }


  else if (modeSelect == 4) {
    carrier.display.fillScreen(ST77XX_BLACK);
    digitalWrite(TFT_BACKLIGHT, LOW);
    carrier.leds.clear();
    carrier.leds.fill();
    carrier.leds.show();

  }

  else if (modeSelect == 5) {
    carrier.leds.setBrightness(10);
    carrier.leds.fill(myCustomColor, 0, 1);
    carrier.leds.show();
    delay(5000);
    myCustomColor = carrier.leds.Color(0, 255, 0);
    carrier.leds.fill(myCustomColor, 0, 3);
    carrier.leds.show();
    delay(5000);
    carrier.leds.clear();
    carrier.leds.fill();
    carrier.leds.show();
  }

  else if (modeSelect == 6) {
    digitalWrite(TFT_BACKLIGHT, HIGH);
    carrier.display.fillScreen(ST77XX_YELLOW);
    carrier.display.setTextColor(ST77XX_RED);
    carrier.display.setTextSize(4);

    carrier.display.setCursor(60, 60);
    carrier.display.print("Haaaa");
    carrier.display.setCursor(20, 110); //sets position for printing (x and y)
    carrier.display.print("tu  Michal");
    carrier.leds.clear();
    //carrier.leds.fill()
    //carrier.leds.setBrightness(colorLightSwitch.getBrightness());
    //carrier.leds.colordLight
    //Serial.println(colorLightSwitch.getHue());
    //Serial.println(colorLightSwitch.getSaturation());
    //Serial.println(colorLightSwitch.getBrightness());
    //Serial.println(colorLightSwitch.getSwitch());
   // myCustomColor = carrier.leds.Color(0, 255, 0);

    //carrier.leds.fill(myCustomColor, 0, 5);
    carrier.leds.fill(rgbcolor1);
    carrier.leds.show();
  }


  else {
    carrier.display.fillScreen(ST77XX_BLACK);

    //pinMode(LED_BUILTIN, OUTPUT);
    //digitalWrite(LED_BUILTIN, HIGH);
    //delay(5000);
    //digitalWrite(LED_BUILTIN, LOW);
    //delay(5000);
    //digitalWrite(LED_BUILTIN, HIGH);
    //delay(5000);


    digitalWrite(TFT_BACKLIGHT, LOW);
    //carrier.display.enableDisplay(false);
    //delay(5000);
    //digitalWrite(TFT_BACKLIGHT, HIGH);
    // carrier.display.enableSleep(false);
    //carrier.display.enableDisplay(true);
    //delay(5000);
    //carrier.display.enableSleep(true);
    //delay(5000);
    //carrier.display.enableSleep(false);
  }
}





void onLEDswitchChange() {
  // Do something
}


void onColordLightChange() {
  // Do something
}


void onColordLightSwitchChange() {
  // Do something
}


void onColorLightSwitchChange() {
  // Do something
}

@missdrew do you have any suggestions?

ok I strip code completely to make it super simple and here is an issue to initialize ThingsBoard line 19

//MKR1010 + MKR IOT Carrier
#include "ThingsBoard.h"
#include "thingProperties.h"
#include <Arduino_MKRIoTCarrier.h>
#include <WiFiNINA.h>

MKRIoTCarrier carrier;

// See https://thingsboard.io/docs/getting-started-guides/helloworld/
// to understand how to obtain an access token
#define TOKEN               "ARDUINO_DEMO_TOKEN"
#define THINGSBOARD_SERVER  "vps418835.ovh.net"
#define THINGSBOARD_PORT    8080

WiFiClient client;
//ThingsBoardHttp tb(client);

// Initialize ThingsBoard instance
ThingsBoardHttp tb(client, TOKEN, THINGSBOARD_SERVER,  THINGSBOARD_PORT);

here is the build log text and error

/home/builder/opt/arduino-builder/arduino-builder -compile -core-api-version 10611 -hardware /home/builder/opt/arduino-builder/hardware -hardware /home/builder/.arduino15/packages -tools /home/builder/opt/arduino-builder/tools -tools /home/builder/.arduino15/packages -built-in-libraries /home/builder/opt/libraries/latest -logger humantags -fqbn arduino:samd:mkrwifi1010 -build-cache /tmp -build-path /tmp/372392528/build -verbose -prefs runtime.tools.CMSIS.path=/home/builder/.arduino15/packages/arduino/tools/CMSIS/4.5.0 -prefs runtime.tools.CMSIS-Atmel.path=/home/builder/.arduino15/packages/arduino/tools/CMSIS-Atmel/1.2.0 -prefs runtime.tools.arduinoOTA.path=/home/builder/.arduino15/packages/arduino/tools/arduinoOTA/1.2.1 -prefs runtime.tools.arm-none-eabi-gcc.path=/home/builder/.arduino15/packages/arduino/tools/arm-none-eabi-gcc/7-2017q4 -prefs runtime.tools.bossac.path=/home/builder/.arduino15/packages/arduino/tools/bossac/1.7.0-arduino3 -prefs runtime.tools.openocd.path=/home/builder/.arduino15/packages/arduino/tools/openocd/0.10.0-arduino7 -prefs runtime.tools.sketchUploader.path=/home/builder/.arduino15/packages/Intel/tools/sketchUploader/1.6.2+1.0 -prefs runtime.tools.rp2040tools.path=/home/builder/.arduino15/packages/arduino/tools/rp2040tools/1.0.2 -prefs runtime.tools.i586-poky-linux-uclibc.path=/home/builder/.arduino15/packages/Intel/tools/i586-poky-linux-uclibc/1.6.2+1.0 -prefs runtime.tools.mkspiffs.path=/home/builder/.arduino15/packages/esp8266/tools/mkspiffs/2.5.0-3-20ed2b9 -prefs runtime.tools.esptool.path=/home/builder/.arduino15/packages/esp8266/tools/esptool/2.5.0-3-20ed2b9 -prefs runtime.tools.xtensa-lx106-elf-gcc.path=/home/builder/.arduino15/packages/esp8266/tools/xtensa-lx106-elf-gcc/2.5.0-3-20ed2b9 -prefs runtime.tools.arc-elf32.path=/home/builder/.arduino15/packages/Intel/tools/arc-elf32/1.6.9+1.0.1 -prefs runtime.tools.avrdude.path=/home/builder/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino8 -prefs runtime.tools.esptool_py.path=/home/builder/.arduino15/packages/esp32/tools/esptool_py/3.0.0 -prefs runtime.tools.flashpack.path=/home/builder/.arduino15/packages/Intel/tools/flashpack/2.0.0 -prefs runtime.tools.avr-gcc.path=/home/builder/.arduino15/packages/arduino/tools/avr-gcc/7.3.0-atmel3.6.1-arduino7 -prefs runtime.tools.arm-linux-gcc.path=/home/builder/.arduino15/packages/arduino/tools/arm-linux-gcc/4.9.3 -prefs runtime.tools.core2-32-poky-linux.path=/home/builder/.arduino15/packages/Intel/tools/core2-32-poky-linux/1.6.2+1.0 -prefs runtime.tools.dfu-util.path=/home/builder/.arduino15/packages/arduino/tools/dfu-util/0.10.0-arduino1 -prefs runtime.tools.nrf5x-cl-tools.path=/home/builder/.arduino15/packages/arduino/tools/nrf5x-cl-tools/9.3.1 -prefs runtime.tools.x86-linux-gcc.path=/home/builder/.arduino15/packages/arduino/tools/x86-linux-gcc/7.2.0 -prefs runtime.tools.linuxuploader.path=/home/builder/.arduino15/packages/arduino/tools/linuxuploader/1.5.1 -prefs runtime.tools.serial-discovery.path=/home/builder/.arduino15/packages/builtin/tools/serial-discovery/1.2.1 -prefs runtime.tools.ctags.path=/home/builder/.arduino15/packages/builtin/tools/ctags/5.8-arduino11 -prefs runtime.tools.xtensa-esp32-elf-gcc.path=/home/builder/.arduino15/packages/esp32/tools/xtensa-esp32-elf-gcc/1.22.0-97-gc752ad5-5.2.0 -prefs runtime.tools.arduino101load.path=/home/builder/.arduino15/packages/Intel/tools/arduino101load/2.0.1 -libraries /tmp/372392528/custom -libraries /tmp/372392528/pinned /tmp/372392528/testMQTT

Multiple libraries were found for "PubSubClient.h"

Used: /home/builder/opt/libraries/latest/pubsubclient_2_8_0

Not used: /home/builder/opt/libraries/latest/esp8266_microgear_1_2_4

Not used: /home/builder/opt/libraries/latest/allthingstalk_wifi_sdk_2_1_2

Not used: /home/builder/opt/libraries/latest/acs_m1128_2_2_1_b2

Not used: /home/builder/opt/libraries/latest/cmmc_mqtt_connector_1_3_3

Not used: /home/builder/opt/libraries/latest/antares_esp8266_mqtt_0_9_2

Not used: /home/builder/opt/libraries/latest/azureiothubmqttclient_0_2_3

Multiple libraries were found for "ArduinoJson.h"

Used: /home/builder/opt/libraries/latest/arduinojson_6_18_0

Not used: /home/builder/opt/libraries/latest/balemessengerbot_arduino_0_1_0

Not used: /home/builder/opt/libraries/latest/antares_esp8266_http_1_3_1

Not used: /home/builder/opt/libraries/latest/cmmc_mqtt_connector_1_3_3

Not used: /home/builder/opt/libraries/latest/antares_esp8266_mqtt_0_9_2

Not used: /home/builder/opt/libraries/latest/thingsiot_1_2_0

Not used: /home/builder/opt/libraries/latest/coogleiot_1_3_1

Not used: /home/builder/opt/libraries/latest/thingesp_1_2_2

Not used: /home/builder/opt/libraries/latest/allthingstalk_lte_m_sdk_2_0_4

Using library adafruit_sleepydog_library_1_4_0 at version 1.4.0 in folder: /home/builder/opt/libraries/latest/adafruit_sleepydog_library_1_4_0

Using library adafruit_busio_1_7_3 at version 1.7.3 in folder: /home/builder/opt/libraries/latest/adafruit_busio_1_7_3

In file included from /tmp/372392528/testMQTT/testMQTT.ino:3:0:

/home/builder/opt/libraries/latest/thingsboard_0_4_0/src/ThingsBoard.h: In member function 'void ThingsBoardSized<PayloadSize, MaxFieldsAmt, Logger>::process_message(char, uint8_t*, unsigned int)':*

/home/builder/opt/libraries/latest/thingsboard_0_4_0/src/ThingsBoard.h:328:16: error: return-statement with a value, in function returning 'void' [-fpermissive]

return false;

*^~~~~*

/home/builder/opt/libraries/latest/thingsboard_0_4_0/src/ThingsBoard.h:334:16: error: return-statement with a value, in function returning 'void' [-fpermissive]

return false;

*^~~~~*

exit status 1