http Get Request Inputting Parameters Sprintf

when i did request as:

client.print("GET /api/Test/Getvalues/12579088/123 HTTP/1.1\r\nHost:192.168.10.191\r\nConnection: close\r\n\r\n");

it is giving proper response ...

but when i input my parameter instead of 12379088 using sprintf its failing more number of times:

char buf[100];
volatile long extract;
extract = (reader1 >> 1) & 0xFFFFFF;
Serial.println(extract);

 sprintf(buf, "GET /api/Test/Getvalues/%08lu/123 HTTP/1.1\r\nHost: 192.168.10.191\r\nConnection: close\r\n\r\n", extract);

sendget like:

if (client.connect(server, 8484) == 1) { //starts client connection, checks for connection
    Serial.println(F("connected"));
    client.print(buf);
    }

it is more than 100 chars. use 128

i did it but same problem
code:

#include <w5100.h>
#include "pins_arduino.h"

#define ID_LEN 34
#define DATA_PIN_0 4
#define DATA_PIN_1 5
#include <SPI.h>
#include <Ethernet.h>
unsigned long startTime;
unsigned long interval = 5000;
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress gateway( 192, 168, 10, 3);
IPAddress subnet( 255, 255, 255, 0 );
IPAddress dns1( 59, 144, 127, 16);
IPAddress ip(192, 168, 10, 14);
IPAddress server( 192, 168, 10, 191);
EthernetClient client;
String data;
volatile long extract;
int start;
int ind1; // - locations
int ind2;
char buf[128];

//////////////////////

volatile uint8_t *port_to_pcmask[] = { &PCMSK0, &PCMSK1, &PCMSK2 };
typedef void (*voidFuncPtr)(void);
volatile static voidFuncPtr PCintFunc[24] = { NULL };
volatile static uint8_t PCintLast[3];

////////////////////////////////////////
// attach an interrupt to a specific pin using pin change interrupts.
void PCattachInterrupt(uint8_t pin, void (*userFunc)(void), int mode)
{

  uint8_t bit = digitalPinToBitMask(pin);
  uint8_t port = digitalPinToPort(pin);
  uint8_t slot;
  volatile uint8_t *pcmask;

  if (mode != CHANGE)
  {
    return;
  }

  // map pin to PCIR register
  if (port == NOT_A_PORT)
  {
    return;
  }
  else
  {
    port -= 2;
    pcmask = port_to_pcmask[port];
  }

  slot = port * 8 + (pin % 8);
  PCintFunc[slot] = userFunc;

  // set the mask
  *pcmask |= bit;

  // enable the interrupt
  PCICR |= 0x01 << port;

}

////////////////////////////////////////
void PCdetachInterrupt(uint8_t pin)
{
  uint8_t bit = digitalPinToBitMask(pin);
  uint8_t port = digitalPinToPort(pin);
  volatile uint8_t *pcmask;

  // map pin to PCIR register
  if (port == NOT_A_PORT)
  {
    return;
  }
  else
  {
    port -= 2;
    pcmask = port_to_pcmask[port];
  }

  // disable the mask.
  *pcmask &= ~bit;

  // if that's the last one, disable the interrupt.
  if (*pcmask == 0)
  {
    PCICR &= ~(0x01 << port);
  }
}

////////////////////////////////////////
// common code for isr handler. "port" is the PCINT number.
// there isn't really a good way to back-map ports and masks to pins.
static void PCint(uint8_t port)
{
  uint8_t bit;
  uint8_t curr;
  uint8_t mask;
  uint8_t pin;

  // get the pin states for the indicated port.
  curr = *portInputRegister(port + 2);
  mask = curr ^ PCintLast[port];
  PCintLast[port] = curr;

  // mask is pins that have changed. screen out non pcint pins.
  if ((mask &= *port_to_pcmask[port]) == 0)
  {
    return;
  }

  // mask is pcint pins that have changed.
  for (uint8_t i = 0; i < 8; i++)
  {
    bit = 0x01 << i;
    if (bit & mask)
    {
      pin = port * 8 + i;
      if (PCintFunc[pin] != NULL)
      {
        PCintFunc[pin]();
      }
    }
  }
}

