 
 int value = 0;
 
+
 void loop() {
-  delay(5000);
+  bool isAlive = true;
+  delay(100);
   ++value;
 
   Serial.print("connecting to ");

#include <ESP8266WiFi.h>
#include "cJSON.h"
#include <string.h>


const char* ssid     = "Eino-Huawei-Y6";
const char* password = "jeejeejoojoo";


/*

  
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 13337;
  
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }

  while(isAlive) {
    int sensorValue = analogRead(A0);
    int timeOffset = 0;
    // char* jsonData = "{\"sensors\":1466076661337,\"input\":\"alex on nortti\"}";
    char jsonData[256];
    // (String("{\"sensors\":{\"name\":\"flex1\",\"collection\":[{\"value\":") + String(sensorValue) + String(",\"timestamp\":") + String(timeOffset) + String("}]}}")).c_str();
    s_printf(jsonData, "{\"sensors\":{\"name\":\"flex1\",\"collection\":[{\"value\":%d,\"timestamp\":%d}]}}", sensorValue, timeOffset);
    Serial.println(String("### DEBUG: Content-Length:") + strlen(jsonData));
    
    // This will send the request to the server
    String request = (String("POST ") + "/messages/" + " HTTP/1.1\r\n" +
                 "Host: " + host + ":" + httpPort + "\r\n" + 
                 "Content-Type: application/json; charset=UTF-8\r\n" +
                 "Content-Length: " + strlen(jsonData) + "\r\n" +
                 "Connection: keep-alive\r\n\r\n" + jsonData);

    Serial.println("Sending request...");
    client.print(request);
    Serial.println("----------------------------------------------------");
    
    Serial.println(request);
  
    Serial.println("----------------------------------------------------");
                 
    Serial.println("Waiting for response");
    unsigned long timeout = millis();
    while (client.available() == 0) {
      if (millis() - timeout > 400) {
        Serial.println(">>> Client Timeout !");
        Serial.println("closing connection");
        client.stop();
        isAlive = false;
        break;
      }
    }
    Serial.println("Reading response");
    timeout = millis();
    // Read all the lines of the reply from server and print them to Serial
    while(client.available() && (millis() - timeout < 100)){
      String line = client.readString();
      Serial.print(line);
    }
    Serial.println("Stopped reading");
  }
}

