Skip to content

Instantly share code, notes, and snippets.

@CelliesProjects
Created March 10, 2020 14:18
Show Gist options
  • Save CelliesProjects/6eba2d2c9dcae9c4dfa9c6cbc353c0a8 to your computer and use it in GitHub Desktop.
Save CelliesProjects/6eba2d2c9dcae9c4dfa9c6cbc353c0a8 to your computer and use it in GitHub Desktop.

Revisions

  1. CelliesProjects created this gist Mar 10, 2020.
    44 changes: 44 additions & 0 deletions static_ip_setup.ino
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,44 @@
    // Load Wi-Fi library
    #include <WiFi.h>

    // Replace with your network credentials
    const char* ssid = "";
    const char* password = "";


    void setup(){
    IPAddress local_IP(192, 168, 0, 60); /* THIS SHOULD BE OUTSIDE YOUR ROUTERS DHCP RANGE! */

    // Set your Gateway IP address
    IPAddress gateway(192, 168, 0, 1);

    IPAddress subnet(255,255,255,0); /* USUALLY 255,255,255,0 BUT CHECK IT IN YOUR ROUTER */
    IPAddress primaryDNS(192,168,0,30); //optional
    IPAddress secondaryDNS( 192,168,0,50 ); //optional

    ESP_LOGI( TAG, "Connecting to: %s", ssid);

    WiFi.begin(ssid, password);

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

    // Configures static IP address
    if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) {
    ESP_LOGI( TAG, "STA Failed to configure" );
    }

    // Print local IP address
    tcpip_adapter_ip_info_t ip_info;
    ESP_ERROR_CHECK( tcpip_adapter_get_ip_info( TCPIP_ADAPTER_IF_STA, &ip_info ) );
    ESP_LOGI( TAG, "Local IP: %s", ip4addr_ntoa( &ip_info.ip ) );

    // Print ESP MAC Address
    ESP_LOGI( TAG, "MAC address: %s",WiFi.macAddress().c_str());
    }

    void loop() {
    // put your main code here, to run repeatedly:
    }