////////////////////////////////////////
SIGNAL(PCINT0_vect)
{
  PCint(0);
}

////////////////////////////////////////
SIGNAL(PCINT1_vect)
{
  PCint(1);
}

////////////////////////////////////////
SIGNAL(PCINT2_vect)
{
  PCint(2);
}

////////////////////////////////////////////////////////
// end of interrupt code
////////////////////////////////////////////////////////

volatile long reader1 = 0;
volatile int reader1Count = 0;

////////////////////////////////////////
void read0(void)
{
  if (digitalRead(DATA_PIN_0) == LOW)
  {
    reader1Count++;
    reader1 = reader1 << 1;
    // Serial.print("0");
  }
}

////////////////////////////////////////
void read1(void)
{
  if (digitalRead(DATA_PIN_1) == LOW)
  {
    reader1Count++;
    reader1 = reader1 << 1;
    reader1 |= 1;
    //Serial.print("1");
  }
}


void setup() {

  // Open serial communications and wait for port to open:

  PCattachInterrupt(DATA_PIN_0, read0, CHANGE);//Attachinterrupt D0
  PCattachInterrupt(DATA_PIN_1, read1, CHANGE);//Attachinterrupt D1
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  digitalWrite (2, LOW);
  digitalWrite (3, LOW);
  delay(10);

  for (int i = 4; i < 5; i++)
  {
    pinMode(i, OUTPUT);
    digitalWrite(i, HIGH); // enable internal pull up causing a one
    digitalWrite(i, LOW);  // disable internal pull up causing zero and thus an interrupt
    pinMode(i, INPUT);
    digitalWrite(i, HIGH); // enable internal pull up
  }



  reader1 = 0;
  reader1Count = 0;



  Serial.begin(115200);
  Ethernet.begin(mac, ip, dns1, gateway, subnet);
  delay(2000);
  client.setTimeout(200);
  W5100.setRetransmissionTime(1000);
  W5100.setRetransmissionCount(2);
  Serial.println("Ready");
  Serial.println(F("Please Give Your Punch")); // what to do to test

}

void loop() {
  if (reader1Count >= ID_LEN)
  {

    Serial.println(F(""));
    Serial.println(F("---------------------"));
    Serial.print(F("data: "));


    extract = (reader1 >> 1) & 0xFFFFFF;
    Serial.println(extract);

    sprintf(buf, "GET /api/Test/Getvalues/%08lu/123 HTTP/1.1\r\nHost: 192.168.10.191\r\nConnection: close\r\n\r\n", extract);
    
    Serial.print( buf );


    Serial.println(F("---------------------"));
    delay(250);
    sendGET();

    reader1 = 0;
    reader1Count = 0;

  }
}



void sendGET()
{
  if (client.connect(server, 8484) == 1) { //starts client connection, checks for connection
    Serial.println(F("connected"));


    const unsigned long startTimestamp = micros();
   
    client.print(buf);    

    const unsigned long endTimestamp = micros();
    Serial.println(endTimestamp - startTimestamp);
    Serial.println(F("request sent"));
  }
  else {
    Serial.println(F("connection failed")); //error message if no client connect

    Serial.println();
  }

  String readString;
  String line ;
  int lines_received = 0;
  while (client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() && client.available()) { //connected or data available
    // client.flush();
    char c = client.read();

    readString.concat(c);

  }

  client.stop();
  Serial.println(F("client disconnected."));
  Serial.println("Data from server captured in readString:");
  Serial.println();
  Serial.print(readString); //prints readString to serial monitor
  Serial.println();
  start = readString.indexOf(" ");  //finds a unique start location
  ind1 = readString.indexOf('"', start + 2); //finds location of first -
  ind2 = readString.indexOf('"', ind1 + 1 ); //finds location of second -
  data = readString.substring(ind1 + 1, ind2); //captures data String
  Serial.print("my data is: ");
  Serial.println(data);
  char charBuf[50];
  data.toCharArray(charBuf, 1024) ;
  int length = strlen(charBuf);
  char end_char = charBuf[strlen(charBuf) - 1]; ;
  Serial.print(F("Received:"));
  Serial.println(charBuf);
  Serial.print(F("Received:"));
  Serial.println(end_char);
  Serial.println();
  if (end_char == '1') {
    Serial.println(F("Plz open the Turnstile"));
    // startTime  = millis();
    Serial.println(F("RELAY TURN ON"));
    digitalWrite (2, HIGH);
    delay(2000);


  }
  else {
    Serial.println(F("Wrong Entry"));
    digitalWrite (3, HIGH);
    delay(200);
    digitalWrite (3, LOW);

  }

  digitalWrite (2, LOW);
  Serial.println(F("RELAY TURN OFF"));

  Serial.println("End of readString");
  Serial.println("==================");
  Serial.println();
  readString = ""; //clear readString variable
  data = ""; //clear data variable
}
Serial.print( buf );

