From time to time, my photon will flash green for a couple hours and then go back to cyan. It does not matter how close it is to my router…
THANK YOU IN ADVANCE FOR ANY HELP!!! IT IS DRIVING ME CRAZY!!!
here is the code-
String lastrun = "not yet";
String whatsup ="";
String xml_result;
boolean sleeptime = false;
String whatwasup = "";
String whatwasb4 = "";
boolean requested = false;
String ender =", Q"; //adds at the end of the meeitn
String ender2 =", Q ";
int ErrorCount =0;
boolean Dreben= false; // holds value of if things got messed up and the Arduino did not find a Q
String commander = ""; // holds value of last command
int Type = 5; // holds value of which function was called
void setup() {
String data = String(10);
Time.zone(-6);
Particle.subscribe("hook-response/google_doc_webhook", myHandler, MY_DEVICES);
Particle.variable("XML_UPDATE", xml_result);
Particle.variable("timer", lastrun);
Particle.variable("whatsup", whatsup);
Particle.variable("whatwasup", whatwasup);
Particle.variable("whatwasb4", whatwasb4);
Particle.variable("Dreben", Dreben);
Spark.function("sendData", sendData);
Spark.function("sendLocation", sendLocation);
Spark.function("sendSteps", sendSteps);
Spark.function("sendReset", sendReset);
Spark.function("sendXML", sendXML);
Serial.begin(9600);
Serial1.begin(9600);
int ttime = Time.hour();
Particle.publish("google_doc_webhook", data, PRIVATE);
lastrun= String(ttime);
}
void loop() {
String data = String(10);
if (Dreben == true && ErrorCount<5)
{
ErrorCount ++;
ender = ender + "reseted X";
delay(7000);
switch (Type)
{
case 1:
sendReseter(commander);
break;
case 2:
sendLocationer (commander);
break;
case 3:
sendStepser (commander);
break;
case 5:
sendXMLer(commander);
break;
}
delay(100);
whatsup = "Dreben fewer than 5 but really " + ErrorCount;
}
else if (Dreben == true)
{
whatsup = "This had an error x " + ErrorCount;
ErrorCount = 0;
Dreben = false;
ender =", Q";
ohno();
}
if(Serial1.available())
{
String holder = Serial1.readString();
if (holder.indexOf("Dreben") > 0)
{
holder=holder.indexOf("Dreben");
Dreben = true;
delay(1000);
}
else
{
(Dreben = false);
ender =", Q";
}
whatwasb4 = whatwasup;
whatwasup = whatsup;
whatsup = holder;
// Serial1.flush();
}
Particle.publish("google_doc_webhook", data, PRIVATE);
int ttime = Time.hour();
if ((( ttime % 2) == 0) && !requested)
{
Particle.publish("google_doc_webhook", data, PRIVATE);
requested = true;
lastrun= String(ttime);
}
if (!(( ttime % 2) == 0) && requested)
{
Particle.publish("google_doc_webhook", data, PRIVATE);
requested = false;
lastrun= String(ttime);
}
/*
if ((ttime > 8) && (ttime < 18) ){
tomorrow=false;
}
else
{
tomorrow = true;
}
*/
//don't show if it is late
if ((ttime > 7) && (ttime < 20) ){
sleeptime=false;
}
else
{
sleeptime = true;
}
}
int sendReset(String command) {
// Serial.print("INCOMING: ");
//Serial.println(command);
commander = command;
Type = 1;
command = "RRRRRRR" + command + ender;
Serial1.println(command);
return 1;
}
int sendLocation(String command) {
// Serial.print("INCOMING: ");
// Serial.println(command);
commander = command;
Type = 2;
command = command + ",0" + ender2;
Serial1.println(command);
return 1;
}
int sendSteps(String command) {
commander = command;
Type = 3;
command = command + ",4" + ender;
Serial1.println(command);
return 1;
}
int sendData(String command) {
commander =command;
Type = 4;
Serial1.println(command);
return 1;
}
int sendXML(String command) {
commander = command;
Type = 5;
xml_result="PPPPPP" + xml_result + ender;
Serial1.print(xml_result);
return 1;
}
void myHandler(const char *event, const char *data)
{
// Handle the integration response
xml_result = String(data);
Particle.publish("XML Result", xml_result, PUBLIC);
xml_result = tryExtractString(0, xml_result, "thread", "Stepper");
}
//
//
//
String tryExtractString(int matchNum, String str, const char* start, const char* end) {
if (str == NULL) {
return "";
}
int count = 0;
int lastIdx = 0;
while (count <= matchNum) {
int idx = str.indexOf(start, lastIdx);
int endIdx = str.indexOf(end, lastIdx + idx + strlen(start));
lastIdx = endIdx;
if (count == matchNum) {
return str.substring(idx + strlen(start), endIdx);
}
count++;
}
}
void sendReseter(String command) {
commander = command;
Type = 1;
command = "RRRRRRR" + command + ender;
Serial1.println(command);
}
void sendLocationer (String command) {
commander = command;
Type = 2;
command = command + ",0" + ender2;
Serial1.println(command);
}
void sendStepser (String command) {
commander = command;
Type = 3;
command = command + ",4" + ender;
Serial1.println(command);
}
void sendXMLer(String command) {
commander = command;
Type = 5;
xml_result="PPPPPP" + xml_result + ender;
Serial1.print(xml_result);
}
void ohno()
{
String Stringer="PPPPPP" + ender;
Serial1.print(Stringer);
}