     } else {
 
       ESPserial.println(F("AT+CIPSEND=258"));
-      delay(1000);
-
-      i = 0;
-      while (ESPserial.available() ) {
-        response[i] = ESPserial.read();
-        i++;
-      }
-      response[i++] = '\0';
-      Serial.println(response);
-      for (i = 0; i < 725; i++) {
-        response[i] = '\0';
-      }
+      if (!isOk()) returnSetup();
 
       ESPserial.println(F("POST /data HTTP/1.1"));
       ESPserial.println(F("Host: demo.iven.io"));

      ESPserial.println(jSonBody2);

    }
    i = 0;
    while (true) {
      if (ESPserial.available()) {
        response[i] = ESPserial.read();
        i++;
        if (i > 3) {
          if (response[i - 4] == 'I' && response[i - 3] == 'P' && response[i - 2] == 'D' && response[i - 1] == ',') {
            Serial.print("index is: ");
            Serial.println(i);
            i = 0;
            if ( ESPserial.available()) response[i] = ESPserial.read();
            i++;
            if ( ESPserial.available()) response[i] = ESPserial.read();
            i++;
            if ( ESPserial.available()) response[i] = ESPserial.read();
            i++;
            if ( ESPserial.available()) response[i] = ESPserial.read();
            i++;
            response[i++] = '\0';
            Serial.println(response);
            sscanf(response, "%d", &j);
            Serial.println(j);
            i = 0;
            response[0] = '\0';
          }
        }

        if (i == j) {
          response[i++] = '\0';
          break;
        }
      }
    }
    response[i++] = '\0';
    Serial.println(response);
    if (response[9] == '2' && response[10] == '0' && response[11] == '0') {
      count++;
      Serial.println("Response is 200");
      Serial.print("Count is: ");
      Serial.println(count);
    }
    delay(5000);



  }

}



#include <SoftwareSerial.h>
#include <SoftReset.h>

#define ard_rx_esp_tx 2
#define ard_tx_esp_rx 3
#define lightPin 1

SoftwareSerial ESPserial(ard_rx_esp_tx, ard_tx_esp_rx); // RX | TX

char jSonBuffer[128];
String api_key = "";
char ivenCode[5];

bool isOk();
bool apiParse();
bool ivenCodeParse();

void returnSetup();
void responseHandle();


String jSonBody1 = "{\"data\":[{\"available\":true,\"at\":\"now\"}]}";
String jSonBody2 = "{\"data\":[{\"available\":false,\"at\":\"now\"}]}";

int sensorValue = 0;
int i, j, index, count, arrayIndex;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);     // communication with the host computer
  while (!Serial);

