Red light when running TCP code [solved]

Hi everyone,
I’ve run this code :

byte serv[] = { 192, 168, 1, 75 }; //dos
//SYSTEM_MODE(MANUAL);<
//TCPServer server = TCPServer(23);
TCPClient client;
#include <string.h>
#include <stdio.h>

void setup()
{
    Serial.begin(9600);
  // start listening for clients
    while(!Serial.available()) SPARK_WLAN_Loop();
  //  client.connect(serv,23);
    if (client.connect(serv, 80))
    {
        Serial.println("connected");
        client.println("We are all connected");
    }
    else
    {
        Serial.println("connection failed");
    }
}
void loop() {
    char emoncmspath[] = {'e', 'm', 'o', 'n', 'c', 'm', 's' };
    char apikey[] = {'3', 'b', '1', '7', '2', 'c', '8', '0', '6', '4', '6', '2', '0', 'd', '9', 'd', 'e', '6', 'd', 'c', 'b', '4', '5', '5', '0', 'b', '4', '9', 'd', '7', '3', 'c'};
    char csv[] = {'2', '0', '0'};
    char nodeid[] = {'1','5'};
    char slash [] = {'/'};
    char apititle [] = {'/','i','n','p','u','t','/','p','o','s','t','.','j','s','o','n','?','a','p','i','k','e','y','='};
    char nodetitle [] = {'&','n','o','d','e','='};
    char csvtitle [] = {'&','c','s','v','=','\0'};
    
    char all [8];
    memcpy(all, slash, 1);
    memcpy(&all[1], emoncmspath, 7);
    memcpy(&all[8], apititle, 24);
    memcpy(&all[32], apikey, 32);
    memcpy(&all[64], nodetitle, 6);
    memcpy(&all[70], nodeid, 2);
    memcpy(&all[72], csvtitle, 6);
    memcpy(&all[78], csv, 3);
    //all.trim();
    
    Serial.println(all);
    delay(1000);
    client.write(all);

} 

On both of my cores and I’m getting red lights on both. Clearly it’s a problem with my code, can anyone find it?

Thanks!

what flash sequence are you getting? is it SOS and 1 flash?

@OddieCAT, you defined “all” as char [8] but then use memcpy with references to &all[78]!! You are going out of bounds and causing a hard fault I bet. You should define char all[81] at least! :smile:

1 Like

Yes peekay, that’s what did it! I was trying to break the code earlier in the week and I had forgotten I left it there!

1 Like