   
 }
 
+void setup_buttons()
+{
+  for (int i=0; i<buttons_count; i++) {
+    pinMode(buttons[i], INPUT);
+    digitalWrite(buttons[i], HIGH); //internal pull-ups
+  }
+}
+
 void set_headers()
 {
   client.setHeader(CONTENT_TYPE);
   client.setHeader(ACCEPT);
 }
 
-String json;
-int read_button_state_from_api(int button_number)
+int send_request_to_api(int b_number)
 {
-  json = "";
-  
+  lights_url[11] = lights_url_by_button_number(b_number);
   set_headers();
-  int status_code = client.get( lights_url_by_button_number(button_number), &json );
+  int status_code = client.get( lights_url );
 
-  
   #ifdef DEBUG_SWITCHER
-    Serial.print("Status code from server: ");
-    Serial.println(status_code);
-    Serial.print("Response body from server: ");
-    Serial.println(json);
-  #endif
-  
-  if( status_code == 200 )
-  {     
-    return parse_api_response_to_get_state();
-  }
-  return -1;
-}
-
-int parse_api_response_to_get_state()
-{
-  int index_of_state = json.indexOf("\"state\":");
-  if (index_of_state > 0)
-  {
-    String state;
-    state = json.substring(index_of_state + 9, index_of_state + 11);
-  
-    #ifdef DEBUG_SWITCHER
-      Serial.print("STATE: ");
-      Serial.println(state);
-    #endif
-    
-    if(state == "ON")
-    {
-      return 1;
-    }
-    if(state == "OF")
-    {
-      return 0;
-    }
-  }
-  return -1;
-}
-
-int send_request_to_api(int b_number, int current_state)
-{
-  char*  query_url = lights_url_by_button_number(b_number);
-  set_headers();
-  int status_code = client.post( query_url, param_by_state(current_state) );
-  
-  #ifdef DEBUG_SWITCHER
-    Serial.println("POST query:");
-    Serial.print(query_url);
+    Serial.println("GET query:");
+    Serial.print(lights_url);
     Serial.print("Status code from server: ");
     Serial.println(status_code);
   #endif

  return status_code;
}

char* param_by_state(int state)
{
  if (state)
    return "OFF";
  else
    return "ON";
}

void setup_buttons()
{
  for (int i=0; i<buttons_count; i++) {
    pinMode(buttons[i], INPUT);
    digitalWrite(buttons[i], HIGH); //internal pull-ups
    pinMode(leds_1[i], OUTPUT);
    pinMode(leds_2[i], OUTPUT);
    
    //all off
    digitalWrite(leds_1[i], LOW);
    digitalWrite(leds_2[i], HIGH);
  }
}

char url[40];
char* lights_url_by_button_number(int button_number)
{
  char pin_as_char[2];

  pin_as_char[0] = (char)(((int)'0') + button_number);
  pin_as_char[1] = '\0';

  strcpy (url, LIGHTS_URL);
  strcat (url, pin_as_char);

  return url;
}

void toggle_button_led(int button_number, int state)
{
  if (state == 0 || state == 1)
  {
    digitalWrite(leds_1[button_number-1], state == 1);
    digitalWrite(leds_2[button_number-1], state != 1);
  }

}

int api_available()

void loop()
{
  #ifdef DEBUG_SWITCHER
    //Serial.println(".");
  #endif
  
  // send request to API if button pressed
  for (int i=0; i<buttons_count; i++) {
