pkerspe / ESP-StepperMotor-Server

Turn your ESP32 into a complete stepper motor control server with web UI, REST API and serial control interface
MIT License
225 stars 39 forks source link

Feature Request: Ability to configure Static IP, Gateway and Subnet Mask #13

Closed Stormer2k0 closed 3 years ago

Stormer2k0 commented 3 years ago

It would be rather useful to be able to configure a static IP the same way you configure the SSID name and password. You still can just add a static IP by just by adding this in the main:

IPAddress local_IP(10, 38, 4, 110);
IPAddress gateway(10, 38, 4, 1);
IPAddress subnet(255, 255, 255, 0);

if (!WiFi.config(local_IP, gateway, subnet)) {
    Serial.println("STA Failed to configure");
}

And if not adding static IP to the library then maybe add an example for the people who don't know how to do this.

Stormer2k0 commented 3 years ago

@pkerspe I used this syntax as in WiFiSTA.cpp that is the order the function is written: 2020-10-09 12_36_50-WiFiSTA cpp - Untitled (Workspace) - Visual Studio Code

dns1 and dns2 arn't nessesary as those have been given a default value in the constructor: 2020-10-09 12_47_29-WiFiSTA h - Untitled (Workspace) - Visual Studio Code

pkerspe commented 3 years ago

added in version v0.4.2 Example 3 shows how to use it.

 IPAddress staticIp(192, 168, 178, 49);
 IPAddress gatewayIp(192, 168, 178, 1);
 IPAddress subnetMask(255, 255, 255, 0);
 stepperMotorServer->setStaticIpAddress(staticIp, gatewayIp, subnetMask);

Or you can add the new config nodes to the json config file in the server config section:

...
{
  "serverConfiguration": {
...
    "staticIP": "192.168.178.49",
    "gatewayIP": "192.168.178.1",
    "subnetMask": "255.255.255.0"
  },
...
pkerspe commented 3 years ago

please test and report if all works as requested