What i meant by the first one works and the other doesnt, is the first client connect is to my home theater PC to display the camera on the screen. the second one (pushing box) isnt working.
Some times they both dont connect but running them a second time they both connect but only the XBMC one works.
The core stays breathing Cyan the whole time, sometimes it looks like it gets a little bit cut off but then fades back in and out as per normal.
I have tried an online get request thing which works no worries and triggers the scenario… so im sure its something from the core side of things, probably just a timing issue.
Another little bug i noticed with the spark IDE is if i comment out the line
runXbmcScript(xbmcServer, xbmcPort, xbmcScript, xbmcLogon);
then it will compile ok and appear to flash ok… but the core will still be running the last firmware. i need to comment out the whole Void bit it calls to get it working if that makes sense?
Here is the whole code for reference… As soon as it connects to the cloud (when the D7 led comes on) i terminal in and push enter to start it talking 
#include "application.h"
int doorbell = D0; // Doorbell button connects to D0 on the core
unsigned long Lockout; // used to stop flooding servers
boolean DEBUG = true; // enable Debug
int LED = D7; // Built in LED
// XBMC Setup
char xbmcServer[] = "MyXBMCserver.com";
int xbmcPort = 80;
char xbmcScript[] = "/jsonrpc?request={%22jsonrpc%22:%222.0%22,%22method%22:%22Addons.ExecuteAddon%22,%22params%22:{%22addonid%22:%22script.securitycam%22},%22id%22:%221%22}}";
char xbmcLogon[] = "USERNAME:PASSWORD"; //Base64 encode Username:Password as one thing
// Pushing Box Setup
char serverName[] = "api.pushingbox.com";
char deviceID[] = "DeviceID";
void setup() {
pinMode(doorbell, INPUT_PULLUP); // other side of doorbell will connect to ground to pull low
Lockout = millis();
pinMode(LED, OUTPUT); // sets LED as output
if(DEBUG){
digitalWrite(LED,HIGH); // Light the onboard LED so you know it's time to open your Serial Terminal
Serial.begin(9600);
while(!Serial.available()); // wait here for user to press ENTER in Serial Terminal
digitalWrite(LED,LOW);
Serial.print("SSID: ");
Serial.println(Network.SSID());
Serial.print("Core IP: ");
Serial.println(Network.localIP());
Serial.print("Gateway: ");
Serial.println(Network.gatewayIP());
Serial.print("Mask: ");
Serial.println(Network.subnetMask());
Serial.print("WiFi RSSI: ");
Serial.println(Network.RSSI());
}
}
void loop() {
if (millis() >= Lockout){ // check how long its been since last pushed
if(digitalRead(doorbell) == LOW) { //read the doorbell button
delay(50);
if(digitalRead(doorbell) == LOW) { // debounce check again to make sure
Lockout = millis() + 15000; // set up the lockout period 15 seconds before it will run again
runXbmcScript(xbmcServer, xbmcPort, xbmcScript, xbmcLogon); // opens up a script in xbmc that displays an ip camera
sendToPushingBox(serverName, deviceID); // sends push notification to mobile phone or sends email using pushingbox
}
}
}
}
void runXbmcScript(char *hostname, int port, char *url, char *xbmclogon) {
TCPClient client;
char line[255];
client.stop();
digitalWrite(LED, HIGH); // sets the LED on
if(DEBUG){Serial.print("connecting... ");}
if (client.connect(hostname, port)) {
if(DEBUG){
Serial.print("connected to ");
Serial.println(hostname);
}
delay(200);
strcpy(line, "GET ");
strcat(line, url);
strcat(line, " HTTP/1.1\r\n");
client.print(line);
if(DEBUG){Serial.print(line);}
strcpy(line, "Host: ");
strcat(line, hostname);
strcat(line, "\r\n");
client.print(line);
if(DEBUG){Serial.print(line);}
strcpy(line, "Authorization: Basic ");
strcat(line, xbmclogon);
strcat(line, "\r\n");
strcat(line, "\r\n");
client.print(line);
if(DEBUG){Serial.print(line);}
delay(500);
client.flush();
client.println("Connection: close");
client.flush();
delay(200);
if(DEBUG){Serial.println("closing...");}
client.stop();
digitalWrite(LED, LOW); // sets the LED off
delay(1000);
}
else{
digitalWrite(LED, HIGH); // sets the LED on. If always on, last connexion was failed
if(DEBUG){Serial.println("connection failed");}
}
}
void sendToPushingBox(char *serverName, char *devid) {
TCPClient client;
char line[255];
client.stop();
digitalWrite(LED, HIGH); // sets the LED on
if(DEBUG){Serial.print("connecting... ");}
if (client.connect(serverName, 80)) {
if(DEBUG){
Serial.print("connected to ");
Serial.println(serverName);
}
delay(500);
strcpy(line, "GET /pushingbox?devid=");
strcat(line, devid);
strcat(line, " HTTP/1.0\r\n");
client.print(line);
if(DEBUG){Serial.print(line);}
strcpy(line, "Host: ");
strcat(line, serverName);
strcat(line, "\r\n");
client.print(line);
if(DEBUG){Serial.print(line);}
strcpy(line, "User-Agent: Spark\r\n");
strcat(line, "Content-length: 0\r\n\r\n");
client.print(line);
if(DEBUG){Serial.print(line);}
delay(500);
//client.println("Connection: close");
//delay(400);
client.flush();
delay(200);
if(DEBUG){Serial.println("closing...");}
client.stop();
digitalWrite(LED, LOW); // sets the LED off
}
else{
digitalWrite(LED, HIGH); // sets the LED on. If always on, last connexion was failed
if(DEBUG){Serial.println("connection failed");}
}
}