Hi Guys,
I have a small issue trying to get some data through to an HTTP GET Request with the following method.
(Code is summed up)
** Ports opening and connection done before this **
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 is to get serial data from another Arduino, and insert that serial data into a variable to allow it to be sent off through the GET Request. This request works perfectly fine with a test String in place of the "receivedChars"(I Know, I know, Don't Use String). But when I read the serial data it obviously returns bytes and so I will need to store it to a char array, however, client.print(char array name) always causes the GET Request to return with Error 400 Bad Request.
To elaborate a little more about the test String. If I do this:
String testReceivedChars = "1,4,5,1,691,591,592";
And use it in the GET request it works, but if I then go:
testReceivedChars = recievedChars;
It breaks as it would if I just use recievedChars char array.
Can someone tell me how I can get around this or let me know what I am doing wrong here?
Thanks so much!
Below is the method I use to Read the Serial Data
const byte numChars = 37;
char receivedChars[numChars]; // an array to store the 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 the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.println(receivedChars);
delay(200);
newData = false;
}
}
void loop()
{
recvWithEndMarker();
showNewData();