Support
Support

Reputation: 11

Unable to publish data to cloud from gateway

I installed iot gateway using this https://thingsboard.io/docs/iot-gateway/install/pip-installation/

here is ble device esp-32 ble firmware


# #include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
#include <esp_bt_main.h>
#include <esp_bt_device.h>

// BLE characteristic for transmitting data
BLECharacteristic *characteristicTX;

bool deviceConnected = false;

// UUIDs for the BLE service and characteristics
#define SERVICE_UUID           "ab0828b1-198e-4351-b779-901fa0e0371e"
#define CHARACTERISTIC_UUID_TX "0972EF8C-7613-4075-AD52-756F33D4DA91"

// Callback for connection events
class ServerCallbacks: public BLEServerCallbacks {
    void onConnect(BLEServer* pServer) {
      deviceConnected = true;
    };

    void onDisconnect(BLEServer* pServer) {
      deviceConnected = false;
    }
};

void setup() {
  Serial.begin(115200);

  // Create the BLE Device
  BLEDevice::init("ESP32-BLE");

  // Ensure Bluetooth stack is initialized
  if (!btStart()) {
    Serial.println("Failed to initialize controller");
    return;
  }

  // Get the BLE MAC address
  const uint8_t* mac = esp_bt_dev_get_address();
  char macStr[18];
  snprintf(macStr, sizeof(macStr), "%02X:%02X:%02X:%02X:%02X:%02X", 
           mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);

  // Print the BLE MAC address to the Serial Monitor
  Serial.print("BLE MAC Address: ");
  Serial.println(macStr);

  // Create the BLE Server
  BLEServer *server = BLEDevice::createServer();
  server->setCallbacks(new ServerCallbacks());

  // Create the BLE Service
  BLEService *service = server->createService(SERVICE_UUID);

  // Create a BLE Characteristic for transmitting data
  characteristicTX = service->createCharacteristic(
                      CHARACTERISTIC_UUID_TX,
                      BLECharacteristic::PROPERTY_NOTIFY
                    );
  characteristicTX->addDescriptor(new BLE2902());

  // Start the service
  service->start();
  // Start advertising
  server->getAdvertising()->start();

  Serial.println("Waiting for a client connection to notify...");
}

