# \[OT\] Strange Arduino IDE problem

**URL:** <https://discourse.nodered.org/t/ot-strange-arduino-ide-problem/41247>\
**Category:** General\
**Created:** [18 February 2021 16:44 UTC](https://discourse.nodered.org/t/ot-strange-arduino-ide-problem/41247 "2021-02-18T16:44:08Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 February 2021 16:44 UTC](https://discourse.nodered.org/t/ot-strange-arduino-ide-problem/41247/1 "2021-02-18T16:44:08Z")

</div>

I know this isn't a node-red issue, but possibly someone here can help me out with a very odd issue.  
I am using the Arduino IDE to program a Wemos D1 Mini, which I have done before. I want it to have a fixed ip address so I have

```auto
IPAddress staticIP(192, 168, nn, 65); //ESP static ip
IPAddress gateway(192, 168, nn, 1); //IP Address of your WiFi Router (Gateway)
IPAddress subnet(255, 255, 255, 0); //Subnet mask
IPAddress dns(192, 168, nn, 1); //DNS

```

Then in `setup_wifi()` I have

```auto
  WiFi.config(staticIP, subnet, gateway, dns);
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

```

and everything works perfectly. However, and very strangely, if I specify 192.168.nn.66 for the ip address it ends up with nn.107 which is in the DHCP range. 19.168.nn.67 also works ok. I have looked in the router and can't see anything there that looks relevant.

Can anyone suggest anything or must I just resign myself to not using that address?

Edit: I have tried configuring a PC with .66 as the ip and it is ok, so it seems it is an Arduino ide issue. Google has not been helpful.

---

<div class="post-metadata">

**Author:** ![ghayne](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ghayne/32/39_2.png) [@ghayne](https://discourse.nodered.org/u/ghayne)\
**Post date:** [18 February 2021 17:57 UTC](https://discourse.nodered.org/t/ot-strange-arduino-ide-problem/41247/2 "2021-02-18T17:57:03Z")

</div>

Have you perhaps in the router configuration associated the PC MAC address with .66 at some point in the past? That's the only thing I can think of!

My EE Router has this option:  
 ![Opera Snapshot_2021-02-18_180122_192.168.1.1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/9/e907c4697302f200985a43c966483654e6e57db9.png)

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [18 February 2021 21:46 UTC](https://discourse.nodered.org/t/ot-strange-arduino-ide-problem/41247/3 "2021-02-18T21:46:26Z")

</div>

> [@Colin](#):
>
> `WiFi.config(staticIP, subnet, gateway, dns);`

Isn't it **WiFi.config(staticIP, dns, gateway,subnet)** , different order then you have.

> **[WiFi - Arduino Reference](https://www.arduino.cc/reference/en/libraries/wifi/)**
>
> The Arduino programming language Reference, organized into Functions, Variable and Constant, and Structure keywords.

Edit: Confusing, for the ESP8266 you see indeed **WiFi.config(staticIP, subnet, gateway, dns)** on the various forums.  
I'm using myself in a working project **WiFi.config(ip, gateway, subnet, dns1, dns2);**

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [18 February 2021 22:10 UTC](https://discourse.nodered.org/t/ot-strange-arduino-ide-problem/41247/4 "2021-02-18T22:10:46Z")

</div>

Plus it works fine with other addresses, and on the other Wemos I have had working for some time. It is only 66 that gives the problem.

---

<div class="post-metadata">

**Author:** ![stefan24](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/stefan24/32/23075_2.png) [@stefan24](https://discourse.nodered.org/u/stefan24)\
**Post date:** [18 February 2021 22:27 UTC](https://discourse.nodered.org/t/ot-strange-arduino-ide-problem/41247/5 "2021-02-18T22:27:16Z")

</div>

Can you ping that .66 or have you tried a netscan tool to check, whether .66 is indeed free?  
Which router do you use? My AVM Fritzbox has some IP addresses it reserves as soon as I configure VPN connections (but reacts not the way you described).

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [19 February 2021 10:50 UTC](https://discourse.nodered.org/t/ot-strange-arduino-ide-problem/41247/6 "2021-02-19T10:50:55Z")

</div>

> [@edje11](#):
>
> Isn't it **WiFi.config(staticIP, dns, gateway,subnet)** ,

Brilliant, well spotted, though it is even more complex than that. The Arduino function expects **ip, dns, gateway, subnet** but the config function for the ESP8266 expects **ip, gateway, subnet, dns**. To cope with this (presumably accidental) situation there is a function `ipAddressReorder` in the ESP library that examines the parameters and attempts to work out which is being used and swaps them round if necessary. If it finds values that don't seem to fit either pattern then it returns false to indicate a failure.  
Unfortunately I actually had **ip, subnet, gateway, dns** which I must have picked up from a tutorial somewhere and is wrong on all counts. It turns out that with the ip .66 the swap functions recognises there is an error and fails, causing DHCP to be used, but with .65 it thinks everything is ok, and uses that address. The gateway. subnet and dns were not right, but since I am only using it to communicate within the local network the gateway and dns don't matter, and provided the subnet is compatible with the ip it will work ok.  
So I have corrected it to the correct ESP format (IP, gateway, subnet, dns) and in addition added a test on WiFi.config that checks for a `false` return and logs a warning if so. I have also added comments explaining the situation so that hopefully I won't fall over it again.

Thanks to @edje11, @ghayne and @stefan24 for the help with this.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [5 March 2021 10:51 UTC](https://discourse.nodered.org/t/ot-strange-arduino-ide-problem/41247/7 "2021-03-05T10:51:06Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