What are you seeing on serial monitor?

solved :slight_smile:

Any better way to request?

#include <w5100.h>
#include "pins_arduino.h"

#define ID_LEN 34
#define DATA_PIN_0 4
#define DATA_PIN_1 5
#include <SPI.h>
#include <Ethernet.h>
unsigned long startTime;
unsigned long interval = 5000;
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
IPAddress gateway( 192, 168, 10, 3);
IPAddress subnet( 255, 255, 255, 0 );
IPAddress dns1( 59, 144, 127, 16);
IPAddress ip(192, 168, 10, 11);
IPAddress server( 192, 168, 10, 191);
EthernetClient client;
char buf[100];
String data;
int start;
int ind1; // - locations
int ind2;
//////////////////////
volatile long extract;
volatile uint8_t *port_to_pcmask[] = { &PCMSK0, &PCMSK1, &PCMSK2 };
typedef void (*voidFuncPtr)(void);
volatile static voidFuncPtr PCintFunc[24] = { NULL };
volatile static uint8_t PCintLast[3];

////////////////////////////////////////
// attach an interrupt to a specific pin using pin change interrupts.
void PCattachInterrupt(uint8_t pin, void (*userFunc)(void), int mode)
{

  uint8_t bit = digitalPinToBitMask(pin);
  uint8_t port = digitalPinToPort(pin);
  uint8_t slot;
  volatile uint8_t *pcmask;

  if (mode != CHANGE)
  {
    return;
  }

  // map pin to PCIR register
  if (port == NOT_A_PORT)
  {
    return;
  }
  else
  {
    port -= 2;
    pcmask = port_to_pcmask[port];
  }

  slot = port * 8 + (pin % 8);
  PCintFunc[slot] = userFunc;

  // set the mask
  *pcmask |= bit;

  // enable the interrupt
  PCICR |= 0x01 << port;

}

////////////////////////////////////////
void PCdetachInterrupt(uint8_t pin)
{
  uint8_t bit = digitalPinToBitMask(pin);
  uint8_t port = digitalPinToPort(pin);
  volatile uint8_t *pcmask;

  // map pin to PCIR register
  if (port == NOT_A_PORT)
  {
    return;
  }
  else
  {
    port -= 2;
    pcmask = port_to_pcmask[port];
  }

  // disable the mask.
  *pcmask &= ~bit;

  // if that's the last one, disable the interrupt.
  if (*pcmask == 0)
  {
    PCICR &= ~(0x01 << port);
  }
}