void loop() {
  if (deviceConnected) {
    // Use fixed values for demonstration
    int temperatureC = 26;
    String carNumber = "B23";
    int latitude = 50;
    int longitude = 36;
    String status = "out";

    // Create a comma-separated string with all the data
    String txString = String(temperatureC) + "," + carNumber + "," + 
                      String(latitude) + "," + String(longitude) + "," + status;

    // Send data via BLE
    characteristicTX->setValue(txString.c_str());       
    characteristicTX->notify(); 

    Serial.print("*** Sent Value via BLE: ");
    Serial.print(txString);
    Serial.println(" ***");
  }
  delay(1000);
}
{
  "name": "BLE Connector",
  "passiveScanMode": false,
  "showMap": true,
  "devices": [
    {
      "name": "ESP32-BLE",
      "MACAddress": "D0:EF:76:48:01:3A",
      "pollPeriod": 5000,
      "showMap": true,
      "timeout": 10000,
      "connectRetry": 5,
      "connectRetryInSeconds": 0,
      "waitAfterConnectRetries": 10,
      "attributes": [],
      "serverSideRpc": [
          {
              "methodRPC": "sharedName",
              "withResponse": true,
              "characteristicUUID": "ab0828b1-198e-4351-b779-901fa0e0371e",
              "methodProcessing": "write"
          }
        ],

      "telemetry": [
        {
          "key": "temperature",
          "method": "notify",
          "characteristicUUID": "0972EF8C-7613-4075-AD52-756F33D4DA91",
          "byteFrom": 0,
          "byteTo": -1
        },
        {
          "key": "car_number",
          "method": "notify",
          "characteristicUUID": "0972EF8C-7613-4075-AD52-756F33D4DA91",
          "byteFrom": 0,
          "byteTo": -1
        },
        {
          "key": "latitude",
          "method": "notify",
          "characteristicUUID": "0972EF8C-7613-4075-AD52-756F33D4DA91",
          "byteFrom": 0,
          "byteTo": -1
        },
        {
          "key": "longitude",
          "method": "notify",
          "characteristicUUID": "0972EF8C-7613-4075-AD52-756F33D4DA91",
          "byteFrom": 0,
          "byteTo": -1
        },
        {
          "key": "status",
          "method": "notify",
          "characteristicUUID": "0972EF8C-7613-4075-AD52-756F33D4DA91",
          "byteFrom": 0,
          "byteTo": -1
        }
      ]
    }
  ],
  "id": "54f7e7c2-aee1-4a3f-8348-38332e00b075"
} 
and tb_gateway.json
{
  "thingsboard": {
    "host": "thingsboard.cloud",
    "port": 1883,
    "remoteShell": false,
    "remoteConfiguration": true,
    "statistics": {
      "enable": true,
      "statsSendPeriodInSeconds": 3600
    },
    "deviceFiltering": {
      "enable": false,
      "filterFile": "list.json"
    },
    "maxPayloadSizeBytes": 1024,
    "minPackSendDelayMS": 200,
    "minPackSizeToSend": 500,
    "checkConnectorsConfigurationInSeconds": 60,
    "handleDeviceRenaming": true,
    "security": {
      "type": "accessToken",
      "accessToken": "D0:EF:76:48:01:3A"
    },
    "qos": 1,
    "checkingDeviceActivity": {
      "checkDeviceInactivity": false,
      "inactivityTimeoutSeconds": 200,
      "inactivityCheckPeriodSeconds": 500
    }
  },
  "storage": {
    "type": "memory",
    "read_records_count": 100,
    "max_records_count": 100000,
    "data_folder_path": "./data/",
    "max_file_count": 10,
    "max_read_records_count": 10,
    "max_records_per_file": 10000,
    "data_file_path": "./data/data.db",
    "messages_ttl_check_in_hours": 1,
    "messages_ttl_in_days": 7
  },
  "grpc": {
    "enabled": false,
    "serverPort": 9595,
    "keepaliveTimeMs": 10000,
    "keepaliveTimeoutMs": 5000,
    "keepalivePermitWithoutCalls": true,
    "maxPingsWithoutData": 0,
    "minTimeBetweenPingsMs": 10000,
    "minPingIntervalWithoutDataMs": 5000,
    "keepAliveTimeMs": 10000,
    "keepAliveTimeoutMs": 5000
  },
  "connectors": [

    {
      "type": "ble",
      "name": "BLE Connector",
      "configuration":"ble.json"
    }

  ]
}

In tb_gateway.json I have given the access token of device i already created on cloud, isgateway option also selected

Errors

2024-06-12 07:33:19 - |ERROR| - [tb_gateway_mqtt.py] - tb_gateway_mqtt - _on_connect - 73 - Service subscription to topic v1/gateway/rpc - failed.
2024-06-12 07:33:19 - |INFO| - [tb_gateway_mqtt.py] - tb_gateway_mqtt - gw_subscribe_to_attribute - 199 - Subscribed to *|* with id 2 for device *
2024-06-12 07:33:36 - |ERROR| - [tb_gateway_mqtt.py] - tb_gateway_mqtt - _on_connect - 65 - Service subscription to topic v1/gateway/attributes/response - failed.
2024-06-12 07:33:42 - |ERROR| - [tb_gateway_mqtt.py] - tb_gateway_mqtt - _on_connect - 73 - Service subscription to topic v1/gateway/rpc - failed.

I simply want to put telemetry data receiving from my ble device to cloud

Upvotes: 0

Views: 64

Answers (0)

Related Questions