TCP connect hard fault

Hi every one,
I’ve just received my first photon and wrote a small program.
Connecting to my local server works fine … almost. Every 2nd (sometimes 3rd) connection leads to a hard fault.
I’ve googled and found which seems to be my problem. Even though it happens way more often to me.

Can anyone tell me, if the solution/fix from that thread is already in the firmware? so should it be fixed if I’m compiling with the newest version, or can I do something (like upgrading the firmware on the WiFi module).

Thanks in advance,

@JKW, Actually what works for me now is to build on version 0.4.5 or locally on develop. If I understand correctly, there was another bug that crept back in to the firmware in 0.4.6 (latest) and will be fixed in 0.4.7

1 Like

man! you made my day. after testing for multiple days, digging through github bugreports and trying to find the solution myself, yours worked right away!

Well nearly…
After extended testing for more time I saw some glitches.
Far away from the last version, where it died every second time but still not 100% perfect.

Is version 4.7 suppose to fix all of those problems?
Thanks jkw

Hi, I have to reach out once more.
Same topic. This hard fault happens in an unpredictable way.

Could someone (mabe @bpr) take a look, its a pretty easy program:

Log: `1/5
Connect to MACS system
WiFi credentials saved
---- Enable Wifi ---------
try 1/20 to reach macs wifi
WiFi connected, here we go!
---- Get Update ---------
ID never set, readingid for this device as 32
und los
connect to!
db request took 887 ms
Total received keys for my id(32):5
Valid Database Key Nr 1: 6215027
Valid Database Key Nr 2: 8286470
Valid Database Key Nr 3: 5103711
Valid Database Key Nr 4: 8279687
Valid Database Key Nr 5: 2147483647
Tag 6215027 found.
Checking database (5) for matching key

1 / 5 Compare current read tag 6215027 to stored key 6215027
Key valid, closing relay
Connecting relay!
und los
connect to!`

** at this point RED RED RED **

sometimes it works a few times, and creates a few entries in my DB, but it will crash within the first 20 tries.

any idea why?

@JKW, gosh, wish I could make sense of your pretty easy(?) code and help but it’s beyond me!
I have no knowledge of the HTTP Client.
In case it’s any use to you, here’s my simple TCP Client code. Haven’t actually used it for anything yet; it’s just a bit of code I wanted to write in case I needed in the future a low-power battery compatible messaging system between photons. It never panics on 0.4.5 or the develop branches, and seems to work with a photon based TCP server(let me know if you want that code) as well as with a simple nodejs server.
Make sure of course your base firmware and program code are all compiled on either 0.4.5 or develop.

//WORKING fine on 045 and develop branches but panics randomly on 0.4.6
//adapted from @Hootie81 & @jon1977 in
#include "application.h"
int serverPort = 6123;
uint32_t lastTime;
char read_char;
char clientmsg = 'x';
char replymsg = '9';
byte server[] = {192, 168, 1, 157};
bool complete;
TCPClient client;
char outmsg[50];

void out(const char *s) {client.write( (const uint8_t*)s, strlen(s) );}

void setup()

void loop() {
  //low power
  System.sleep(D3, RISING, 4);
  if (digitalRead(D3)) {digitalWrite(D6,HIGH);delay(200);digitalWrite(D6,LOW);}

  while (!WiFi.ready()) {
  }// while (!WiFi.ready())

  complete = false;

  //don't unsuccessfully persist trying beyond 10 secs, just go back to sleep
  lastTime = millis();
  while ((!complete) &&  (millis() - lastTime < 10000)){

  if (client.connect( server, serverPort)) {
    if (client.connected()) {

    lastTime = millis();
    while ((!client.available()) && (millis() - lastTime < 5000)) { } //critical 10000

    lastTime = millis();
    while ((millis() - lastTime < 300)) {}//plays better with nodejs server?

 //now get confirmation from server that server received msg
    while (client.available()) {
      read_char =;
      if(read_char == replymsg ) { //we got confirmation
        complete = true;
      }//if(read_char == replymsg )
    }//while (client.available())
  }//if (client.connected())
}//if (client.connect( server, serverPort));

}//while (!complete)

// prevent nodejs ECONNRESET, not necessay with another photon??
  lastTime = millis();
  while ((millis() - lastTime < 500)) {}//prevent nodejs ECONNRESET


hey @bpr, thanks for your code. I’ve copied the mode to manual as you did and added

// test
static int i=0;

at the end of my loop() and sure enough every thing works, I’m monitoring over 1400 accesses without problems.
Being pretty confident that the problem was just connected to the system mode, i went on and removed theses lines.

boom, second request -> SOS.

ok so that specificy entry has to be different from what I send if I receive a RFID tag input … lets go on and fake that

static int i=0;
} else {

guess what … runs in iteration 7923 right now, so the arguments aren’t the problem. So what now? is there some kind of memory allocation error? I’ve added system.freemem() right in front of every call but its pretty much constant at 59824

so obviously it must have a difference from where you call it … e.g. if you call validate_tag() or what ever upfront, but(!) as long as i let the loop() run and call the server every 200mc I can let the full application run. Even with scanning my tags, opening the relay etc. Last try: remove that line and back to [BOOM] after the second read … so what now?
Call the server ever 200ms just for keeping the photon alive?