Created
July 11, 2014 15:45
-
-
Save dmiddlecamp/b2e39f6d48f33f39e16f to your computer and use it in GitHub Desktop.
turn a spark core cc3000 on/off every 45 seconds, give or take
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "application.h" | |
#include "spark_disable_wlan.h" | |
#include "spark_disable_cloud.h" | |
int state = 0; | |
int awake = 0; | |
unsigned int lastWakeup = 0; | |
//wakeup once a minute | |
unsigned int wakeupDelay = 60 * 1000; | |
unsigned int timeAwake = 15 * 1000; | |
void setup() { | |
pinMode(D0, OUTPUT); | |
lastWakeup = millis(); | |
} | |
void loop() { | |
unsigned int now = millis(); | |
if ((now - lastWakeup) >= wakeupDelay) { | |
lastWakeup = now; | |
awake = 1; | |
WiFi.on(); | |
Spark.connect(); | |
} | |
else if (awake && ((now - lastWakeup) >= timeAwake)) { | |
WiFi.off(); | |
awake = 0; | |
} | |
else if (awake && (WiFi.status() == WIFI_ON)) { | |
Spark.publish("awake", String(awake)); | |
} | |
//toggle once a second | |
state = !state; | |
digitalWrite(D0, (state) ? HIGH : LOW); | |
delay(1000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment