Panic, Hard_Fault with TCP Client

Hi all,

I´m trying to send some info using tcp from the photon to many devices, but many many times im getting the following Panic, Hard_Fault event.

My code is as follows:

        for(uint8_t i = 0; i < amountOfServersAllowed; i++){
            if(activeServer[i] == 1){
                if (client.connect(serversAddress[i], serversPort[i])){
                    Particle.publish("Connection Failed");

Any clue?

@alexgrauer, can you show your declarations for serversAddress[] and serversPort[]?


IPAddress serversAddress[10];
uint16_t serversPort[10];

uint8_t server1_bytes[] = {192,168,5,55};
IPAddress server1(server1_bytes);

//In the Setup()

for(uint8_t i = 0; i < amountOfServersAllowed; i++){
        activeServer[i] = 0;
serversAddress[0] = server1;
serversPort[0] = 8080;
activeServer[0] = 1;

Actually we’d need all the info about your arrays and the variables applied to them in that code snippet.

Chances are that you are exceeding any of the array boundaries (e.g. actual_porcentage - I guess percentage :wink: - could be too long to fit into TCP_tx_ buffer, or amountOfServersAllowed could be set too high, …)

@ScruffR, thanks for the answer. There you can see the variables involved.
And thanks about the “percentage” correction. My native language is spanish and we write it Porcentaje, so i guess thats where the confusion came from.

#define amountOfServersAllowed 10

uint8_t activeServer[amountOfServersAllowed];
char TCP_tx_buffer[200];
uint8_t actual_porcentage = 101;

1 Like

What does it mean @abelsm2 message? I didnt solve the problem yet! :frowning:

@ScruffR, do you see anything wrong with the definition of the arrays? I dont see an out of boundaries happening.
What else could it be?


Sorry, I wrote a response and then realized that I don’t think I know what the problem is and I didn’t want to lead you down the wrong path, so I deleted my answer.

What I had pointed out was that you need to keep track of how many sockets you are using. There are currently only 4 sockets available to the user on the photon. Any time I’ve accidentally tried to use more than 4, I get a fault with SOS blink code. It looked to me since you are allowing 10 connections that you will quickly exceed the number of sockets available.


Ok, thanks @abelsm2.

I still have the problem.
I changed the code to this:

uint8_t actual_porcentage = 50;
 byte server[] = { 192, 168, 5, 55 };
    if (client.connect(server, 8080)){
        Particle.publish("Connection Failed");

And still the same. I get the panic, hard_fault.
Anyone with a clue?