I'm after some help with making arduino's have a static IP.
I have it working every time using a wemos and ESP8266WiFi library but the following code using a uno R4 wifi only sometimes sets to the static IP and others connects via DHCP. I'm also having an issue declaring the mac.
If someone could shed some light on what i'm doing wrong, that would be great.
Do you have any other Arduino or ESP active inside the same local network?
Because I see you're using the infamous "DEAD BEEF FEED" Mac address, and if two or more devices expose the same mac address, serious IP packets routing issue comes out, and in this case even DHCP will be messed up (it assigns IP addresses based on Mac address)...
Have you told your router that you have defined that IP address as static on a device? Is it outside the DHCP range? Ideally leave your device using DHCP and configure the router to give the desired IP address to the device based on its Mac address.
yes using this library, if I add the mac into the wifi.config I get the following error:
Compilation error: no matching function for call to 'CWifi::config(arduino::IPAddress&, arduino::IPAddress&, arduino::IPAddress&, arduino::IPAddress&, byte [6])'
Why though, all esp's can have static IP's and they have worked correctly every time for me. There must be a way to correctly set a static IP. The static IP is outside of the DHCP range
That means you need a different configuration or code in each ESP. If it's that important to you that each ESP gets the same IP Address every time (although It's hard for me to imagine why that's important), then, as suggested, set up the static addresses in the router based on each ESP's MAC address. Then every time they connect with DHCP, they're served the same IP Address. It's also much easier to add additional ESPs with this setup.
Sadly router settings not an option. I have multiple devices talking to each other, that communicate differently depending on the IP address data is received from. I do a lot from tethering devices to phones so can't setup on each phone. Not sure why this is a specific problem to genuine arduino's when esp3266 devices work correctly with their libraries
I wonder how those two requirements work together? A device tethered to a phone has an IP address on the phone's LAN (i.e. 192.168.x.y). I suppose you can make that static if you want. But I'm pretty sure all internet traffic from that device carries the phone's external (i.e. routable) IP Address. So, doesn't that mean the phone acts as a router? So, won't any other ESP in your comm network see the IP Address of the phone, not the (static) IP Address of the other ESP on the phone's LAN?
Yes, there local ip on the phone hot-spot network is static. When I'm standing in the middle of the field and have 3 arduino's tethered to my phone, they all have Internet and all talking locally together talking over lan. When one receives info from a ip it responds differently to another ip whilst at the same time giving all devices Internet.
Anyone's phone can be used if they set their hot-spot ssid to what the arduino's are looking for.
Sorry, my fault, it's because ESPs don't need a MAC address to be defined, have their own ones.
So, forget it, I made confusion with Arduino (+Ethernet).
Why do it the way I suggest? So the router knows that those IP addresses belong to those particular devices, so making sure it doesn't allocate them to something else. If that happens you will get weird problems. Also, if you reserve them against the MAC address in the router you only have one place to go to change them should you wish to do so.
Then it's not a problem. What I am suggesting is, in my opinion, good practice. I'm not saying you have to do it that way, that's up to you.
Any device that is capable of connection to an IP network (wireless or Ethernet) should have a MAC address. If you let it connect to your network using DHCP then look in the configuration of the router you should be able to find it. Some / most / all routers allow you to assign a specific IP address to a particular MAC address, how you do so depends on the router, so read the manual or just poke around until you find it. If you happen to have a Draytek router then I can tell you, anything else then I don't know.
Thanks for the replies but I'm not sure it's relevant. I am aware I could do it the way you are talking about. This thread is about coding an arduino to a static ip and specific mac address. If you read above you will see the use case to why I don't want to do it your way. This seems to be a specific issue with the uno R4 using the wifis3 library. Every other version of arduino or esp8266 I've used I can correctly set the ip and mac.