////////////////////////////////////////
// common code for isr handler. "port" is the PCINT number.
// there isn't really a good way to back-map ports and masks to pins.
static void PCint(uint8_t port)
{
  uint8_t bit;
  uint8_t curr;
  uint8_t mask;
  uint8_t pin;

  // get the pin states for the indicated port.
  curr = *portInputRegister(port + 2);
  mask = curr ^ PCintLast[port];
  PCintLast[port] = curr;

  // mask is pins that have changed. screen out non pcint pins.
  if ((mask &= *port_to_pcmask[port]) == 0)
  {
    return;
  }

  // mask is pcint pins that have changed.
  for (uint8_t i = 0; i < 8; i++)
  {
    bit = 0x01 << i;
    if (bit & mask)
    {
      pin = port * 8 + i;
      if (PCintFunc[pin] != NULL)
      {
        PCintFunc[pin]();
      }
    }
  }
}

////////////////////////////////////////
SIGNAL(PCINT0_vect)
{
  PCint(0);
}

////////////////////////////////////////
SIGNAL(PCINT1_vect)
{
  PCint(1);
}

////////////////////////////////////////
SIGNAL(PCINT2_vect)
{
  PCint(2);
}

////////////////////////////////////////////////////////
// end of interrupt code
////////////////////////////////////////////////////////

volatile long reader1 = 0;
volatile int reader1Count = 0;

////////////////////////////////////////
void read0(void)
{
  if (digitalRead(DATA_PIN_0) == LOW)
  {
    reader1Count++;
    reader1 = reader1 << 1;
    // Serial.print("0");
  }
}

////////////////////////////////////////
void read1(void)
{
  if (digitalRead(DATA_PIN_1) == LOW)
  {
    reader1Count++;
    reader1 = reader1 << 1;
    reader1 |= 1;
    //Serial.print("1");
  }
}


void setup() {

  // Open serial communications and wait for port to open:

  PCattachInterrupt(DATA_PIN_0, read0, CHANGE);//Attachinterrupt D0
  PCattachInterrupt(DATA_PIN_1, read1, CHANGE);//Attachinterrupt D1
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);

  delay(10);

  for (int i = 4; i < 5; i++)
  {
    pinMode(i, OUTPUT);
    digitalWrite(i, HIGH); // enable internal pull up causing a one
    digitalWrite(i, LOW);  // disable internal pull up causing zero and thus an interrupt
    pinMode(i, INPUT);
    digitalWrite(i, HIGH); // enable internal pull up
  }



  reader1 = 0;
  reader1Count = 0;



  Serial.begin(115200);
  Ethernet.begin(mac, ip, dns1, gateway, subnet);
  delay(2000);
  client.setTimeout(200);
  W5100.setRetransmissionTime(1000);
  W5100.setRetransmissionCount(2);
  Serial.println("Ready");
  Serial.println(F("Please Give Your Punch")); // what to do to test

}

void loop() {
  if (reader1Count >= ID_LEN)
  {

    Serial.println(F(""));
    Serial.println(F("---------------------"));
    Serial.print(F("data: "));

    extract = (reader1 >> 1) & 0xFFFFFF;
    Serial.println(extract);
    sprintf(buf, "%08lu", extract);

    Serial.println(F("---------------------"));
    delay(250);
    sendGET();

    reader1 = 0;
    reader1Count = 0;

  }
}



