JonnyBooker / split-flap

Code for split-flap display based on: https://github.com/Dave19171/split-flap
https://www.prusaprinters.org/prints/69464-split-flap-display
GNU General Public License v3.0
38 stars 6 forks source link

Possible to add static ip? #7

Closed beroliv closed 2 months ago

beroliv commented 4 months ago

Possible to add static ip to the sketch?

JonnyBooker commented 4 months ago

I would probably say this is a job for your internet router? Think this would be best to avoid conflicts on your network if multiple devices are trying to reserve the same IP address, as your router is aware of all the devices on the network.

Is there a specific reason you'd like to set it up on the device? Maybe ease or your router doesn't allow such actions?

I've never tried to set up a static IP on an individual Sketch before so cannot confirm if it is possible. The library being used underneath is WiFiManager to look after WiFi connections, this might expose something to be able to achieve a static IP. I can have a look into it potentially if get some time over the next few days.

beroliv commented 4 months ago

Hart Code Static ip Adress with try and error

//Initialize WiFi void initWiFi() { int wifiConnectTimeoutSeconds = 180; WiFi.setPhyMode(WIFI_PHY_MODE_11G); // Connection Problem solved? WiFi.mode(WIFI_STA);

// Set your Static IP address IPAddress local_IP(192, 168, 0, 81); // Set your Gateway IP address IPAddress gateway(192, 168, 0, 1);

IPAddress subnet(255, 255, 255, 0); IPAddress primaryDNS(8, 8, 8, 8); //optional IPAddress secondaryDNS(8, 8, 4, 4); //optional // Configures static IP address if (!WiFi.config(local_IP, gateway, subnet, primaryDNS, secondaryDNS)) { Serial.println("STA Failed to configure"); }

...

JonnyBooker commented 4 months ago

@beroliv - Have you tried the above code and found that it works? I haven't had the chance/capacity to look into setting a static IP address using WiFi Manager recently, will hopefully soon.

beroliv commented 4 months ago

I used one of the left over esp. it works somehow. But in the List of devices, in the router shows me the wrong old dhcp adress. When i try to open the ui i can open the ui with the programmed adress. Thats strange i know.

JonnyBooker commented 3 months ago

I've had some time to work on this project. I've introduced a new section for setting a static IP address as a experimental feature.

Currently working off of this feature branch until done further testing: feature/indefinite-scheduled-messages-and-wifi

Inside the ESPMaster.ino, at the top of the file, you'll find a new property you can set to true:

#define WIFI_STATIC_IP      true

Then further down the file you'll find another section for variables which you can set your static IP address amongst other settings:

#if WIFI_STATIC_IP == true
//Static IP address for your device. Try take care to not conflict with something else on your network otherwise
//it is likely to not work
IPAddress wifiDeviceStaticIp(192, 168, 1, 100);

//Your router details
IPAddress wifiRouterGateway(192, 168, 1, 1);
IPAddress wifiSubnet(255, 255, 0, 0);

//DNS Entry. Default: Google DNS
IPAddress wifiPrimaryDns(8, 8, 8, 8);
#endif

My initial testing of this has worked, as noted, if you use a IP address of an existing device on your network, it probably isn't going to work. But, looks to work in both direct/ap mode too.

Hopefully this might be what was looking for 😃

JonnyBooker commented 3 months ago

Will close this issue within the next week, I've created a solution I've tested above which has worked from my testing so feel the original issue has been resolved. I will merge the associated PR within the next week and update the readme.md to have details on how to use the new feature.

JonnyBooker commented 2 months ago

Closing this item down now the PR has been merged. Static IP Address functionality is in master and in release 2.2.0