Hi,
After the build night last wednesday I got the feeling of building again with my spark so I did. However, it seems to fail to retrieve the system time
It connects to the cloud via Wifi no problem after manual claim.
My code uses the Spark.time function, does not work. Time is 1 jan 00:00:00 1970.
I tried flashing the CC3000 chip again, no succes.
Sometimes randomly it does retrieve the time properly, but very rare.
I’m guessing something in my code blocks it from retrieving the code, but what?
below is the code I use (it is a bit messy, needs cleaning )
// This #include statement was automatically added by the Spark IDE.
#include "SparkButton/SparkButton.h"
SparkButton klok = SparkButton();
int hour;
int minutes;
int fiveminutes;
int singleminutes;
int sync = 0; // TODO: RESYNC AFTER X TIME
int GMT = 1; //GMT time diff, use 1 for +1 and -1 for -1 GMT
int brightness = 50;
void setup() {
klok.begin();
Serial.begin(9600);
RGB.control(true);
RGB.color(0,0,0);
}
void loop() {
Serial.print(Time.timeStr());
klok.ledOff(hour);
hour = Time.hourFormat12();
hour += GMT;
minutes = Time.minute();
if (hour == 12||hour == 0)
{
RGB.color(0,brightness,0);
}
else
{
klok.ledOn(hour,0,brightness,0);
}
fiveminutes = convertmin(minutes);
singleminutes = minutes - (fiveminutes*5);
if (fiveminutes > 0 && singleminutes > 0 )
{
if (fiveminutes != hour)
{
do {
klok.ledOff(fiveminutes);
Delay(500);
for(int i = 0; i<singleminutes;i++)
{
Serial.print(Time.timeStr());
klok.ledOn(fiveminutes,brightness,0,brightness);
Delay(100);
klok.ledOff(fiveminutes);
Delay(200);
}
Delay(300);
klok.ledOn(fiveminutes,0,0,brightness);
Delay(5000);
} while (minutes == Time.minute());
klok.ledOff(fiveminutes);
}
else if (fiveminutes == hour)
{
do {
klok.ledOn(fiveminutes,0,brightness,0);
Delay(500);
for(int i = 0; i<singleminutes;i++)
{
Serial.print(Time.timeStr());
klok.ledOn(fiveminutes,brightness,brightness,brightness);
Delay(100);
klok.ledOn(fiveminutes,0,brightness,0);
Delay(200);
}
Delay(300);
klok.ledOn(fiveminutes,0,brightness,brightness);
Delay(5000);
} while (minutes == Time.minute());
klok.ledOn(fiveminutes,0,brightness,0);
}
}
else if (fiveminutes == 0 && singleminutes > 0)
{
if (hour != 1)
{
do {
for(int i = 0; i<singleminutes;i++)
RGB.color(0,0,0);
Delay(500);
{
Serial.print(Time.timeStr());
RGB.color(brightness,0,brightness);
Delay(100);
klok.ledOff(1);
Delay(200);
}
Delay(300);
RGB.color(0,0,brightness);
Delay(5000);
} while (minutes == Time.minute());
RGB.color(0,0,0);
}
else if (hour == 12)
{
do {
for(int i = 0; i<singleminutes;i++)
RGB.color(0,brightness,0);
Delay(500);
{
Serial.print(Time.timeStr());
RGB.color(brightness,brightness,brightness);
Delay(100);
RGB.color(0,brightness,0);
Delay(200);
}
Delay(300);
RGB.color(0,brightness,brightness);
Delay(5000);
} while (minutes == Time.minute());
klok.ledOn(1,0,brightness,0);
RGB.color(0,brightness,0);
}
}
else if (fiveminutes > 0 && singleminutes == 0)
{
if (hour != fiveminutes)
{
do {
klok.ledOn(fiveminutes,0,0,brightness);
} while (minutes == Time.minute());
}
else if (hour == fiveminutes)
{
do {
klok.ledOn(fiveminutes,0,brightness,brightness);
} while(minutes == Time.minute());
}
}
else if (fiveminutes == 0 && singleminutes == 0)
{
do{
Delay(1000); //nothing lol
}while(minutes == Time.minute());
}
}// end main loop
int convertmin(int input)
{
int temp = input/5;
if (input < 5){ return 0;}
if (temp >= 1 && temp <2)
{
temp = 1;
}
else if (temp >= 2 && temp <3)
{
temp = 2;
}
else if (temp >= 3 && temp <4)
{
temp = 3;
}
else if (temp >= 4 && temp <5)
{
temp = 4;
}
else if (temp >= 5 && temp <6)
{
temp = 5;
}
else if (temp >= 6 && temp <7)
{
temp = 6;
}
else if (temp >= 7 && temp <8)
{
temp = 7;
}
else if (temp >= 8 && temp <9)
{
temp = 8;
}
else if (temp >= 9 && temp <10)
{
temp = 9;
}
else if (temp >= 10 && temp <11)
{
temp = 10;
}
else if (temp >= 11 && temp <12)
{
temp = 11;
}
else temp = 0;
return temp;
}