# Static IP (not static dynamic) \[RESOLVED\]

**URL:** <https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707>\
**Category:** Cloud\
**Created:** [May 29, 2014, 11:54pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707 "2014-05-29T23:54:23Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sej7278](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@sej7278](https://community.particle.io/u/sej7278)\
**Post date:** [May 29, 2014, 11:54pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/1 "2014-05-29T23:54:23Z")

</div>

How do you configure the sparkcore to use a static ip address?

i don’t mean a static dynamic using mac addresses, i mean true static ip’s that need no router config.

I’m writing a TCPServer and was a bit surprised that none of the `IPAddress` functions actually _set_ the IP, as `Network.localIP();` does not match what i set.

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [May 30, 2014, 12:13am UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/2 "2014-05-30T00:13:56Z")

</div>

The TI CC3000 WiFi module does this in a very funny way by stuffing the IP address into the MAC address and the current core firmware does **not** handle this (which I think is perfectly reasonable). You can do it yourself with the instructions here and calling `netapp_dhcp` and reseting the TI CC3000.

[http://processors.wiki.ti.com/index.php/CC3000\_Basic\_Wi-Fi\_example\_application\_for\_MSP430#Static\_IP\_Configuration](http://processors.wiki.ti.com/index.php/CC3000_Basic_Wi-Fi_example_application_for_MSP430#Static_IP_Configuration)

Since the core always has to talk to the gateway anyway, I think it makes more sense to define a static address in your router’s DHCP server.

---

<div class="post-metadata">

**Author:** ![sej7278](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@sej7278](https://community.particle.io/u/sej7278)\
**Post date:** [May 30, 2014, 12:25am UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/3 "2014-05-30T00:25:01Z")

</div>

> [@bko](#):
>
> Since the core always has to talk to the gateway anyway, I think it makes more sense to define a static address in your router's DHCP server.

i don't agree, its not very portable having to configure ether tables, or what if i don't want to run a dhcp server, or i don't have control of the router (e.g. corporate)?

i'll have a look at the TI docs though, thanks for the link.

edit: i tried it, but for some reason the ip address was backwards! adafruit comments on how to do it with their cc3300 breakout: [https://forums.adafruit.com/viewtopic.php?f=31&t=47004](https://forums.adafruit.com/viewtopic.php?f=31&t=47004)

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [August 9, 2014, 8:20pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/4 "2014-08-09T20:20:15Z")

</div>

Sorry to dig up an old thread. I’m thinking this could be fixed in the firmware and made configurable using the existing means of wifi configuration. It seems to be a fairly often requested feature.

[netapp\_dhcp](https://github.com/spark/core-firmware/blob/master/src/spark_wlan.cpp#L131)() is currently called as part of the CC3000 initialization, where all values are set to 0. (activating DHCP.)

I’m wondering if static IP can be supported by storing the values that are passed to netapp\_dhcp() in persistent storage? Say, somewhere in the reserved areas of flash. That way, on startup the cc3000 is configured using the values from flash - either all 0s for DHCP, or configured IP addresses for static.

Then we extend the existing tools (serial config, smartconfig, spark cli etc…) to get/set the static IP/DHCP setting by reading/writing the appropriate flash location.

---

<div class="post-metadata">

**Author:** ![sej7278](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@sej7278](https://community.particle.io/u/sej7278)\
**Post date:** [August 9, 2014, 9:52pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/5 "2014-08-09T21:52:34Z")

</div>

@mdma i’ve been playing with just that todayas i’ve seen its been done on arduino and msp430/mbed.

i’ve managed to assign a static ip/netmask/gateway/dns by putting this in setup() - note that the ip address octets are backwards and in lowercase hex:

```auto
    unsigned long pucSubnetMask[1] = {0x00ffffff}; // 255.255.255.0
    unsigned long pucIP_Addr[1] = {0x2a00a8c0}; // 192.168.0.42
    unsigned long pucIP_DefaultGWAddr[1] = {0xfe00a8c0}; // 192.168.0.254
    unsigned long pucDNS[1] = {0x08080808}; // 8.8.8.8

    netapp_dhcp(pucIP_Addr, pucSubnetMask, pucIP_DefaultGWAddr, pucDNS);   
    wlan_stop();
    delay(200);
    wlan_start(0);

```

i’ve proven it by assigning an ip outside of my dhcp range. so all we need now is a pretty way of calling it and configuring it via usb/cli and i guess smartconfig.

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [August 9, 2014, 10:42pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/6 "2014-08-09T22:42:40Z")

</div>

Cool. Have you been able to ping the spark externally? and the spark can connect to the cloud? It might also be worth printing out the network IP to serial.

> [@sej7278](#):
>
> it looks like you have to pass in a 4-octet array of each of ip, netmask, gateway and dns server in hex - some docs say it has to be lowercase and backwards.

Just so you know, since these are integer values, not strings, the case doesn't make any difference - they are converted to the same 32-bit literal values by the compiler.

They are hex, because you pack 4 bytes into one 4-byte value - each pair of hex digits is 1 byte so hex makes it easy. The values are inverted because of the cpu architecture (little-endian).

But looking at the docs, I'm surprised you have to do it like that. If you later find the spark isn't getting the static IP, could you try something like this?

```c++
unsigned long ip[] = {192, 168, 2, 51};
unsigned long subnet[] = {255, 255, 255, 0};
unsigned long gateway[] = {192, 168, 2, 1};
unsigned long dns[] = {192, 168, 2, 1};

long status = netapp_dhcp(ip, subnet, gateway, dns);

wlan_stop();
delay(20);
wlan_start(0);

```

---

<div class="post-metadata">

**Author:** ![sej7278](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@sej7278](https://community.particle.io/u/sej7278)\
**Post date:** [August 9, 2014, 10:46pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/7 "2014-08-09T22:46:33Z")

</div>

i tried putting the individual octets into an array and it didn’t like it.

yes i can ping the core, yes it can connect to the cloud - i’ve been sending it tweets too 😉 and `Serial.println(WiFi.localIP());` etc. works too - that’s how i debugged it

p.s. thanks for the explanations @mdma

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [August 9, 2014, 10:55pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/8 "2014-08-09T22:55:40Z")

</div>

Cool, nice one and congrats you got it working! Just wanted to be sure! 🙂

It should be fairly straightforward to make the IP configurable, and add this to the serial config, spark cli and maybe smartconfig too.

But one thing puzzles me, why does the firmware call netaddr\_dhcp() on each startup, since the values given are persisted to the cc3000 eeprom, so this method only needs calling if the values changed. This would seem to generate unnecessary wear on the cc3000’s eeprom. cc’ing @satishgn who probably knows the reason behind it!

---

<div class="post-metadata">

**Author:** ![sej7278](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@sej7278](https://community.particle.io/u/sej7278)\
**Post date:** [August 9, 2014, 10:57pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/9 "2014-08-09T22:57:59Z")

</div>

hmm, i take it back, for some reason it doesn’t seem to work if i enable the cloud - still gets a dhcp address, but i guess that’s a symptom of doing this from the sketch rather than earlier in the library - its getting a dhcp address before entering setup()

anyway, its just a proof-of-concept, so we know it can be done (oh and it can still connect to the internet if i disable the cloud), someone just needs to add it into the libs rather than the sketch and that should sort the cloud issues. plus some exception handling 😉

---

<div class="post-metadata">

**Author:** ![satishgn](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/satishgn/32/20740_2.png) [@satishgn](https://community.particle.io/u/satishgn)\
**Post date:** [August 10, 2014, 5:50am UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/10 "2014-08-10T05:50:13Z")

</div>

correct @mdma netapp\_dhcp() need not be called everytime. I guess that was added in way back while debugging the cause of CFOD bug months ago. Certainly needs to invoke the same conditionally.

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [August 10, 2014, 11:53am UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/11 "2014-08-10T11:53:05Z")

</div>

Thanks for the confirmation! Perhaps it’s best to put the netapp\_dhcp() call in with the wifi configuration, so it’s only involved when wifi details are changed.

---

<div class="post-metadata">

**Author:** ![rocksetta](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rocksetta/32/5099_2.png) [@rocksetta](https://community.particle.io/u/rocksetta)\
**Post date:** [May 14, 2015, 6:25pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/12 "2015-05-14T18:25:01Z")

</div>

Its been a while since this thread was active. @mdma Is this still the accepted way to assign a static IP?

```
    unsigned long pucSubnetMask[1] = {0x00ffffff}; // 255.255.255.0    
// NOTE: the bytes are enterd in reversed pairs
    unsigned long pucIP_Addr[1] = {0x2a00a8c0}; // 192.168.0.42
    unsigned long pucIP_DefaultGWAddr[1] = {0xfe00a8c0}; // 192.168.0.254
    unsigned long pucDNS[1] = {0x08080808}; // 8.8.8.8

    netapp_dhcp(pucIP_Addr, pucSubnetMask, pucIP_DefaultGWAddr, pucDNS);   
    wlan_stop();
    delay(200);
    wlan_start(0);

```

And are the other steps still needed. (what @bko mentioned about reseting the TI CC3000. ) or can I just plug this code into my .ino file? My problem is that I would like to operate this from home, I could port forward using the MAC address, but at work I have a set internal IP connected to an external IP, and then from my cells hotspot (OK this last one may never work since I would need some kind of control over my service provider ) Any suggestions? I am leaning towards @bko suggestion to have my Cores TCP server connect to an external Nodejs server to handle the communication.

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [May 14, 2015, 6:26pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/13 "2015-05-14T18:26:26Z")

</div>

Just to be clear: this method will only work on the TI CC3000, not on the new Photon etc.

---

<div class="post-metadata">

**Author:** ![rocksetta](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rocksetta/32/5099_2.png) [@rocksetta](https://community.particle.io/u/rocksetta)\
**Post date:** [May 14, 2015, 6:26pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/14 "2015-05-14T18:26:59Z")

</div>

So on the Photon, can the static IP be set???

---

<div class="post-metadata">

**Author:** ![sej7278](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@sej7278](https://community.particle.io/u/sej7278)\
**Post date:** [May 19, 2015, 10:37pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/15 "2015-05-19T22:37:59Z")

</div>

yes come on, its crazy that we had to resort to a hack to get this working on the core, it needs to be done properly for the photon.

---

<div class="post-metadata">

**Author:** ![sej7278](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@sej7278](https://community.particle.io/u/sej7278)\
**Post date:** [June 3, 2015, 4:57pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/16 "2015-06-03T16:57:42Z")

</div>

netapp\_dhcp() no longer seems to work at all in the develop or hal branches, i assume its been replaced by something not cc3300-specific, if so what with?

do we have a portable way to assign a static ip on both devices yet?

---

<div class="post-metadata">

**Author:** ![bko](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/bko/32/20704_2.png) [@bko](https://community.particle.io/u/bko)\
**Post date:** [June 3, 2015, 5:07pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/17 "2015-06-03T17:07:08Z")

</div>

Hi @sej7278

I don’t see anything in the HAL layer to allow you to set static IP addresses. Perhaps @mdma could have a look.

If you want to open or comment on an issue on github, that would get it on their backlog.

---

<div class="post-metadata">

**Author:** ![sej7278](https://avatars.discourse-cdn.com/v4/letter/s/8c91f0/32.png) [@sej7278](https://community.particle.io/u/sej7278)\
**Post date:** [June 3, 2015, 5:12pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/18 "2015-06-03T17:12:27Z")

</div>

ok thanks, i’ll wait to see what @mdma says before raising a github issue.

there used to be a very colourful website listing the backlog (not github) can anyone remember that, sorry i’ve been away from the community for a while.

---

<div class="post-metadata">

**Author:** ![mdma](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/mdma/32/1924_2.png) [@mdma](https://community.particle.io/u/mdma)\
**Post date:** [June 3, 2015, 6:06pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/19 "2015-06-03T18:06:55Z")

</div>

If you add `#include "netapp.h"` that will make it compile. Previously on the core the whole stack was included by default, including the cc3000 headers. This causes quite a few issues - `delay()` vs `Delay()` and `TRUE` `FALSE` being defined and used (when people should be using true and false.)

They were removed when making the HAL to be sure our code was truly platform agnostic. Now we have a separate user module, these can be added back into the user namespace so that user apps get full access to the underlying platform (on the Core.) I will add this in the develop branch shortly.

---

<div class="post-metadata">

**Author:** ![peekay123](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/peekay123/32/810_2.png) [@peekay123](https://community.particle.io/u/peekay123)\
**Post date:** [June 3, 2015, 6:16pm UTC](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707/20 "2015-06-03T18:16:22Z")

</div>

@mdma, it sounds like including “netapp.h” only applies to the Core. Does the Photon suppot static IPs?

[Next page](https://community.particle.io/t/static-ip-not-static-dynamic-resolved/4707.md?page=2)
