ESP32-S3 BLE compile error "Duplicate label"

Hello!
I tried to compile this code, which I found here:GitHub - andi38/TPMS: Decode tire pressure monitoring system TPMS BLE 433MHz CC1101 ESP8266 ESP32.

/*
   Based on Neil Kolban example for IDF: https://github.com/nkolban/esp32-snippets/blob/master/cpp_utils/tests/BLE%20Tests/SampleScan.cpp
   Ported to Arduino ESP32 by Evandro Copercini
*/

#include "BLEDevice.h"
#include "BLEUtils.h"
#include "BLEScan.h"
#include "BLEAdvertisedDevice.h"

int scanTime = 5;  //In seconds
BLEScan *pBLEScan;
BLEUtils utils;

char convertCharToHex(char ch)
{
  char returnType;
  switch(ch)
  {
    case '0':
    returnType = 0;
    break;
    case  '1' :
    returnType = 1;
    break;
    case  '2':
    returnType = 2;
    break;
    case  '3':
    returnType = 3;
    break;
    case  '4' :
    returnType = 4;
    break;
    case  '5':
    returnType = 5;
    break;
    case  '6':
    returnType = 6;
    break;
    case  '7':
    returnType = 7;
    break;
    case  '8':
    returnType = 8;
    break;
    case  '9':
    returnType = 9;
    break;
    case  'a':
    returnType = 10;
    break;
    case  'b':
    returnType = 11;
    break;
    case  'c':
    returnType = 12;
    break;
    case  'd':
    returnType = 13;
    break;
    case  'e':
    returnType = 14;
    break;
    case  'f' :
    returnType = 15;
    break;
    default:
    returnType = 0;
    break;
  }
  return returnType;
}

//class MyAdvertisedDeviceCallbacks : public BLEAdvertisedDeviceCallbacks {
  //void onResult(BLEAdvertisedDevice advertisedDevice) {
    //Serial.printf("Advertised Device: %s \n", advertisedDevice.toString().c_str());
  //}
//};

class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
  void onResult(BLEAdvertisedDevice advertisedDevice) {
    String addr = advertisedDevice.getAddress().toString().c_str();
    String mfdata = advertisedDevice.getManufacturerData().c_str();
    uint8_t* payload = advertisedDevice.getPayload();
    uint8_t payloadlen = advertisedDevice.getPayloadLength();
    char *payloadhex = utils.buildHexData(nullptr, payload, payloadlen);
    if (addr.startsWith("ac:15:85")) {  // my sensors MAC start with ac:15:85
      Serial.print("Payload: "); Serial.print(payloadhex);

// convert hex-payload to array
      char *pPL = utils.buildHexData(nullptr, (uint8_t*)advertisedDevice.getPayload(), advertisedDevice.getPayloadLength());
      String sPL = (String) pPL;
      byte plByte[16];
      byte plNib[31];
      sPL.getBytes(plNib,31);
      for (int i=0; i<30; i=i+2) {
        plByte[i/2] = convertCharToHex(plNib[i])*16 + convertCharToHex(plNib[i+1]);
      }
        
      Serial.print("  ADDR: "); Serial.print(addr.substring(12));
      char*pHex = utils.buildHexData(nullptr, (uint8_t*)advertisedDevice.getManufacturerData().toInt(), advertisedDevice.getManufacturerData().length());
      Serial.print("  MFG DATA: "); Serial.print(pHex);
      String sHex = (String) pHex;
      byte nib[16];
      sHex.getBytes(nib,15);
      for (int i=0; i<14; i++) {
        nib[i] = convertCharToHex(nib[i]);
      }
      float Press = (float)((nib[7]*256+nib[8]*16+nib[9])-145)/10.0;
      String sPress = (String)Press;
      Serial.print("  p: "); Serial.print(sPress.substring(0,sPress.length()-1));
      int Temp = nib[4]*16+nib[5];
      Serial.print("  T: "); Serial.print(Temp);
      float Batt = (float)(nib[2]*16+nib[3])/10.0;
      String sBatt = (String)Batt;
      Serial.print("  b: "); Serial.print(sBatt.substring(0,sBatt.length()-1));
      Serial.print("  BIN: ");
      for (int i=0; i<2; i++) {prtnib:(nib[i]);}
      Serial.print(".");
      for (int i=2; i<4; i++) {prtnib:(nib[i]);}
      Serial.print(".");
      for (int i=4; i<6; i++) {prtnib:(nib[i]);}
      //Serial.print(".");
      //for (int i=6; i<10; i++) {prtnib:(nib[i]);}
      //Serial.print(".");
      //for (int i=10; i<14; i++) {prtnib:(nib[i]);}

      bool nl = false;
      if (nib[0]==8) {Serial.print("   ALARM"); nl=true;}
      if (nib[0]==4) {Serial.print("   ROTAT"); nl=true;}
      if (nib[0]==2) {Serial.print("   STILL"); nl=true;}
      if (nib[0]==1) {Serial.print("   BGROT"); nl=true;}
      if (nib[1]==8) {Serial.println("   DECR2"); nl=false;}
      if (nib[1]==4) {Serial.println("   RISIN"); nl=false;}
      if (nib[1]==2) {Serial.println("   DECR1"); nl=false;}
      if ((nib[0]*16+nib[1])==0xff) {Serial.println("   LBATT");}
      if (nl) {Serial.println();}
    }
  }
};


