NimBLE library for help

#include <Arduino.h>
#include <BluetoothSerial.h>
#include <L298N.h>
// #include <WiFi.h>
// #include <AsyncTCP.h>
// #include <ESPAsyncWebServer.h>
// #include <AsyncElegantOTA.h>
#include <NimBLEDevice.h>
#include <NimBLECharacteristic.h>




NimBLEDevice  ble_device;
NimBLECharacteristic mycharacteristic;
BluetoothSerial bt;


const unsigned int IN1_A = 12;
const unsigned int IN2_A = 13;

const unsigned int IN3_B = 14;
const unsigned int IN4_B = 27;


const unsigned int IN5_C = 26;
const unsigned int IN6_C = 25;

const unsigned int IN7_D = 33;
const unsigned int IN8_D = 32;




L298N motor1(IN1_A,IN2_A);
L298N motor2(IN3_B,IN4_B);
L298N motor3(IN5_C,IN6_C);
L298N motor4(IN7_D,IN8_D);


void qianjin(){  //前进
  motor1.forward(); 
  motor2.forward();
  motor3.forward();
  motor4.forward();
}

void houtui(){   //后退  
  motor1.backward(); 
  motor2.backward();
  motor3.backward();
  motor4.backward();
}

void zuopiaoyi(){  //左漂移
  motor1.backward(); 
  motor2.forward();
  motor3.forward();
  motor4.backward();
}

void youpiaoyi(){  //右漂移
  motor1.forward(); 
  motor2.backward();
  motor3.backward();
  motor4.forward();
}

void shache(){    //刹车
  motor1.stop(); 
  motor2.stop();
  motor3.stop();
  motor4.stop();
}

void youzhuan(){    //右转
  motor1.forward();
  motor3.forward();
}  

void zuozhuan(){     //左转
  motor1.backward();
  motor3.backward();
}

void yuandixuanzhuan(){  //原地旋转
  motor1.forward();
  motor2.backward();
  motor3.forward();
  motor4.backward();
}


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

  ble_device.init();
  mycharacteristic.getUUID();
  
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(27, OUTPUT);
  pinMode(26, OUTPUT);
  pinMode(25, OUTPUT);
  pinMode(33, OUTPUT);
  pinMode(32, OUTPUT);
  
  delay(1000);
}
  
  
void loop() {
  if (mycharacteristic.getDataLength() > 0) {
      mycharacteristic.getValue();
      Serial.println(mycharacteristic.getValue());
    
    delay(500);

    
}


src/main.cpp:18:19: error: no matching function for call to 'NimBLECharacteristic::NimBLECharacteristic()'
 BLECharacteristic NimBLECharacteristic;
                   ^~~~~~~~~~~~~~~~~~~~
In file included from .pio/libdeps/esp32dev/NimBLE-Arduino/src/NimBLEService.h:22,
                 from .pio/libdeps/esp32dev/NimBLE-Arduino/src/NimBLEServer.h:33,
                 from .pio/libdeps/esp32dev/NimBLE-Arduino/src/NimBLEDevice.h:38,
                 from src/main.cpp:8:
.pio/libdeps/esp32dev/NimBLE-Arduino/src/NimBLECharacteristic.h:71:5: note: candidate: 'NimBLECharacteristic::NimBLECharacteristic(const NimBLEUUID&, uint16_t, uint16_t, NimBLEService*)'
     NimBLECharacteristic(const NimBLEUUID &uuid,
     ^~~~~~~~~~~~~~~~~~~~
.pio/libdeps/esp32dev/NimBLE-Arduino/src/NimBLECharacteristic.h:71:5: note:   candidate expects 4 arguments, 0 provided
.pio/libdeps/esp32dev/NimBLE-Arduino/src/NimBLECharacteristic.h:65:5: note: candidate: 'NimBLECharacteristic::NimBLECharacteristic(const char*, uint16_t, uint16_t, NimBLEService*)'
     NimBLECharacteristic(const char* uuid,
     ^~~~~~~~~~~~~~~~~~~~
.pio/libdeps/esp32dev/NimBLE-Arduino/src/NimBLECharacteristic.h:65:5: note:   candidate expects 4 arguments, 0 provided
.pio/libdeps/esp32dev/NimBLE-Arduino/src/NimBLECharacteristic.h:63:7: note: candidate: 'NimBLECharacteristic::NimBLECharacteristic(const NimBLECharacteristic&)'       
 class NimBLECharacteristic {
       ^~~~~~~~~~~~~~~~~~~~
.pio/libdeps/esp32dev/NimBLE-Arduino/src/NimBLECharacteristic.h:63:7: note:   candidate expects 1 argument, 0 provided
src/main.cpp: In function 'void setup()':
src/main.cpp:121:3: error: 'mycharacteristic' was not declared in this scope
   mycharacteristic.
   ^~~~~~~~~~~~~~~~
src/main.cpp:121:3: note: suggested alternative: 'BLECharacteristic'
   mycharacteristic.
   ^~~~~~~~~~~~~~~~
   BLECharacteristic
src/main.cpp: In function 'void loop()':
src/main.cpp:142:7: error: 'mycharacteristic' was not declared in this scope
   if (mycharacteristic.getDataLength() > 0) {
       ^~~~~~~~~~~~~~~~
src/main.cpp:142:7: note: suggested alternative: 'BLECharacteristic'
   if (mycharacteristic.getDataLength() > 0) {
       ^~~~~~~~~~~~~~~~
       BLECharacteristic
*** [.pio\build\esp32dev\src\main.cpp.o] Error 1

Please can you also paste your code in code tags too.

OK,uploaded,thanks.

You can't define an "empty" characteristic, it should be created and initializated by createCharacteristic() method:

BLECharacteristic *pCharacteristic = pService->createCharacteristic(
                                     CHARACTERISTIC_UUID,
                                     NIMBLE_PROPERTY::READ |
                                     NIMBLE_PROPERTY::WRITE
                                    );

See the manual:
https://h2zero.github.io/esp-nimble-cpp/md__migration_guide.html#characteristics

https://h2zero.github.io/esp-nimble-cpp/class_nim_b_l_e_characteristic.html

I have never used pointers and cannot instantiate them. How can I use the other functions in the class?

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