Skip to content

Instantly share code, notes, and snippets.

@CelliesProjects
Created May 16, 2019 12:09
Show Gist options
  • Select an option

  • Save CelliesProjects/292b47c358f42a5576e90d297eb30fab to your computer and use it in GitHub Desktop.

Select an option

Save CelliesProjects/292b47c358f42a5576e90d297eb30fab to your computer and use it in GitHub Desktop.
Setting static ip address on a esp32 in Arduino IDE.
// Load Wi-Fi library
#include <WiFi.h>
// Replace with your network credentials
const char* ssid = "YOURSIDD";
const char* password = "YOURPSK";
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( 0,0,0,0 ); //optional
ESP_LOGI( TAG, "Connecting to: %s", ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
// 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:
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment