   }
 
 
-  G[0] = alpha * G[0] + (1-alpha) * accel.X;
-  G[1] = alpha * G[1] + (1-alpha) * accel.Y;
-  G[2] = alpha * G[2] + (1-alpha) * accel.Z;
-  
+if (millis() - 20 >= timer_read_from_accel) {
+Serial.println(timer_read_from_accel);
+timer_read_from_accel = millis();
+  accel.read();//This function gets new data from the accelerometer
+
+  G[0] = alpha * G[0] + (1 - alpha) * accel.X;
+  G[1] = alpha * G[1] + (1 - alpha) * accel.Y;
+  G[2] = alpha * G[2] + (1 - alpha) * accel.Z;
+
   //char* row;
   //sprintf(row, "%d,%d,%d", accel.X - G[0], accel.Y - G[1], accel.Z - G[2]);
-  
-  String row = String(int(accel.X - G[0])) + "," + String(int(accel.Y - G[1])) + "," + String(int(accel.Z - G[2]));
-  Serial.println(row);
-  
-  
+
+  row += String(int(accel.X - G[0])) + "," + String(int(accel.Y - G[1])) + "," + String(int(accel.Z - G[2]));
+  //  Serial.println(row);
+} 
+
+Serial.println(row); 
   // We now create a URI for the request
   String url = "/stream";
-  String tsData = String(accel.X);
+  String tsData = String(row);
   //Serial.println(tsData);
-  
-  Serial.print("Requesting URL: ");
-  Serial.println(url);
+
+  //  Serial.print("Requesting URL: ");
+  //  Serial.println(url);
 
 
-  
+
   // This will send the request to the server
   client.print(String("POST ") + url + " HTTP/1.1\r\n" + "Host: " + host + "\r\n");
   client.print("Content-Type: application/x-www-form-urlencoded\r\n");

  client.print("\r\n\r\n");
  client.print(tsData);
  client.print("Connection: close\r\n\r\n");
 
  delay(1000);
  
  // Read all the lines of the reply from server and print them to Serial
  while(client.available()){
    String line = client.readStringUntil('\r');
    Serial.print(line);
  }
  
  Serial.println();
  Serial.println("closing connection");
}


  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

//int value = 0;

void loop() {
//  delay(5000);
//  ++value;

//  Serial.print("connecting to ");
//  Serial.println(host);


  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 3001;
