diff --git a/Framing.h b/Framing.h index b05bb7e..634fd22 100644 --- a/Framing.h +++ b/Framing.h @@ -69,6 +69,8 @@ #define CMD_WIFI_SSID 0x6B #define CMD_WIFI_PSK 0x6C #define CMD_WIFI_CHN 0x6E + #define CMD_WIFI_IP 0x84 + #define CMD_WIFI_NM 0x85 #define CMD_BOARD 0x47 #define CMD_PLATFORM 0x48 diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index 0f50013..1984c9b 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -1190,6 +1190,34 @@ void serial_callback(uint8_t sbyte) { } } #endif + } else if (command == CMD_WIFI_IP) { + #if HAS_WIFI + if (sbyte == FESC) { ESCAPE = true; } + else { + if (ESCAPE) { + if (sbyte == TFEND) sbyte = FEND; + if (sbyte == TFESC) sbyte = FESC; + ESCAPE = false; + } + if (frame_len < CMD_L) cmdbuf[frame_len++] = sbyte; + } + + if (frame_len == 4) { for (uint8_t i = 0; i<4; i++) { eeprom_update(config_addr(ADDR_CONF_IP+i), cmdbuf[i]); } } + #endif + } else if (command == CMD_WIFI_NM) { + #if HAS_WIFI + if (sbyte == FESC) { ESCAPE = true; } + else { + if (ESCAPE) { + if (sbyte == TFEND) sbyte = FEND; + if (sbyte == TFESC) sbyte = FESC; + ESCAPE = false; + } + if (frame_len < CMD_L) cmdbuf[frame_len++] = sbyte; + } + + if (frame_len == 4) { for (uint8_t i = 0; i<4; i++) { eeprom_update(config_addr(ADDR_CONF_NM+i), cmdbuf[i]); } } + #endif } else if (command == CMD_BT_CTRL) { #if HAS_BLUETOOTH || HAS_BLE if (sbyte == 0x00) { diff --git a/ROM.h b/ROM.h index e1d6838..c883434 100644 --- a/ROM.h +++ b/ROM.h @@ -56,6 +56,8 @@ #define CONFIG_SIZE 256 #define ADDR_CONF_SSID 0x00 #define ADDR_CONF_PSK 0x21 + #define ADDR_CONF_IP 0x42 + #define ADDR_CONF_NM 0x46 ////////////////////////////////// #endif diff --git a/Remote.h b/Remote.h index 7d3ccdc..2928674 100644 --- a/Remote.h +++ b/Remote.h @@ -74,6 +74,23 @@ void wifi_remote_start_ap() { void wifi_remote_start_sta() { WiFi.mode(WIFI_STA); + + uint8_t ip[4]; bool ip_ok = true; + for (uint8_t i = 0; i < 4; i++) { ip[i] = EEPROM.read(config_addr(ADDR_CONF_IP+i)); } + if (ip[0]==0x00 && ip[1]==0x00 && ip[2]==0x00 && ip[3]==0x00) { ip_ok = false; } + if (ip[0]==0xFF && ip[1]==0xFF && ip[2]==0xFF && ip[3]==0xFF) { ip_ok = false; } + + uint8_t nm[4]; bool nm_ok = true; + for (uint8_t i = 0; i < 4; i++) { nm[i] = EEPROM.read(config_addr(ADDR_CONF_NM+i)); } + if (nm[0]==0x00 && nm[1]==0x00 && nm[2]==0x00 && nm[3]==0x00) { nm_ok = false; } + if (nm[0]==0xFF && nm[1]==0xFF && nm[2]==0xFF && nm[3]==0xFF) { nm_ok = false; } + + if (ip_ok && nm_ok) { + IPAddress sta_ip(ip[0], ip[1], ip[2], ip[3]); + IPAddress sta_nm(nm[0], nm[1], nm[2], nm[3]); + WiFi.config(sta_ip, sta_ip, sta_nm); + } + delay(100); if (wr_ssid[0] != 0x00) { if (wr_psk[0] != 0x00) { WiFi.begin(wr_ssid, wr_psk); }