HTTP GET Not working with Char Array?


hi guys,

i have small issue trying data through http request following method.
(code summed up)
code: [select]

** ports opening , connection done before **

 client.print("get /scripts/urltosendto.php?datastring=");
 client.print(receivedchars);
 client.print(" http/1.1\r\n");
 client.print("host: ");
 client.print(host);
 client.print("\r\n");
 client.print("connection: close\r\n\r\n");



my goal serial data arduino, , insert serial data variable allow sent off through request. request works fine test string in place of "receivedchars"(i know, know, don't use string). when read serial data returns bytes , need store char array, however, client.print(*char array name*) causes request return error 400 bad request.

to elaborate little more test string. if this:

code: [select]

string testreceivedchars = "1,4,5,1,691,591,592";


and use in request works, if go:

code: [select]

testreceivedchars = recievedchars;


it breaks if use recievedchars char array.


can tell me how can around or let me know doing wrong here?
thanks much!

below method use read serial data
code: [select]


const byte numchars = 37;
char receivedchars[numchars];   // array store received data

boolean newdata = false;



void recvwithendmarker() {
    static byte ndx = 0;
    char endmarker = '\n';
    char rc;
   
    while (serial.available() > 0 && newdata == false) {
        rc = serial.read();

        if (rc != endmarker) {
            receivedchars[ndx] = rc;
            ndx++;
            if (ndx >= numchars) {
                ndx = numchars - 1;
            }
        }
        else {
            receivedchars[ndx] = '\0'; // terminate string
            ndx = 0;
            newdata = true;
        }
    }
}

void shownewdata() {
    if (newdata == true) {
        serial.println(receivedchars);
        delay(200);
        newdata = false;
    }
}

void loop()
{
  recvwithendmarker();
  shownewdata();





you can't this!  testreceivedchars = recievedchars;

testreceivedchars string not same character array.


see if reply #11 zoomkat useful   https://forum.arduino.cc/index.php?topic=286518.0


Arduino Forum > Using Arduino > Programming Questions > HTTP GET Not working with Char Array?


arduino

Comments