Photon internet Connection issues, Converted Code from core to photon

We have been struggling to get the photon working as well as we were able to get the core working. This might be expected as the code we developed was built up and each routine tested as we added more. There were plenty of connection and crashing issues with the cores as well. Although by the end of it, we had some very stable and functioning code. This code is currently running on 10 cores as we speak with little to no issue, maybe once a week I get an email one rebooted.

Moving on, now unable to get the core any more, we had to port our code to the photon. After a few weeks of tweaking and flashing new firmware, we have gotten it to function ok.

There is an issue, when we submit the “Start” command to our photon, it connects to the website and reads all the information it needs, then goes semi-unresponsive.

Symptoms
Tries to connect to the URL but fails over and over again.
It can ping the local wifi router
It can not goto sleep, just turns the wifi off and never back on again.
Can still send additional web commands to the photon, But it always fails to respond after the first
System.memory() returns around a 5000 value

Our semi Fix:
After the 4.3 firmware the photons stopped rebooting on socket connection failed. We added a System.reset() function every time the photon starts. This works pretty well, except sometimes the photon goes unresponsive outside of the start function.

We can’t share the code due to the size of it, its over 15 custom libraries.

Any thoughts or idea’s why the photon would be able to communicate locally, but not be able to reach an internet host.

On boot, if the website tells the program to start it runs just fine
void setup{
net.message(NET_BOOT);
net_retrieve_data(flush);
}

Serial out:

1101010000320493048d048304790000 <— This command is the stop command
2701010000320493048d048304790000 <— This is just describing what is stopping
2301010000320493048d048304790001RL CYCLE 2 <— This is just describing what is stopping
Message sent successfully
Message sent successfully
Message sent successfully
5*<------- Ping from the core to the router*
5 <------- Ping from the core to the router
1001010000320493048d048304790000 <--------------10 Network command to start
unable to connect**<----outbound internet traffic stops here, and never recovers**
Failed to send message ( on connect )
5
Wifi Down
Wifi Up
unable to connect
unable to connect
Failed to send message ( post connect )
5
unable to connect
Failed to send message ( on connect )
5

Thank you,
Brian

Hi @Brian

There are really important fixes to TCP in 0.4.4 and if you have not upgraded to that release you really need to do that first. After that if you are still having problems, read on:

Have you tried taking DNS out of the equation by using the IPAddress of the Internet host? I have some code that fails on a Photon but works on a Core that seems to be sensitive to DNS problems that I am still debugging. It is worth trying removing DNS in my opinion.

Hi BKO,

Yes I have updated to 0.4.4

I’ll try the DNS idea.

Wow, So that was unexpected. It hard crashed with RED flashing LED

Serial out:
cycle attached
22010100000000000000000000000001RL CYCLE 2
cycle started
Local ping: 5
Internet Ping: 5

Adjusted code. Added Sever2

if ( millis() - test > 5000 ){
      uint8_t server2[] = { 208, 113, 128, 195};
      uint8_t server[] = { 192, 168, 1, 1};
      Serial.print("Local ping: ");
      Serial.println(WiFi.ping(server));
      Serial.print("Internet Ping: ");
      Serial.println(WiFi.ping(server2));

      test = millis();
  }

(ScruffR: I reformatted your code block)

I’ll just try to ping 1 server next.

1 Server ping works fine.

Serial out
20000000000000000000000000000000
cycle attached
22010100000000000000000000000001RL CYCLE 2
cycle started
Internet Ping: 5
Message sent successfully
26010100000000000000000000000001
Message sent successfully
Message sent successfully
Message sent successfully
Internet Ping: 5
Internet Ping: 5
Internet Ping: 5
Internet Ping: 5
Internet Ping: 5

It still crashes.

The Internet ping to the server works the entire time.
It looks like the photon connects to the server, but the data errors out.

Any Idea’s on how to see exactly what the photon is sending to the website? I’m sure it must be garbled, because this exactly same command works flawlessly in void setup(){ }

Serial out

20000000000000000000000000000000
cycle attached
22010100000000000000000000000001RL CYCLE 2
cycle started
Internet Ping: 5
Message sent successfully
26010100000000000000000000000001
Message sent successfully
Message sent successfully
Message sent successfully
Internet Ping: 5
Internet Ping: 5
11010100000c0496048c048704780000
27010100000c0496048c048704780000
23010100000c0496048c048704780001RL CYCLE 2
Message sent successfully
Message sent successfully
Internet Ping: 5
Message sent successfully
Internet Ping: 5
10010100000c0496048c048704780000
03010100000c0496048c048704780001
Message failed on server
Internet Ping: 5
Message failed on server
03010100000c0496048c048704780002
Message failed on server
Message failed on server
03010100000c0496048c048704780003
Message failed on server
Message failed on server
Internet Ping: 5
03010100000c0496048c048704780004
Message failed on server
Message failed on server
03010100000c0496048c048704780005
Message failed on server

There is a definite DNS issue, I have replaced everything with IP address.

I can start and stop the photon, with web commands by replacing the DNS. But after the first web "Start" command all the message to the server fail.

  • The photon can ping the server
  • the Server can ping the photon
  • Photon can connect to the server and access the database information
  • The Photon can receive web commands from the server to start and stop

The Photon can not send messages on its own to the server. No POST

Any Idea's? I think installing a packet sniffer to my router is the next best hope, and trying to see what data is really being sent.

I forgot to replace the _host with my url in the POST routine :smile:

So its not a DNS issue, its the storage of the DNS in a variable that looks to be the issue.

Hard coding the URL into the print HTML worked

        client.println("POST /status.pl HTTP/1.1");
        client.print("Host: ");
        client.println("www.google.com");      
        client.println("User-Agent: GrowNet/0.0");
        client.println("Connection: close");
        client.println("Content-Type: application/x-www-form-urlencoded;");
        client.print("Content-Length: ");