Last active
December 2, 2019 19:46
-
-
Save vlazar-/ae08cd672e42b9cf67425751c1fe34a6 to your computer and use it in GitHub Desktop.
MKR1000 Wake Up
This file contains hidden or 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
void runApplication() { | |
heartbeat(); | |
WiFi.noLowPowerMode(); | |
while(WiFi.status() != WL_CONNECTED){ | |
WiFi.begin(ssid, pass); | |
heartbeat(); | |
} | |
char buff[10]; | |
char* msg = ltoa(WiFi.RSSI(), buff, 10); | |
displayMessage(msg); | |
WiFi.end(); | |
} |
This file contains hidden or 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
void runApplication() { | |
heartbeat(); | |
WiFi.noLowPowerMode(); | |
while(WiFi.status() != WL_CONNECTED){ | |
WiFi.begin(ssid, pass); | |
heartbeat(); | |
} | |
char buff[10]; | |
char* msg = ltoa(WiFi.RSSI(), buff, 10); | |
displayMessage(msg); | |
executeGet(IPAddress(185,158,80,20), "api.hnb.hr", "/tecajn/v1?valuta=EUR"); | |
WiFi.end(); | |
} |
This file contains hidden or 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
void heartbeat(){ | |
digitalWrite(LED_BUILTIN, HIGH); | |
delay(100); | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(500); | |
digitalWrite(LED_BUILTIN, HIGH); | |
delay(100); | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(500); | |
} | |
void displayMessage(String msg){ | |
Serial.println(msg); | |
} |
This file contains hidden or 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
void heartbeat(){ | |
digitalWrite(LED_BUILTIN, HIGH); | |
delay(100); | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(500); | |
digitalWrite(LED_BUILTIN, HIGH); | |
delay(100); | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(500); | |
} | |
void displayMessage(String msg){ | |
Serial.println(msg); | |
} | |
void executeGet(IPAddress ip, String host, String url){ | |
if (client.connect(ip, 80)) { | |
Serial.println("### Connected"); | |
client.println("GET " + url); | |
client.println("Host: " + host); | |
client.println("Connection: close"); | |
client.println(); | |
} | |
Serial.println("###"); | |
while (client.available()) { | |
char c = client.read(); | |
Serial.write(c); | |
} | |
if (!client.connected()) { | |
Serial.println(); | |
while (true); | |
} | |
} |
This file contains hidden or 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 <SPI.h> | |
#include <WiFi101.h> | |
#include <RTCZero.h> | |
const byte year = 2019; | |
const byte month = 12; | |
const byte day = 2; | |
byte wakeupHours = 0; | |
byte wakeupMinutes = 0; | |
byte wakeupSeconds = 5; | |
const String ssid = ""; | |
const String pass = ""; | |
RTCZero rtc; | |
WiFiClient client; | |
bool alarm = false; | |
void triggerAlarm(){ | |
alarm = true; | |
} | |
void setup() { | |
pinMode(LED_BUILTIN, OUTPUT); | |
digitalWrite(LED_BUILTIN, LOW); | |
rtc.begin(); | |
rtc.setDate(day, month, year); | |
rtc.setTime(0,0,0); | |
rtc.setAlarmTime(wakeupHours, wakeupMinutes, wakeupSeconds); | |
rtc.enableAlarm(rtc.MATCH_HHMMSS); | |
rtc.attachInterrupt(triggerAlarm); | |
} | |
void loop() { | |
if(alarm){ | |
alarm = false; | |
runApplication(); | |
rtc.setTime(0,0,0); | |
rtc.setAlarmTime(wakeupHours, wakeupMinutes, wakeupSeconds); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment