 
 int send_request_to_api(int b_number)
 {
-  lights_url[11] = lights_url_by_button_number(b_number);
   set_headers();
-  int status_code = client.get( lights_url );
+  int status_code;
+
+  status_code = client.get( lights_url_by_button_number(b_number) );
 
   #ifdef DEBUG_SWITCHER
-    Serial.println("GET query:");
-    Serial.print(lights_url);
+    Serial.print("GET query:");
+    Serial.println(lights_url_by_button_number(b_number));
     Serial.print("Status code from server: ");
     Serial.println(status_code);
   #endif

  delay(100);
  
  // send request to API if button pressed
  for (int i=0; i<buttons_count; i++) {
    if ( millis() - last_pressed_at > minimal_delay )
    {
      if(!button_was_pressed[i] && digitalRead(buttons[i]) == LOW) {
        #ifdef DEBUG_SWITCHER
          Serial.println("Button pressed!");
        #endif
        digitalWrite( main_led_pin, HIGH );
        button_was_pressed[i] = true;

        send_request_to_api( i+1 );
        last_pressed_at = millis();
      }

      if(button_was_pressed[i] && digitalRead(buttons[i]) == HIGH)
      {
        button_was_pressed[i] = false;
        digitalWrite( main_led_pin, LOW );
      }
    } 
  }
  
}

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

  return status_code;
}

char* lights_url_by_button_number(int button_number)
{  
  switch (button_number) {
    case 0:
      return "/CMD?Smart_Switch_1=TOGGLE";
    case 1:
      return "/CMD?Smart_Switch_Day_Lights=TOGGLE";
    case 2:
      return "/CMD?Smart_Switch_Night_Lights=TOGGLE";
    default:
      return "";
  }
}

void sturtup_blink()
{
  for (int i=0; i<5; i++) {
    control_led(HIGH);
    delay(250);
    control_led(LOW);
    delay(250);
  }
}

void control_led(int state)
{
    #ifdef DEBUG_SWITCHER
      if(state == LOW)
        Serial.println("led is off");
      else
        Serial.println("led is on");
    #endif
    digitalWrite( status_led_pin, state );
}

