Arduino concatenate string and * char

I am new to arduino and I stumbled upon a problem. I want to send data via my esp8266 to my php page. But I dont know how to join my data with this GET request.

Here is my code:

String card = "2-3d-fg-d6-12-68-32-3f-35-45-42-53-2a-3";
char *hello = "GET /insert.php?card="+card+"&error=1 HTTP/1.1\r\nHost: testsite.com\r\n\r\n"; 
wifi.send((const uint8_t*)hello, strlen(hello));

      

And this is what I get in the arduino console:

error: cannot convert 'StringSumHelper' to 'char *' on initialization cannot convert 'StringSumHelper' to 'char *' on initialization

+3


source to share


1 answer


You can use a function std::string::c_str()

that returns a pointer to a const char buffer:

String card = "2-3d-fg-d6-12-68-32-3f-35-45-42-53-2a-3";
char *prefix = "GET /insert.php?card=";
char *postfix ="&error=1 HTTP/1.1\r\nHost: testsite.com\r\n\r\n"; 

String url = prefix +card+ postfix;
const char *url_complete = url.c_str();
//...

      



See also the linked post: How to concatenate a string and a char constant?

+4


source







All Articles