const uint8_t IP_ADDRESS_ARRAY = {192, 168, 35, 222};
const uint8_t NETMASK_ARRAY = {255, 255, 255, 0};
const uint8_t GATEWAY_ADDRESS_ARRAY = {192, 168, 35, 1};
const uint8_t DNS1_ADDRESS_ARRAY = {210, 220, 163, 82}; // 1차 DNS
const uint8_t DNS2_ADDRESS_ARRAY = {168, 126, 63, 1}; // 2차 DNS
SYSTEM_MODE(MANUAL); // OS 제어권 확보 (필수)
void setup() {
// 1. 초기화 및 자격 증명 설정
WiFi.disconnect();
WiFi.clearCredentials();
WiFi.setCredentials(ssid, pass);
// 2. 고정 IP 강제 설정 (connect() 직전)
WiFi.setConfig(NetworkInterfaceConfig()
.source(NetworkInterfaceConfigSource::STATIC)
.address(IP_ADDRESS_ARRAY, NETMASK_ARRAY)
.gateway(SockAddr(GATEWAY_ADDRESS_ARRAY))
.dns(SockAddr(DNS1_ADDRESS_ARRAY))
.dns(SockAddr(DNS2_ADDRESS_ARRAY)));
// 3. 연결 시작
Serial.println("Attempting Static IP connection...");
WiFi.connect();
// 4. 연결 후 IP 확인 (고정 IP가 나와야 함)
if (waitFor(WiFi.ready, 20000)) {
Serial.print("Final IP: ");
Serial.println(WiFi.localIP());
} else {
Serial.println("Connection failed.");
}
}
I want to use a static IP, but I'm having trouble with DHCP mode.
I flashed the above code to my Photon2, and it's running in DHCP mode.
(I also flashed it in DFU mode, and it still runs in DHCP.)
How can I assign a static IP?
Thank you for your help.