void sendGET()
{
  if (client.connect(server, 8484) == 1) { //starts client connection, checks for connection
    Serial.println(F("connected"));
    const unsigned long startTimestamp = micros();
    client.print("GET /api/Test/Getvalues/");
    client.print(buf);
    client.print("/123 HTTP/1.1\r\nHost: 192.168.10.191\r\nConnection: close\r\n\r\n");
    const unsigned long endTimestamp = micros();
    Serial.println(endTimestamp - startTimestamp);
    Serial.println(F("request sent"));
  }
  else {
    Serial.println(F("connection failed")); //error message if no client connect

    Serial.println();
  }

  String readString;
  String line ;
  int lines_received = 0;
  while (client.connected() && !client.available()) delay(1); //waits for data
  while (client.connected() && client.available()) { //connected or data available
    char c = client.read();

    readString.concat(c);

  }

  client.stop();
  Serial.println(F("client disconnected."));
  Serial.println("Data from server captured in readString:");
  Serial.println();
  Serial.print(readString); //prints readString to serial monitor
  Serial.println();
  start = readString.indexOf(" ");  //finds a unique start location
  ind1 = readString.indexOf('"', start + 2); //finds location of first -
  ind2 = readString.indexOf('"', ind1 + 1 ); //finds location of second -
  data = readString.substring(ind1 + 1, ind2); //captures data String
  Serial.print("my data is: ");
  Serial.println(data);
  char charBuf[50];
  data.toCharArray(charBuf, 1024) ;
  int length = strlen(charBuf);
  char end_char = charBuf[strlen(charBuf) - 1]; ;
  Serial.print(F("Received:"));
  Serial.println(charBuf);
  Serial.print(F("Received:"));
  Serial.println(end_char);
  Serial.println();
  if (end_char == '1') {
    Serial.println(F("Plz open the Turnstile"));
    // startTime  = millis();
    Serial.println(F("RELAY TURN ON"));
    digitalWrite (2, HIGH);
    delay(2000);


  }
  else {
    Serial.println(F("Wrong Entry"));
    digitalWrite (3, HIGH);
    delay(200);
    digitalWrite (3, LOW);

  }

  digitalWrite (2, LOW);
  Serial.println(F("RELAY TURN OFF"));

  Serial.println("End of readString");
  Serial.println("==================");
  Serial.println();
  readString = ""; //clear readString variable
  data = ""; //clear data variable
}
  for (int i = 4; i < 5; i++)

How many times is that loop going to iterate?

  char charBuf[50];
  data.toCharArray(charBuf, 1024) ;

Liar! There is NOT room to write 1024 characters in that array!

I really do not understand the use of pin change interrupts on so many pins (including the hardware serial pins) being used in code littered with delays.

that code is for wiegand interfacing :

/* Crazy People
 * By Mike Cook April 2009
 * Three RFID readers outputing 26 bit Wiegand code to pins:-
 * Reader A (Head) Pins 4 & 5
 * Reader B (Body) Pins 6 & 7
 * Reader C (Legs) Pins 8 & 9
 * Interrupt service routine gathers Wiegand pulses (zero or one) until 26 have been recieved
 * Then a sting is sent to processing
 */
#include "pins_arduino.h"
/*
 * an extension to the interrupt support for arduino.
 * add pin change interrupts to the external interrupts, giving a way
 * for users to have interrupts drive off of any pin.
 * Refer to avr-gcc header files, arduino source and atmega datasheet.
 */

/*
 * Theory: all IO pins on Atmega168 are covered by Pin Change Interrupts.
 * The PCINT corresponding to the pin must be enabled and masked, and
 * an ISR routine provided.  Since PCINTs are per port, not per pin, the ISR
 * must use some logic to actually implement a per-pin interrupt service.
 */

/* Pin to interrupt map:
 * D0-D7 = PCINT 16-23 = PCIR2 = PD = PCIE2 = pcmsk2
 * D8-D13 = PCINT 0-5 = PCIR0 = PB = PCIE0 = pcmsk0
 * A0-A5 (D14-D19) = PCINT 8-13 = PCIR1 = PC = PCIE1 = pcmsk1
 */

volatile uint8_t *port_to_pcmask[] = {
  &PCMSK0,
  &PCMSK1,
  &PCMSK2
};

typedef void (*voidFuncPtr)(void);

volatile static voidFuncPtr PCintFunc[24] = { 
  NULL };

volatile static uint8_t PCintLast[3];

/*
 * attach an interrupt to a specific pin using pin change interrupts.
 * First version only supports CHANGE mode.
 */
 void PCattachInterrupt(uint8_t pin, void (*userFunc)(void), int mode) {
  uint8_t bit = digitalPinToBitMask(pin);
  uint8_t port = digitalPinToPort(pin);
  uint8_t slot;
  volatile uint8_t *pcmask;

  if (mode != CHANGE) {
    return;
  }
  // map pin to PCIR register
  if (port == NOT_A_PORT) {
    return;
  } 
  else {
    port -= 2;
    pcmask = port_to_pcmask[port];
  }
  slot = port * 8 + (pin % 8);
  PCintFunc[slot] = userFunc;
  // set the mask
  *pcmask |= bit;
  // enable the interrupt
  PCICR |= 0x01 << port;
}

