     + "Content-Length: " + payload.length() + "\r\n"
     + "\r\n"
     + payload + "\r\n";
-  http_post(request);
- }
- 
- void lg_sensor(int val) {
-  String payload = "{ \"host\": \"" + gethostname(true) + "\", \"soil\": " + val + " }"; 
-  String request = "POST /api/collections/sensor?user_key=" + String(LG_API_KEY) + " HTTP/1.1\r\n"
-    + "Host: " + LG_HOST + "\r\n"
-    + "User-Agent: arduino-wino/1.0 \r\n"
-    + "Content-Type: application/json \r\n"
-    + "Connection: close \r\n"
-    + "Content-Length: " + payload.length() + "\r\n"
-    + "\r\n"
-    + payload + "\r\n";
-  http_post(request);
- }
-
- void http_post(String url) {
-  uint8_t buffer[1024] = {0};
-
-  SerialUSB.print("host: ");
-  SerialUSB.print(LG_HOST);
-  SerialUSB.print(" - port: ");
-  SerialUSB.println(LG_PORT);
-  SerialUSB.println("=== HTTP request start ===");
-  SerialUSB.println(url);
- 
-  SerialUSB.println("=== HTTP request end ===");
-  SerialUSB.print("url.length(): ");
-  SerialUSB.println(url.length());
   
   if (wifi.connect("TCP", LG_HOST, LG_PORT)) {
     logDebug("tcp connection created");

  }

  
  if (wifi.writeln(url)) {
    logDebug("request sent with wifi.writeln(String), lrc = true");  
  } else {
    logDebug("request sent with wifi.writeln(String), lrc = false");      
  }
  uint32_t len = wifi.read(buffer, sizeof(buffer), 10000);
  if (len > 0) {
    SerialUSB.print("http_post(): Received: [");
    for (uint32_t i=0; i<len; i++) {
      SerialUSB.print((char)buffer[i]);  
    }
    SerialUSB.println("]");
    logDebug((char *)buffer);
  } else {
    logDebug("<empty response>");


 void lg_heartbeat(void) {
  String payload = "{ \"host\": \"" + gethostname(true) + "\", \"loopcount\": " + loopcnt + ", \"errcount\": " + errcnt + " }"; 
  String url = "/api/collections/heartbeat?user_key=" + String(LG_API_KEY);
  http_post(url, payload);
 }
 
 void lg_sensor(int val) {
  String payload = "{ \"host\": \"" + gethostname(true) + "\", \"soil\": " + val + " }"; 
  String url = "/api/collections/sensor?user_key=" + String(LG_API_KEY);
  http_post(url, payload);
 }

 void http_post(String url, String payload) {
  uint8_t buffer[1024] = {0};

  String request = "POST " + url + " HTTP/1.1\r\n"
    + "Host: " + LG_HOST + "\r\n"
    + "User-Agent: arduino-wino/1.0 \r\n"
    + "Content-Type: application/json \r\n"
