Compare commits
No commits in common. "3109c1168e58780843a2117eb5e9513129a404aa" and "18a87d8098589d9ab9bc847c9fba745eac631896" have entirely different histories.
3109c1168e
...
18a87d8098
3 changed files with 13 additions and 98 deletions
|
@ -46,10 +46,8 @@ This repository contains the PlatformIO project with the mapper firmware. Copy c
|
|||
|
||||
If a Button is connected you can use the following functions:
|
||||
|
||||
* **Short press:** Schedule an imideate send, regardless of interval | In Setup Mode - cycle through Settings or Change Activated Setting
|
||||
* **Long Press (>1s):** Enter Setup Mode, Activate a Setting in Setup Mode
|
||||
|
||||
In Setup Mode a '>' in front of a Line identifies the selected option, a '>>' identifies an activated setting (can be changed by short press). Use long press to deactivate an activated setting
|
||||
* **Short press:** Schedule an imideate send, regardless of interval
|
||||
* **Long Press (>1s):** Enter Setup Mode, change interval with short press, use another long press to leave setup
|
||||
|
||||
## License
|
||||
|
||||
|
|
|
@ -1,13 +1,6 @@
|
|||
//*******************************************************************
|
||||
// LoRa Config - Put Your Keys Here! MSB Left for all three
|
||||
//*******************************************************************
|
||||
|
||||
// Primary Keyset, will be used on Startup
|
||||
unsigned char NwkSkey_1[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
unsigned char AppSkey_1[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
unsigned char DevAddr_1[4] = { 0x00, 0x00, 0x00, 0x00 };
|
||||
|
||||
// Secondary ABP Keyset, can be selected via Setup
|
||||
unsigned char NwkSkey_2[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
unsigned char AppSkey_2[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
unsigned char DevAddr_2[4] = { 0x00, 0x00, 0x00, 0x00 };
|
||||
unsigned char NwkSkey[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
unsigned char AppSkey[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
|
||||
unsigned char DevAddr[4] = { 0x00, 0x00, 0x00, 0x00 };
|
92
src/main.cpp
92
src/main.cpp
|
@ -3,7 +3,6 @@
|
|||
#include <avr/interrupt.h>
|
||||
#include <SPI.h>
|
||||
#include <Wire.h>
|
||||
#include <EEPROM.h>
|
||||
#include <LoRaWAN.h>
|
||||
|
||||
// OLED
|
||||
|
@ -27,20 +26,8 @@ enum Modes {
|
|||
M_SETUP
|
||||
};
|
||||
|
||||
enum Settings {
|
||||
S_NONE,
|
||||
S_INTERVAL,
|
||||
S_KEYSET,
|
||||
S_EXIT
|
||||
};
|
||||
|
||||
Modes amode = M_NORMAL; // Active Mode
|
||||
Modes omode = M_NORMAL; // Previous Mode
|
||||
Settings cset = S_INTERVAL; // Current Setting
|
||||
Settings aset = S_NONE; // Selected Setting
|
||||
|
||||
#define EEPROM_KEYSET_ADR 0
|
||||
#define EEPROM_INTERVAL_ADR 1
|
||||
|
||||
// LoRa
|
||||
#include "config.h" // Contains LoRa ABP Keys
|
||||
|
@ -48,12 +35,11 @@ Settings aset = S_NONE; // Selected Setting
|
|||
#define NSS PIN_PA5
|
||||
RFM95 rfm(DIO0, NSS);
|
||||
LoRaWAN lora = LoRaWAN(rfm);
|
||||
uint16_t Frame_Counter_Tx = 0x0001;
|
||||
uint16_t Frame_Counter_Tx = 0x0000;
|
||||
|
||||
// Some Status Variables
|
||||
uint8_t interval = 20; // Sending Interval in Settings
|
||||
uint8_t packets = 0; // Sent LoRa Packets
|
||||
uint8_t keyset = 1; // LoRa KeySet
|
||||
String statusmsg = "";
|
||||
|
||||
uint8_t loraBuffer[9]; // Lora Data Packet
|
||||
|
@ -74,40 +60,14 @@ uint16_t readSupplyVoltage() {
|
|||
return reading;
|
||||
}
|
||||
|
||||
void loraKeySetup(uint8_t keyset) {
|
||||
if (keyset == 1)
|
||||
lora.setKeys(NwkSkey_1, AppSkey_1, DevAddr_1);
|
||||
if (keyset == 2)
|
||||
lora.setKeys(NwkSkey_2, AppSkey_2, DevAddr_2);
|
||||
}
|
||||
|
||||
// Button Handler Function
|
||||
void handler(Button2& btn) {
|
||||
switch (btn.getClickType()) {
|
||||
case SINGLE_CLICK:
|
||||
if (amode == M_SETUP) {
|
||||
if (aset == S_INTERVAL) {
|
||||
interval = interval += 10;
|
||||
if (interval > 30)
|
||||
interval = 10;
|
||||
} else if (aset == S_KEYSET) {
|
||||
keyset = keyset + 1;
|
||||
if (keyset > 2)
|
||||
keyset = 1;
|
||||
loraKeySetup(keyset);
|
||||
} else {
|
||||
switch (cset) {
|
||||
case S_INTERVAL:
|
||||
cset = S_KEYSET;
|
||||
break;
|
||||
case S_KEYSET:
|
||||
cset = S_EXIT;
|
||||
break;
|
||||
case S_EXIT:
|
||||
cset = S_INTERVAL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
interval = interval += 10;
|
||||
if (interval > 40)
|
||||
interval = 10;
|
||||
} else if (amode == M_NORMAL) {
|
||||
statusmsg = "Adhoc Request";
|
||||
adhocsend = true;
|
||||
|
@ -117,19 +77,9 @@ void handler(Button2& btn) {
|
|||
switch (amode) {
|
||||
case M_NORMAL:
|
||||
amode = M_SETUP;
|
||||
cset = S_INTERVAL;
|
||||
break;
|
||||
case M_SETUP:
|
||||
if (cset == S_EXIT) {
|
||||
aset = S_NONE;
|
||||
amode = M_NORMAL;
|
||||
EEPROM.update(EEPROM_KEYSET_ADR, keyset);
|
||||
EEPROM.update(EEPROM_INTERVAL_ADR, interval);
|
||||
} else if (aset == S_NONE) {
|
||||
aset = cset;
|
||||
} else {
|
||||
aset = S_NONE;
|
||||
}
|
||||
amode = M_NORMAL;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
@ -152,25 +102,8 @@ void updateDisplay() {
|
|||
if (amode == M_SETUP) {
|
||||
oled.println ("<< SETUP >>");
|
||||
oled.println ("");
|
||||
char tmp = ' ';
|
||||
|
||||
tmp = (cset == S_INTERVAL) ? '>' : ' ';
|
||||
oled.print(tmp);
|
||||
tmp = (aset == S_INTERVAL) ? '>' : ' ';
|
||||
oled.print(tmp);
|
||||
oled.print("Interval: ");
|
||||
oled.println(interval);
|
||||
|
||||
tmp = (cset == S_KEYSET) ? '>' : ' ';
|
||||
oled.print(tmp);
|
||||
tmp = (aset == S_KEYSET) ? '>' : ' ';
|
||||
oled.print(tmp);
|
||||
oled.print("ABP KeySet: ");
|
||||
oled.println(keyset);
|
||||
tmp = (cset == S_EXIT) ? '>' : ' ';
|
||||
oled.print(tmp);
|
||||
oled.println(" Exit Setup");
|
||||
|
||||
} else if (amode == M_NORMAL) {
|
||||
if (hasFix) {
|
||||
if (hasFix != oldFix){
|
||||
|
@ -186,7 +119,7 @@ void updateDisplay() {
|
|||
oled.print("Int: ");
|
||||
oled.println(interval);
|
||||
oled.print("Packet: ");
|
||||
oled.println(packets);
|
||||
oled.println(Frame_Counter_Tx);
|
||||
oled.print("Alt: ");
|
||||
oled.println(buffer[3]);
|
||||
oled.print("Speed: ");
|
||||
|
@ -206,7 +139,7 @@ void updateDisplay() {
|
|||
oled.print("Int: ");
|
||||
oled.println(interval);
|
||||
oled.print("Packet: ");
|
||||
oled.println(packets);
|
||||
oled.println(Frame_Counter_Tx);
|
||||
oled.print("Bat: ");
|
||||
oled.println((float)readSupplyVoltage()/1000);
|
||||
}
|
||||
|
@ -233,17 +166,9 @@ void setup() {
|
|||
oled.setFlipMode(1);
|
||||
oled.clear();
|
||||
|
||||
// Get Settings from EEPROM
|
||||
|
||||
EEPROM.get(EEPROM_KEYSET_ADR, keyset);
|
||||
if (keyset > 2) keyset = 1;
|
||||
if (keyset < 1) keyset = 1;
|
||||
EEPROM.get(EEPROM_INTERVAL_ADR, interval);
|
||||
if (interval < 10 || interval > 30) interval = 20;
|
||||
|
||||
// Lora Initialization
|
||||
rfm.init();
|
||||
loraKeySetup(keyset);
|
||||
lora.setKeys(NwkSkey, AppSkey, DevAddr);
|
||||
}
|
||||
|
||||
// Main Loop
|
||||
|
@ -261,7 +186,6 @@ void loop() {
|
|||
|
||||
gps.buildPacket(loraBuffer);
|
||||
lora.Send_Data((unsigned char *)&loraBuffer, sizeof(loraBuffer), Frame_Counter_Tx, SF7BW125, 0x01);
|
||||
packets++;
|
||||
Frame_Counter_Tx++;
|
||||
lastmillis = millis();
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue