I want to use my Core to monitor my fish tank and some other temperatures etc.
I do not want to use the automatic mode because the WiFi is rather unstable and drops connection every few minutes. This makes the core go offline and stop the code, turning off my led strip inside the fishtank, leaving the fish in the dark
So I tried to use it in manual mode and only open connection to publish some temperature or status, such as it dimming the lights. However, it does not connect to WiFi or even turn on the ledstrip, it is just dead. It seems like it continues to reboot, first the RGB led is white for a second, then it flashes green for a bit and then it just dies and restarts after 10 seconds.
Here is the code I am using at the moment:
// This #include statement was automatically added by the Spark IDE.
#include "SparkButton/SparkButton.h"
SYSTEM_MODE(MANUAL);
int awake = 1;
int asleep = 0;
SparkButton b = SparkButton();
void setup() {
Spark.connect();
b.begin();
RGB.control(true);
pinMode(A0,OUTPUT);
Spark.syncTime();
Time.zone(+1);
Spark.publish("Status","back online at " + Time.timeStr());
}
void loop() {
if (Time.weekday() > 1 && Time.weekday() < 7)
{
if ((Time.hour() >= 10 || b.allButtonsOff() == 0) && awake == 0 && Time.hour() < 23)
{
if (!Spark.connected()) Spark.connect();
if (Spark.connected())
{
Spark.process();
Spark.publish("Status","awakening at " + Time.timeStr());
}
awake = 1;
asleep = 0;
RGB.color(10,0,0);
for (int i = 0; i < 200; i++)
{
analogWrite(A0,i);
myDelay(7060);
if (i == 200)
{
if (!Spark.connected()) Spark.connect();
if (Spark.connected())
{
Spark.process();
Spark.publish("Status","awake at " + Time.timeStr());
}
}
}
}
}
else
{
if (Time.hour() >= 10 && awake == 0 && Time.hour() < 23)
{
if (!Spark.connected()) Spark.connect();
if (Spark.connected())
{
Spark.process();
Spark.publish("Status","awakening at " + Time.timeStr());
}
awake = 1;
asleep = 0;
RGB.color(10,0,0);
for (int i = 0; i < 200; i++)
{
analogWrite(A0,i);
myDelay(7060);
if (i == 200)
{
if (!Spark.connected()) Spark.connect();
if (Spark.connected())
{
Spark.process();
Spark.publish("Status","awake at " + Time.timeStr());
}
}
}
}
}
if (awake == 1)
{
analogWrite(A0,200);
myDelay(60000);
RGB.color(10,10,10);
if (!Spark.connected()) Spark.connect();
if (Spark.connected())
{
Spark.process();
Spark.publish("Awake","awake at " + Time.timeStr());
}
}
if (Time.hour() >= 23 && asleep == 0)
{
asleep = 1;
awake = 0;
RGB.color(0,0,10);
if (!Spark.connected()) Spark.connect();
if (Spark.connected())
{
Spark.process();
Spark.publish("Status","sleepy at " + Time.timeStr());
}
for (int i = 200; i > -1; i--)
{
analogWrite(A0,i);
myDelay(7060);
if (i == 0)
{
if (!Spark.connected()) Spark.connect();
if (Spark.connected())
{
Spark.process();
Spark.publish("Status","asleep at " + Time.timeStr());
}
}
}
Spark.syncTime();
}
if (asleep == 1)
{
analogWrite(A0,0);
RGB.color(0,0,0);
if (!Spark.connected()) Spark.connect();
if (Spark.connected())
{
Spark.process();
Spark.publish("Asleep","Asleep at " + Time.timeStr());
}
myDelay(60000);
}
}
void myDelay(unsigned long duration)
{
unsigned long start = millis();
while (millis() - start <= duration)
{
Spark.process();
}
}
any help would be greatly appreciated