@bko
Sorry for the delay in replying.
This is the code. It runs and posts successfully to my server, but when I do a web request to it, it flashes SOS in red and reboots.
#include “application.h”
#include “HttpClient/HttpClient.h”
unsigned int nextTime = 0; // Next time to contact the server
char message[60];
int loopcount = 0;
char pinStatus[64] = “NONE”;
HttpClient http;
http_request_t request;
http_response_t response;
http_header_t headers[] = {
{ “Content-Type”, “application/json” },
{ “User-agent”, “Particle HttpClient”},
{ “Accept” , “/”},
{ NULL, NULL } // NOTE: Always terminate headers will NULL
};
//------------------------------------------------------------------------------------
void setup() {
nextTime = millis() + 30000; // give some time before we start looping.
loopcount = 0;
sprintf(message, "");
request.body = message;
request.hostname = "www.sysweb.co.za";
request.port = 80;
pinMode(0, OUTPUT);
pinMode(1, OUTPUT);
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
// Cloud functions
Spark.function("fnrouter", fnRouter);
// Cloud variables
Spark.variable("pinStatus", &pinStatus, STRING);
// update the "pinStatus" global variable with the current pin statusses.
updateStatus();
}
void loop() {
// This is where I will poll for button press
///The next part of the loop only runs every 30 seconds
if (nextTime > millis()) {
return;
}
loopcount++; //this is to see how many times the loop runs before it crashes
String ppath = "";
ppath.concat("/Core.aspx?TestVer=12|loop:");
ppath.concat(String(loopcount));
request.path = ppath;
// Get request
http.get(request, response, headers);
nextTime = millis() + 30000;
}
//webhook function to call from jquery
int fnRouter(String command) {
command.trim();
command.toUpperCase();
if(command.equals("D0HIGH")) {digitalWrite(0, HIGH);}
if(command.equals("D1HIGH")) {digitalWrite(1, HIGH);}
if(command.equals("D2HIGH")) {digitalWrite(2, HIGH);}
if(command.equals("D3HIGH")) {digitalWrite(3, HIGH);}
if(command.equals("D0LOW")) {digitalWrite(0, LOW);}
if(command.equals("D1LOW")) {digitalWrite(1, LOW);}
if(command.equals("D2LOW")) {digitalWrite(2, LOW);}
if(command.equals("D3LOW")) {digitalWrite(3, LOW);}
updateStatus();
return 0;
}
//function to update the pinStatus variable used for web requests.
void updateStatus(){
int val0 = 0;
int val1 = 0;
int val2 = 0;
int val3 = 0;
val0 = digitalRead(D0); // read input value
val1 = digitalRead(D1); // read input value
val2 = digitalRead(D2); // read input value
val3 = digitalRead(D3); // read input value
String strPinStatus = "";
if (val0 == HIGH) { strPinStatus.concat("1|"); } else { strPinStatus.concat("0|"); }
if (val1 == HIGH) { strPinStatus.concat("1|"); } else { strPinStatus.concat("0|"); }
if (val2 == HIGH) { strPinStatus.concat("1|"); } else { strPinStatus.concat("0|"); }
if (val3 == HIGH) { strPinStatus.concat("1|"); } else { strPinStatus.concat("0|"); }
strPinStatus.toCharArray(pinStatus, 64);
}