void setup() {
  Serial.begin(115200);
  delay(500);
  Serial.println("Scanning...");

  BLEDevice::init("");
  pBLEScan = BLEDevice::getScan();  //create new scan
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks());
  pBLEScan->setActiveScan(true);  //active scan uses more power, but get results faster
  pBLEScan->setInterval(100);
  pBLEScan->setWindow(99);  // less or equal setInterval value
}

void loop() {
  // put your main code here, to run repeatedly:
  BLEScanResults *foundDevices = pBLEScan->start(scanTime, false);
  Serial.print("Devices found: ");
  Serial.println(foundDevices->getCount());
  Serial.println("Scan done!");
  pBLEScan->clearResults();  // delete results fromBLEScan buffer to release memory
  delay(2000);
}

The error received:
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino: In member function 'virtual void MyAdvertisedDeviceCallbacks::onResult(BLEAdvertisedDevice)':
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino:121:32: error: duplicate label 'prtnib'
121 | for (int i=2; i<4; i++) {prtnib:(nib[i]);}
| ^~~~~~
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino:123:32: error: duplicate label 'prtnib'
123 | for (int i=4; i<6; i++) {prtnib:(nib[i]);}
| ^~~~~~

exit status 1

Compilation error: duplicate label 'prtnib'

Don't understand why....

Welcome to the forum

prtnib:(nib[i]);

Please explain the syntax of this code snippet. What is the purpose of the colon ?

Thanks for your prompt reply!!!
I'm trying to print bytes.
One clarification: I'm new with arduino...

@jor742002: How did you copy the code from the GitHub site you linked to? There is no colon in the code BLE_TPMS.ino at GitHub.

Clear! Sorry!
I remover colon and now:
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino: In member function 'virtual void MyAdvertisedDeviceCallbacks::onResult(BLEAdvertisedDevice)':
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino:119:32: error: 'prtnib' was not declared in this scope
119 | for (int i=0; i<2; i++) {prtnib(nib[i]);}
| ^~~~~~
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino:121:32: error: 'prtnib' was not declared in this scope
121 | for (int i=2; i<4; i++) {prtnib(nib[i]);}
| ^~~~~~
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino:123:32: error: 'prtnib' was not declared in this scope
123 | for (int i=4; i<6; i++) {prtnib(nib[i]);}
| ^~~~~~
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino:125:33: error: 'prtnib' was not declared in this scope
125 | for (int i=6; i<10; i++) {prtnib(nib[i]);}
| ^~~~~~
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino:127:34: error: 'prtnib' was not declared in this scope
127 | for (int i=10; i<14; i++) {prtnib(nib[i]);}
| ^~~~~~

exit status 1

Compilation error: 'prtnib' was not declared in this scope

Again, how did you copy the .ino from GitHub? Obviously you did it wrong.
At Github the function is there:

void prtnib(int n) {
  if (n>=8) {Serial.print("1"); n-=8;} else {Serial.print("0");}
  if (n>=4) {Serial.print("1"); n-=4;} else {Serial.print("0");}
  if (n>=2) {Serial.print("1"); n-=2;} else {Serial.print("0");}
  if (n>=1) {Serial.print("1");} else {Serial.print("0");}
}

but in your code its missing.
You can download the complete code by clicking on the download symbol
Screenshot 2025-03-18 162834
at the top.

Thanks a lot Mirco for your patience!
As I mention I'm new in Arduino....
Now I download code properly and have these errors:
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino: In member function 'virtual void MyAdvertisedDeviceCallbacks::onResult(BLEAdvertisedDevice)':
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino:96:97: error: 'class String' has no member named 'data'
96 | char pHex = utils.buildHexData(nullptr, (uint8_t)advertisedDevice.getManufacturerData().data(), advertisedDevice.getManufacturerData().length());
| ^~~~
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino: In function 'void loop()':
C:\Users\yyordanov\Documents\Arduino\ESP32_TPMS_lite1\ESP32_TPMS_lite1.ino:159:48: error: conversion from 'BLEScanResults*' to non-scalar type 'BLEScanResults' requested
159 | BLEScanResults foundDevices = pBLEScan->start(scanTime, false);
| ~^~~

exit status 1

Compilation error: 'class String' has no member named 'data'

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.