I'm trying to send a string from a Blend micro to an iOS app. I've been trying to modify the chat example but keep running into the error:
SimpleChat2.ino: In function 'void transmit(String)': SimpleChat2:128: error: invalid cast from type 'String' to type 'unsigned char*' SimpleChat2:128: error: cannot convert 'String' to 'const char*' for argument '1' to 'size_t strlen(const char*)'
I'm trying to replace the line from the example:
ble_write( Serial.read() );*
with:
String testString = "test content";
ble_write( testString );
How would I go about converting my string into something that will work?
#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();
}
I edited my previous post to fix the parentheses. But my problem is still the same. I need to know how to convert a string so that I can send it via Bluetooth.
I don't know the parameter type. These are answers I'm trying to find out by posting here. I've been searching forums and stack exchange and this problem for this board seems to come up a bunch, but there are either no answers or the ones I tried haven't worked. There is little documentation and this is all very frustrating.
It's not going well. I want to be able to send "strings" of letters and numbers. You've told me not to use strings and I've been asking from the beginning, how do I convert "strings" of characters into something that I can send. I've asked that more than once.
nonlinearmind:
It's not going well. I want to be able to send "strings" of letters and numbers. You've told me not to use strings and I've been asking from the beginning, how do I convert "strings" of characters into something that I can send. I've asked that more than once.
When you say "look at reply #7, it isn't helpful, without elaboration, when in reply #8, I show where I tried it and I still get a conversion error. Though it is :
SimpleChat:45: error: invalid conversion from 'const char*' to 'char'