-2

I am building a device for my research team. To briefly describe it, this device uses a motor and load sensor connected to an Arduino to apply a rotational force to a corn stalk and record the resistance of the stalk. We are in the process of building Bluetooth into the device. We are using this BT module. We have a BLE GATT Service with 2 characteristics for storing DATA and 1 for holding the command which is an integer that will be read by the device and acted on. Reading the command characteristic is where we encounter our problem.

void get_input(){
     uint16_t bufSize = 15;
     char inputBuffer[bufSize];
     bleParse = Adafruit_ATParser();    // Throws error: bleParse was not declared in this scope
     bleParse.atcommandStrReply("AT+GATTCHAR=3",&inputBuffer,bufSize,1000); 
     Serial.print("input:");
     Serial.println(inputBuffer);
}

The functions I am trying to use are found in the library for the module in Adarfruit_ATParser.cpp

/******************************************************************************/
/*!
    @brief Constructor
*/
/******************************************************************************/
Adafruit_ATParser::Adafruit_ATParser(void)
{
  _mode    = BLUEFRUIT_MODE_COMMAND;
  _verbose = false;
}


******************************************************************************/
/*!
    @brief Send an AT command and get multiline string response into
           user-provided buffer.
    @param[in] cmd Command
    @param[in] buf Provided buffer
    @param[in] bufsize buffer size
    @param[in] timeout timeout in milliseconds
*/
/******************************************************************************/
uint16_t Adafruit_ATParser::atcommandStrReply(const char cmd[], char* buf, uint16_t bufsize, uint16_t timeout)
{
  uint16_t result_bytes;
  uint8_t current_mode = _mode;
  // switch mode if necessary to execute command
  if ( current_mode == BLUEFRUIT_MODE_DATA ) setMode(BLUEFRUIT_MODE_COMMAND);

  // Execute command with parameter and get response
  println(cmd);
  result_bytes = this->readline(buf, bufsize, timeout, true);

  // switch back if necessary
  if ( current_mode == BLUEFRUIT_MODE_DATA ) setMode(BLUEFRUIT_MODE_DATA);

  return result_bytes;
}

None of the examples in the library use this. They all create their own parsers. For example, the neopixel_picker example sketch has a file called packetParser.cpp which I believe retrieves data from the BT module for that specific sketch, but it never includes or uses Adafruit_ATParser.. There are no examples of this constructor anywhere and I cannot figure out how to use it. I have tried these ways:
bleParse = Adafruit_ATParser();
Adafruit_ATParser bleParse();
Adafruit_ATParser();
ble.Adafruit_ATParser bleParse();
note: ble is an object that signifies a Serial connection between arduino and BT created with:

SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);
Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);

Can anyone give me a clue on how to use the Adafruit_ATParser() constructor? Also, if the constructor has no reference to the ble object, how does it pass AT commands to the BT module?

I know this is a big ask, I appreciate any input you can give me.

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190

1 Answers1

1

Like this

Adafruit_ATParser bleParse;

You were closest with this one Adafruit_ATParser bleParse();. This is a common beginner mistake because it looks right. Unfortunately it declares a function bleParse which takes no arguments and returns a Adafruit_ATParser object.

I can't answer the second question.

EDIT

I've taken the time to have a look at the code. This is what I found

class Adafruit_BluefruitLE_UART : public Adafruit_BLE
{

and

class Adafruit_BLE : public Adafruit_ATParser
{

what this means is that the Adafruit_BluefruitLE_UART class is derived from the Adafruit_BLE class which in turn is derived from the Adafruit_ATParser class. Derivation means that any public methods in Adafruit_BLE can also be used on a Adafruit_BluefruitLE_UART object. You already have an Adafruit_BluefruitLE_UART object (you called it ble) so you can just use the method you want to use on that object.

SoftwareSerial bluefruitSS = SoftwareSerial(BLUEFRUIT_SWUART_TXD_PIN, BLUEFRUIT_SWUART_RXD_PIN);
Adafruit_BluefruitLE_UART ble(bluefruitSS, BLUEFRUIT_UART_MODE_PIN,BLUEFRUIT_UART_CTS_PIN, BLUEFRUIT_UART_RTS_PIN);
ble.atcommandStrReply( ... );
john
  • 85,011
  • 4
  • 57
  • 81
  • Using `Adafruit_ATParser bleParse` Gets compiler error `cannot declare variable 'bleParse' to be of abstract type 'Adafruit_ATParser'` What does this mean? – KopiousKarp Jun 15 '22 at 20:50
  • 1
    @KopiousKarp Well that means you have to find another class **derived** from `Adafruit_ATParser`. Presumably that class will also answer your second question. And obviously this explains why you couldn't find any examples, you are not meant to use that class directly. – john Jun 15 '22 at 20:56
  • 1
    @KopiousKarp Rereading your question, I would say that you are meant to write the class derived from `Adafruit_ATParser` yourself. That what the implication is when you said *They all create their own parsers*. I'm guessing that's what you are expected to do with this library. – john Jun 15 '22 at 20:58
  • Can you derive and build on a class that is not even mentioned or included? As far as I can tell, the examples just reinvent the wheel. There are no connections from the examples to `Adafruit_ATParser`. Perhaps I can create my own class to connect the dots? Should I make a Adafruit_ATParser object an attribute of my new class? I appreciate your help – KopiousKarp Jun 15 '22 at 21:15
  • 1
    @KopiousKarp I've taken the trouble to look at the code. I think I have the solution. Please see editted question above. – john Jun 15 '22 at 21:15