void PCdetachInterrupt(uint8_t pin) {
  uint8_t bit = digitalPinToBitMask(pin);
  uint8_t port = digitalPinToPort(pin);
  volatile uint8_t *pcmask;

  // map pin to PCIR register
  if (port == NOT_A_PORT) {
    return;
  } 
  else {
    port -= 2;
    pcmask = port_to_pcmask[port];
  }

  // disable the mask.
  *pcmask &= ~bit;
  // if that's the last one, disable the interrupt.
  if (*pcmask == 0) {
    PCICR &= ~(0x01 << port);
  }
}

// common code for isr handler. "port" is the PCINT number.
// there isn't really a good way to back-map ports and masks to pins.
static void PCint(uint8_t port) {
  uint8_t bit;
  uint8_t curr;
  uint8_t mask;
  uint8_t pin;

  // get the pin states for the indicated port.
  curr = *portInputRegister(port+2);
  mask = curr ^ PCintLast[port];
  PCintLast[port] = curr;
  // mask is pins that have changed. screen out non pcint pins.
  if ((mask &= *port_to_pcmask[port]) == 0) {
    return;
  }
  // mask is pcint pins that have changed.
  for (uint8_t i=0; i < 8; i++) {
    bit = 0x01 << i;
    if (bit & mask) {
      pin = port * 8 + i;
      if (PCintFunc[pin] != NULL) {
        PCintFunc[pin]();
      }
    }
  }
}

SIGNAL(PCINT0_vect) {
  PCint(0);
}
SIGNAL(PCINT1_vect) {
  PCint(1);
}
SIGNAL(PCINT2_vect) {
  PCint(2);
}

// End of interrupts code and start of the reader code

volatile long reader1 = 0,reader2 = 0, reader3 = 0;
volatile int reader1Count = 0, reader2Count = 0,  reader3Count = 0;

void reader1One(void) {
  if(digitalRead(4) == LOW){
  reader1Count++;
  reader1 = reader1 << 1;
  reader1 |= 1;
  }
}

void reader1Zero(void) {
  if(digitalRead(5) == LOW){
  reader1Count++;
  reader1 = reader1 << 1;  
  }
}

void reader2One(void) {
  if(digitalRead(6) == LOW){
  reader2Count++;
  reader2 = reader2 << 1;
  reader2 |= 1;
  }
}

void reader2Zero(void) {
  if(digitalRead(7) == LOW){
  reader2Count++;
  reader2 = reader2 << 1;  
  }
}

void reader3One(void) {
  if(digitalRead(8) == LOW){
  reader3Count++;
  reader3 = reader3 << 1;
  reader3 |= 1;
  }
}

void reader3Zero(void) {
  if(digitalRead(9) == LOW){
  reader3Count++;
  reader3 = reader3 << 1;  
  }
}

void setup()
{
  Serial.begin(57000);
  // Attach pin change interrupt service routines from the Wiegand RFID readers
  PCattachInterrupt(4, reader1One, CHANGE);
  PCattachInterrupt(5, reader1Zero, CHANGE);
  PCattachInterrupt(6, reader2One, CHANGE);
  PCattachInterrupt(7, reader2Zero, CHANGE);
  PCattachInterrupt(8, reader3One, CHANGE);
  PCattachInterrupt(9, reader3Zero, CHANGE);
  delay(10);
  // the interrupt in the Atmel processor mises out the first negitave pulse as the inputs are already high,
  // so this gives a pulse to each reader input line to get the interrupts working properly.
  // Then clear out the reader variables.
  // The readers are open collector sitting normally at a one so this is OK
  for(int i = 4; i<10; i++){
  pinMode(i, OUTPUT);
   digitalWrite(i, HIGH); // enable internal pull up causing a one
  digitalWrite(i, LOW); // disable internal pull up causing zero and thus an interrupt
  pinMode(i, INPUT);
  digitalWrite(i, HIGH); // enable internal pull up
  }
  delay(10);
  // put the reader input variables to zero
  reader1 = reader2 = reader3 = 0;
  reader1Count = reader2Count =  reader3Count = 0;
  digitalWrite(13, HIGH);  // show Arduino has finished initilisation
}

