Skip to content

Commit 412e47e

Browse files
authored
Static IP configuration moved to helper file (#983)
- Static IP configuration moved to helper file - added docs for socket
1 parent 140831c commit 412e47e

6 files changed

Lines changed: 453 additions & 77 deletions

File tree

uCNC/src/cnc_hal_config_helper.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2447,6 +2447,22 @@ typedef uint16_t step_t;
24472447
#define ENABLE_LONG_HOMING_CYCLE
24482448
#endif
24492449

2450+
/*static IP definitions for network interfaces*/
2451+
#ifdef USE_STATIC_IP
2452+
#ifndef STATIC_IP_IP
2453+
// 192.168.1.200
2454+
#define STATIC_IP_IP 3355551936
2455+
#endif
2456+
#ifndef STATIC_IP_GW
2457+
// 192.168.1.1
2458+
#define STATIC_IP_GW 16885952
2459+
#endif
2460+
#ifndef STATIC_IP_SUB
2461+
// 255.255.255.0
2462+
#define STATIC_IP_SUB 16777215
2463+
#endif
2464+
#endif
2465+
24502466
#include "hal/io_hal.h"
24512467

24522468
#ifdef __cplusplus

uCNC/src/hal/mcus/esp32common/esp32_wifi.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,20 +81,7 @@ static esp_netif_t *netif_sta = NULL;
8181
static esp_netif_t *netif_ap = NULL;
8282
static bool wifi_initialized = false;
8383

84-
#ifdef USE_STATIC_IP
85-
#ifndef STATIC_IP_IP
86-
// 192.168.1.200
87-
#define STATIC_IP_IP 3355551936
88-
#endif
89-
#ifndef STATIC_IP_GW
90-
// 192.168.1.1
91-
#define STATIC_IP_GW 16885952
92-
#endif
93-
#ifndef STATIC_IP_SUB
94-
// 255.255.255.0
95-
#define STATIC_IP_SUB 16777215
96-
#endif
97-
#endif
84+
9885

9986
extern "C" void esp32_wifi_stop(void)
10087
{
@@ -177,7 +164,10 @@ extern "C" void esp32_wifi_config(bool force)
177164
if (wifi_settings.wifi_mode != 2)
178165
{
179166
#ifdef USE_STATIC_IP
180-
WiFi.config(IPAddress(STATIC_IP_IP), IPAddress(STATIC_IP_GW), IPAddress(STATIC_IP_SUB));
167+
if (!WiFi.config(IPAddress(STATIC_IP_IP), IPAddress(STATIC_IP_GW), IPAddress(STATIC_IP_SUB)))
168+
{
169+
proto_info("Static IP config failed");
170+
}
181171
#endif
182172
WiFi.begin((char *)wifi_settings.ssid, (char *)wifi_settings.pass);
183173
}

uCNC/src/hal/mcus/esp8266/esp8266_arduino.cpp

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ typedef struct
8888

8989
uint16_t wifi_settings_offset;
9090
wifi_settings_t wifi_settings;
91+
9192
#endif
9293

9394
extern "C"
@@ -110,6 +111,12 @@ extern "C"
110111
ATOMIC_CODEBLOCK
111112
{
112113
WiFi.disconnect();
114+
#ifdef USE_STATIC_IP
115+
if (!WiFi.config(local_IP, gateway, subnet))
116+
{
117+
proto_info("Static IP config failed");
118+
}
119+
#endif
113120
switch (wifi_settings.wifi_mode)
114121
{
115122
case 1:
@@ -591,25 +598,6 @@ extern "C"
591598
}
592599
#endif
593600

594-
#ifdef USE_STATIC_IP
595-
#ifndef STATIC_IP_IP
596-
// 192.168.1.200
597-
#define STATIC_IP_IP 3355551936
598-
#endif
599-
#ifndef STATIC_IP_GW
600-
// 192.168.1.1
601-
#define STATIC_IP_GW 16885952
602-
#endif
603-
#ifndef STATIC_IP_SUB
604-
// 255.255.255.0
605-
#define STATIC_IP_SUB 16777215
606-
#endif
607-
608-
static IPAddress local_IP((uint32_t)(STATIC_IP_IP));
609-
static IPAddress gateway((uint32_t)(STATIC_IP_GW));
610-
static IPAddress subnet((uint32_t)(STATIC_IP_SUB));
611-
#endif
612-
613601
void __attribute__((weak)) mcu_network_init(void)
614602
{
615603
#ifdef ENABLE_WIFI
@@ -644,6 +632,12 @@ extern "C"
644632

645633
if (wifi_settings.wifi_on)
646634
{
635+
#ifdef USE_STATIC_IP
636+
if (!WiFi.config(local_IP, gateway, subnet))
637+
{
638+
proto_info("Static IP config failed");
639+
}
640+
#endif
647641
switch (wifi_settings.wifi_mode)
648642
{
649643
case 1:

uCNC/src/hal/mcus/rp2040/rp2040_arduino.cpp

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ typedef struct
108108

109109
uint16_t wifi_settings_offset;
110110
wifi_settings_t wifi_settings;
111+
111112
#endif
112113

113114
#ifdef BOARD_HAS_CUSTOM_SYSTEM_COMMANDS
@@ -607,30 +608,14 @@ extern "C" void ota_server_start(void)
607608
}
608609
#endif
609610

610-
#ifdef USE_STATIC_IP
611-
#ifndef STATIC_IP_IP
612-
// 192.168.1.200
613-
#define STATIC_IP_IP 3355551936
614-
#endif
615-
#ifndef STATIC_IP_GW
616-
// 192.168.1.1
617-
#define STATIC_IP_GW 16885952
618-
#endif
619-
#ifndef STATIC_IP_SUB
620-
// 255.255.255.0
621-
#define STATIC_IP_SUB 16777215
622-
#endif
623-
624-
static IPAddress local_IP(STATIC_IP_IP);
625-
static IPAddress gateway(STATIC_IP_GW);
626-
static IPAddress subnet(STATIC_IP_SUB);
627-
#endif
628-
629611
extern "C" void __attribute__((weak)) mcu_network_init(void)
630612
{
631613
#ifdef ENABLE_WIFI
632614
#ifdef USE_STATIC_IP
633-
WiFi.config(local_IP, gateway, gateway, subnet);
615+
if (!WiFi.config(IPAddress(STATIC_IP_IP), IPAddress(STATIC_IP_GW), IPAddress(STATIC_IP_SUB)))
616+
{
617+
proto_info("Static IP config failed");
618+
}
634619
#endif
635620
WiFi.mode(WIFI_AP);
636621
WiFi.begin((char *)BOARD_NAME, (char *)WIFI_PASS);
@@ -666,7 +651,10 @@ extern "C" void rp2040_wifi_bt_init(void)
666651
case 1:
667652
WiFi.mode(WIFI_STA);
668653
#ifdef USE_STATIC_IP
669-
WiFi.config(local_IP, gateway, subnet);
654+
if (!WiFi.config(IPAddress(STATIC_IP_IP), IPAddress(STATIC_IP_GW), IPAddress(STATIC_IP_SUB)))
655+
{
656+
proto_info("Static IP config failed");
657+
}
670658
#endif
671659
WiFi.begin((char *)wifi_settings.ssid, (char *)wifi_settings.pass);
672660
proto_info("Trying to connect to WiFi");
@@ -681,7 +669,10 @@ extern "C" void rp2040_wifi_bt_init(void)
681669
default:
682670
WiFi.mode(WIFI_AP_STA);
683671
#ifdef USE_STATIC_IP
684-
WiFi.config(local_IP, gateway, gateway, subnet);
672+
if (!WiFi.config(IPAddress(STATIC_IP_IP), IPAddress(STATIC_IP_GW), IPAddress(STATIC_IP_SUB)))
673+
{
674+
proto_info("Static IP config failed");
675+
}
685676
#endif
686677
WiFi.begin((char *)wifi_settings.ssid, (char *)wifi_settings.pass);
687678
proto_info("Trying to connect to WiFi");

uCNC/src/hal/mcus/rp2350/rp2350_arduino.cpp

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ typedef struct
108108

109109
uint16_t wifi_settings_offset;
110110
wifi_settings_t wifi_settings;
111+
111112
#endif
112113

113114
#ifdef BOARD_HAS_CUSTOM_SYSTEM_COMMANDS
@@ -151,6 +152,12 @@ bool mcu_custom_grbl_cmd(void *args)
151152
if (!strcmp((const char *)&(cmd_params->cmd)[4], "ON"))
152153
{
153154
WiFi.disconnect();
155+
#ifdef USE_STATIC_IP
156+
if (!WiFi.config(IPAddress(STATIC_IP_IP), IPAddress(STATIC_IP_GW), IPAddress(STATIC_IP_SUB)))
157+
{
158+
proto_info("Static IP config failed");
159+
}
160+
#endif
154161
switch (wifi_settings.wifi_mode)
155162
{
156163
case 1:
@@ -604,30 +611,11 @@ extern "C"
604611
}
605612
#endif
606613

607-
#ifdef USE_STATIC_IP
608-
#ifndef STATIC_IP_IP
609-
// 192.168.1.200
610-
#define STATIC_IP_IP 3355551936
611-
#endif
612-
#ifndef STATIC_IP_GW
613-
// 192.168.1.1
614-
#define STATIC_IP_GW 16885952
615-
#endif
616-
#ifndef STATIC_IP_SUB
617-
// 255.255.255.0
618-
#define STATIC_IP_SUB 16777215
619-
#endif
620-
621-
static IPAddress local_IP((uint32_t)(STATIC_IP_IP));
622-
static IPAddress gateway((uint32_t)(STATIC_IP_GW));
623-
static IPAddress subnet((uint32_t)(STATIC_IP_SUB));
624-
#endif
625-
626614
void __attribute__((weak)) mcu_network_init(void)
627615
{
628616
#ifdef ENABLE_WIFI
629617
#ifdef USE_STATIC_IP
630-
if (!WiFi.config(local_IP, gateway, subnet))
618+
if (!WiFi.config(IPAddress(STATIC_IP_IP), IPAddress(STATIC_IP_GW), IPAddress(STATIC_IP_SUB)))
631619
{
632620
proto_info("Static IP config failed");
633621
}
@@ -659,7 +647,12 @@ void rp2350_wifi_bt_init(void)
659647
if (wifi_settings.wifi_on)
660648
{
661649
uint8_t str[64];
662-
650+
#ifdef USE_STATIC_IP
651+
if (!WiFi.config(IPAddress(STATIC_IP_IP), IPAddress(STATIC_IP_GW), IPAddress(STATIC_IP_SUB)))
652+
{
653+
proto_info("Static IP config failed");
654+
}
655+
#endif
663656
switch (wifi_settings.wifi_mode)
664657
{
665658
case 1:

0 commit comments

Comments
 (0)