Delay 60s, add colour per device

This commit is contained in:
Nico Schottelius 2016-09-15 09:48:53 +02:00
parent 06a61cbd6f
commit 1eb3683ae0

View file

@ -5,34 +5,78 @@
#define debugSerial SerialUSB #define debugSerial SerialUSB
#define loraSerial Serial1 #define loraSerial Serial1
/* The number of the device: 1,2,3,4 */
#define deviceNo 2
void BLUE() { void BLUE() {
digitalWrite(LED_RED, HIGH); digitalWrite(LED_RED, HIGH);
digitalWrite(LED_GREEN, HIGH); digitalWrite(LED_GREEN, HIGH);
digitalWrite(LED_BLUE, LOW); digitalWrite(LED_BLUE, LOW);
} }
void RED() {
digitalWrite(LED_RED, LOW);
digitalWrite(LED_GREEN, HIGH);
digitalWrite(LED_BLUE, HIGH);
}
void YELLOW() {
digitalWrite(LED_RED, LOW);
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_BLUE, HIGH);
}
void WHITE() {
digitalWrite(LED_RED, LOW);
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_BLUE, LOW);
}
void GREEN() {
digitalWrite(LED_RED, HIGH);
digitalWrite(LED_GREEN, LOW);
digitalWrite(LED_BLUE, HIGH);
}
void CLEAR() { void CLEAR() {
digitalWrite(LED_RED, HIGH); digitalWrite(LED_RED, HIGH);
digitalWrite(LED_GREEN, HIGH); digitalWrite(LED_GREEN, HIGH);
digitalWrite(LED_BLUE, HIGH); digitalWrite(LED_BLUE, HIGH);
} }
void blueBlink() { void blink(int length) {
switch(deviceNo) {
case 1:
BLUE(); BLUE();
delay(30); break;
case 2:
RED();
break;
case 3:
GREEN();
break;
case 4:
YELLOW();
break;
}
delay(length);
CLEAR(); CLEAR();
} }
// OTAA // OTAA
// Random numbers chosen: // Random numbers chosen + device id
uint8_t DevEUI[8] = { 0x9c, 0xd9, 0x0b, 0xb5, 0x2b, 0x6a, 0x1d, 0x01 }; uint8_t DevEUI[8] = { 0x9c, 0xd9, 0x0b, 0xb5, 0x2b, 0x6a, 0x1d, deviceNo };
uint8_t AppEUI[8] = { 0xd4, 0x16, 0xcd, 0x0b, 0x7b, 0xcf, 0x2d, 0x5c }; uint8_t AppEUI[8] = { 0xd4, 0x16, 0xcd, 0x0b, 0x7b, 0xcf, 0x2d, 0x5c };
uint8_t AppKey[16] = { 0xa9, 0xbc, 0x8b, 0x6a, 0x81, 0x75, 0xf6, 0x33, uint8_t AppKey[16] = { 0xa9, 0xbc, 0x8b, 0x6a, 0x81, 0x75, 0xf6, 0x33,
0xe0, 0xd6, 0x64, 0xd9, 0x2b, 0xcb, 0x13, 0x78 }; 0xe0, 0xd6, 0x64, 0xd9, 0x2b, 0xcb, 0x13, 0x78 };
uint8_t counter;
void setupLoRaOTAA(){ void setupLoRaOTAA(){
if (LoRaBee.initOTA(loraSerial, DevEUI, AppEUI, AppKey, true)) if (LoRaBee.initOTA(loraSerial, DevEUI, AppEUI, AppKey, true))
{ {
@ -68,7 +112,10 @@ void setup() {
// LoRaBee.setDiag(debugSerial); // optional // LoRaBee.setDiag(debugSerial); // optional
setupLED(); setupLED();
blueBlink(); blink(60);
/* used for blinking */
counter=0;
//connect to the LoRa Network //connect to the LoRa Network
setupLoRa(); setupLoRa();
@ -122,10 +169,19 @@ void sendPacket(String packet){
} }
void loop() { void loop() {
// put your main code here, to run repeatedly: // put your main code here, to run repeatedly:
String packet = "SODAQ"; String packet = "SODAQ";
sendPacket(packet);
blueBlink();
delay(5000); /* Blink long after sending packet */
if(counter >= 60) {
sendPacket(packet);
blink(500);
counter = 0;
} else {
blink(30);
counter++;
}
delay(1000);
} }