void loop() {
  if(reader1Count >= 26){
//  Serial.print(" Reader 1 ");Serial.println(reader1,HEX);
  Serial.println("A");Serial.println(reader1 & 0xfffffff);
  reader1 = 0;
  reader1Count = 0;
     }
     
  if(reader2Count >= 26){
  Serial.println("B");Serial.println(reader2 & 0xfffffff);
  reader2 = 0;
  reader2Count = 0;
     }
     
 if(reader3Count >= 26){
  Serial.println("C");Serial.println(reader3 & 0xfffffff);
  reader3 = 0;
  reader3Count = 0;
     }
    
}

sometimes still response as: :confused:

---------------------
data: 12579088
---------------------
connected
1764
request sent
client disconnected.
Data from server captured in readString:


my data is: 
Received:
Received:5

Wrong Entry
RELAY TURN OFF
End of readString

where it is proper giving proper response everytime when:

---------------------
data: 12579088
---------------------
connected
1768
request sent
client disconnected.
Data from server captured in readString:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Thu, 12 Jul 2018 11:00:57 GMT
Connection: close
Content-Length: 5

["1"]
my data is: 1
Received:1
Received:1

Plz open the Turnstile
RELAY TURN ON
RELAY TURN OFF
End of readString
==================

when sending as request as:

client.print("GET /api/Test/Getvalues/12579088/123 HTTP/1.1\r\nHost:192.168.10.191\r\nConnection: close\r\n\r\n");
  start = readString.indexOf(" ");  //finds a unique start location
  ind1 = readString.indexOf('"', start + 2); //finds location of first -
  ind2 = readString.indexOf('"', ind1 + 1 ); //finds location of second -
  data = readString.substring(ind1 + 1, ind2); //captures data String

If there is no space in readString, the rest of the calls get garbage input, and produce garbage output.

Defensive programming is not something you add later, when it all works. It's stupid-proofing that you add in the beginning.

Then How to read only response body?

Then How to read only response body?

That is a dumb question. You have to read the entire response. You do not have to SAVE the part(s) of the response that are not useful.

I don't see where you add '[' or ']' to what you print of the server response. I presume, then, that they are part of the server response. The content-length value supports that, since '[', '"', '1', '"', and ']' are 5 characters.

So, you read each character from the server. You don't store anything until the '[' arrives. You stop storing when the ']' arrives.

That means that you have stored three characters, '"', '1', and '"'.

If you have any control over the server output, stop sending the double quotes. Then, all you'd have stored is one character, the '1'.

In either case, dealing with the stored data is easy.

Serial Input Basics - updateed specifically refers to serial, but is equally applicable to server data.

And, it doesn't piss away resources using the String class.

receiving empty string on alternate request :confused:

first request:

---------------------
data: 12579088
---------------------
connected
1860
request sent
client disconnected.
Data from server captured in readString:


my data is: 
Received:
Received:/

Wrong Entry
RELAY TURN OFF
End of readString
==================

second request and so on :

---------------------
data: 12579088
---------------------
connected
1760
request sent
client disconnected.
Data from server captured in readString:

HTTP/1.1 200 OK
Cache-Control: no-cache
Pragma: no-cache
Content-Type: application/json; charset=utf-8
Expires: -1
Server: Microsoft-IIS/7.5
X-AspNet-Version: 4.0.30319
X-Powered-By: ASP.NET
Date: Fri, 13 Jul 2018 08:30:16 GMT
Connection: close
Content-Length: 5

["1"]
my data is: 1
Received:1
Received:1

Plz open the Turnstile
RELAY TURN ON
RELAY TURN OFF
End of readString
==================