Photon is unable to connect to wifi after flashing static IP code. [ SOLVED ]


#1

Dear all,
I have no clue what is going on with my photon.
My photon was running perfectly fine : running simple web server just before I insert code to establish static IP.
I wanted to run the web server at same IP regardless of the wifi networks that it is connected.
The code I inserted is like this.
In fact, I obtained this piece of code from this link here.

void setup() {
//Turn off wifi so we can set up our static ip
WiFi.off();
//Set static ip info
IPAddress myAddress(192,168,1,100);
IPAddress netmask(255,255,255,0);
IPAddress gateway(192,168,11,1);
IPAddress dns(192,168,11,1);
//Actually set the static ip
WiFi.setStaticIP(myAddress, netmask, gateway, dns);
//Tell the photon to use the static ip 
WiFi.useStaticIP();
//Reconnect to wifi
WiFi.on();
WiFi.connect();
.........
}

It successfully flashed and uploaded to photo.
After importing that, my photon lost internet connection.
When I logged into my router site, it is showing that IP address that I set.
But it keeps flashing cyan.
I spent for about 8 hours… tried to reset, go into safe mode, upload the firmware again…
But I still couldn’t get it right.
After that, I try to download the original working code which is firmware.bin and upload via dfu.
Photon doesn’t seem to be accepting any code imported with dfu.
I tried to set up with iOS app but when it reaches the stage of connecting to wifi network, it is flashing cyan forever.
I followed the troubleshooting guide and searched every single topic related to my problem in google… but could not find any working solution.
I am losing hope. :frowning:

Firmware version is 0.5.1.


#2

WiFi.useStaticIP() is a sticky setting. If you want to revert to dynamic IP you’d need to actuvely set that via WiFi.useDynamicIP().
And you are using 192.168.11.x and 192.168.1.x with subnet mask 255.255.255.0 so you are dealing with two seperate subnets.
How does your device behave when you have the Photon in the same subnet as its gateway?


#3

I could not think much about the subnet mask because it is my first photon project. :pensive:
It lost connection to wifi and was flashing cyan forever.
Hence, I cannot upload the code to photon from both web and desktop IDE.


#4

You can always flash via CLI or dfu_util if you have them on your computer (always a good idea to have them :wink: )


#5

Yeah I flashed firmware.bin via dfu_util. Although it showed successful flashing… the code doesn’t seem to be updated at all.
Cyan is always flashing and still cannot connect to wifi.
I will try with CLI method. Thank you. :blush:

This is the screenshot of DFU flashing.


#6

Try flashing this

SYSTEM_MODE(MANUAL)
STARTUP(WiFi.selectAntenna(ANT_INTERNAL))
void setup()
{
  WiFi.on();
  WiFi.useDynamicIP();
  WiFi.connect();
  waitUntil(WiFi.ready);
  Particle.connect();
}
void loop()
{
  Particle.process();
}

#7

Sorry. I am not sure how to debug this… My bad. :sweat:


#8

You seem to be targeting a Core and not a Photon.
You need to select the correct target device to build a suitable binary.


#9

How should I do that?
I cannot find photon under devices because I remove it from the list to restart everything freshly.
I have made a mistake. :disappointed_relieved:


#10

You can compile via CLI.
Put the sketch into a text file, rename it to something.ino and do

particle compile photon something.ino

then you should get a .bin file to flash via CLI

particle flash --usb your.bin

You usually don’t need to remove or unclaim devices from your list - not even if things go wrong. There usually are other causes that can fixed otherwise.


#11

Appreciate for clear and straight forward instruction.
I thought restarting everything from step 1 such as removing from the list could help… end up causing me to get headache. :grin:
I was able to flash your code via cli.
Now, photon is flashing in such a way that cyan is blinking periodically … then suddenly blinking very fast in cyan followed by red light… and then repeats.
Any idea, Sir?


#12

Is this a very short fast burst of orange (three or so very brief flashes)?
Then you could try

particle keys doctor <yourDeviceID>

#13

It was very short burst of orange.
Thank you, Sir. Thank you very much.
You have helped me within a couple of hours to solve the problem which I have been struggling for 8 hours.
It worked like a charm.
I was looking through this thread.
I typed these in terminal provided in the above thread.

  1. particle keys server cloud_public.der
  2. particle keys new photon
  3. particle keys load photon.der
  4. particle keys send photon.pub.pem

No 4. command did not work in Terminal.
At the moment, I saw your reply.
Then I typed in command you provided.

< particle keys doctor myDeviceID >

Magically, I see cyan breathing on photon.
Photon is connected to wifi and my web server works like it did before.

Again, thank you very much, Sir.
It means a lot to me.


#14

Hi ScruffR,

So I am having a similar issue with the red led glowing.

So what I am trying to do here is

  • I am using the WiFi.useDynamicIP() to get the local ip address assigned by the router.
  • then i am retriving the first 3 bytes of this ip address
  • then i am trying to set a static ip address using the first three bytes of the dynamic local ip and concatenating with 254 to assign the ip address.
  • then i am calling the setStaticIp() function.

Right after the above photon led blinks twice red and then it resets. The same cycle repeats after reset.

Please suggest.


#15

It’d be better (and easier) to post the code than just spelling out what you intend to do.