Converting String to const char*

So, despite what you wrote, that isn't the same error message as in the original post, is it?
Why don't you post your code and the error message you got?

Ok, thanks gfvalvo... that helps. But I still don't know how to "prepare" a string of data so that it can be sent via one of those functions. Earlier I had tried doing this:

void transmit(String testString){uint8_t sendbuffer[20];
          testString.getBytes(sendbuffer, 20);
           char sendbuffersize = min( 20, testString.length());
      //I also tried:      uint8_t sendbuffersize = min( 20,testString.length());

          Serial.print(F("\n* Sending -> \"")); Serial.print((char *)sendbuffer); Serial.print("        ");Serial.print(sendbuffersize);Serial.println("");

          // write the data
    ble_write_bytes(sendbuffer, sendbuffersize);}

And it worked, but wasn't truncating the data once it reached the buffer size. It bunched consecutive "strings" together like this:

testing1234testingAB
CDtesting5678testing
EFGH

rather than:

testing1234
testingABCD
testing5678
testingEFGH

So that's where I am with it right now and where I'm stuck.

Can you see the difference between "string" and "String"?

It would help if you posted your code.

I think this has been mentioned.

gfvalvo Honestly, I tried it with [] and it didn't work and I thought that it might be where my variable name belongs, so I tried that. Sometimes stuff that seems obvious to folks who have been doing this for years isn't to those of us who haven't. I'm not asking for anyone to write my code for me or anything, but with little context to go on beyond a sentence or two, it leaves me left trying all sorts of things.

You keep telling me to post my code and I have all along the way. In my first post, I posted my original code.

#include <SPI.h>
#include <boards.h>
#include <RBL_nRF8001.h>

void setup()
{  
  // Default pins set to 9 and 8 for REQN and RDYN
  // Set your REQN and RDYN here before ble_begin() if you need
  //ble_set_pins(3, 2);
  
  // Set your BLE Shield name here, max. length 10
  //ble_set_name("My Name");
  
  // Init. and start BLE library.
  ble_begin();
  
  // Enable serial debug
  Serial.begin(57600);
}

unsigned char buf[16] = {0};
unsigned char len = 0;

void loop()
{
  if ( ble_available() )
  {
    while ( ble_available() )
      Serial.write(ble_read());
      
    Serial.println();
  }
  
  if ( Serial.available() )
  {
    delay(5);
    
    while ( Serial.available() ){
    
      //////This line from the example works
         ble_write( Serial.read() );

    //////These two lines of mine don't
        String testString = "test content";
        
        ble_write( testString );
    //////////////
  }
  
  }
  
  ble_do_events();
}

Then in my second post I posted code from an attempt to convert my strings into chars and explained what I was getting.

transmit("testing1234");

transmit("testingABCD");

transmit("testing5678");

transmit("testingEFGH");



void transmit(String testString){uint8_t sendbuffer[20];
          testString.getBytes(sendbuffer, 20);
           char sendbuffersize = min( 20, testString.length());
      //I also tried:      uint8_t sendbuffersize = min( 20,testString.length());

          Serial.print(F("\n* Sending -> \"")); Serial.print((char *)sendbuffer); Serial.print("        ");Serial.print(sendbuffersize);Serial.println("");

          // write the data
    ble_write_bytes(sendbuffer, sendbuffersize);}

Then I posted the same function I was trying to get working a second time in reply 21. I posted a link to the library in 13. Please be specific about what code I need to post and I will.

You should post the COMPLETE sketch of the version that almost works the way you want. Heck, it compiles and actually gives pretty much the output you're looking for. Your other version won't even compile!!! Without the full sketch, I can't see exactly what you're doing. I'm not at all familiar with this library, but you should probably call ble_do_events() after EVERY call to transmit().

Next, ditch the use of String type all together. The message that we've been trying to get across is that String != string. One is C++ and very complicated. The other is c and is just a char [] (or char * if you prefer).

Your transmit() function becomes:

void transmit(char *xmitString) {
  ble_write_bytes(xmitString, strlen(xmitString));
}

I'm not sure why your transmitted strings are being concatenated. Maybe you just need line breaks in them. Don't know what the receiving device wants try ending them with one of:

"testing1234\n"
"testing1234\n\r"
"testing1234\r\n"

Also, if you look in RBL_nRF8001.cpp, you'll see:

#define MAX_TX_BUFF 64

So, don't try to send a string longer than that (including line breaks and \0 NULL terminator).

Finally warning: I don't have your hardware or library installed. So, this is all just guidance. You might have to do some modifications.

gfvalvo:

#define MAX_TX_BUFF 64

So, don't try to send a string longer than that (including line breaks and \0 NULL terminator).

Actually, I was wrong. I don't think strlen() counts the \0 NULL terminator.