current working changes
This commit is contained in:
parent
23d27d7e2d
commit
2c146ff224
11
Makefile
11
Makefile
@ -17,6 +17,7 @@ CFLAGS?=-Datmega328p\
|
||||
-DARDUINO=200\
|
||||
-DARDUINO_AVR_NANO\
|
||||
-DARDUINO_ARCH_AVR\
|
||||
-std=c++11\
|
||||
-Os\
|
||||
-ffunction-sections\
|
||||
-fdata-sections\
|
||||
@ -59,9 +60,9 @@ SRC_FILES?=./$(ARDUINO_DIR)/cores/arduino/main.cpp\
|
||||
./$(NANOPB_DIR)/pb_common.c\
|
||||
./gateway/message.pb.c
|
||||
|
||||
build: $(OUT)$(NAME).hex
|
||||
build: $(OUT)$(NAME)
|
||||
|
||||
$(OUT)$(NAME).hex: $(OUT)$(NAME).elf
|
||||
$(OUT)$(NAME): $(OUT)$(NAME).elf
|
||||
$(OBJCOPY) -R .eeprom -O ihex $(OUT)$(NAME).elf $(OUT)$(NAME).hex
|
||||
$(OUT)eep.hex: $(OUT)$(NAME).elf
|
||||
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $(OUT)$(NAME).elf $(OUT)eep.hex
|
||||
@ -70,13 +71,17 @@ $(OUT)$(NAME).elf: protobuf bin
|
||||
|
||||
protobuf:
|
||||
mkdir -p protobuf/gateway
|
||||
python external/nanopb/generator/nanopb_generator.py gateway/message.proto -D protobuf
|
||||
python3 external/nanopb/generator/nanopb_generator.py gateway/message.proto -D protobuf
|
||||
|
||||
bin:
|
||||
mkdir bin
|
||||
|
||||
flash:
|
||||
avrdude -v -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:$(OUT)$(NAME).hex:i
|
||||
|
||||
stop:
|
||||
avrdude -v -patmega328p -carduino -P/dev/ttyUSB0 -b115200 -D -Uflash:w:nothing.hex:i
|
||||
|
||||
clean:
|
||||
rm -r protobuf
|
||||
rm -r bin
|
||||
|
9
README.md
Normal file
9
README.md
Normal file
@ -0,0 +1,9 @@
|
||||
# Dependencies
|
||||
|
||||
- python3-protobuf
|
||||
- protobuf
|
||||
- protobuf-c
|
||||
|
||||
# Python3 dependencies
|
||||
- protobuf
|
||||
- grpcio-tools
|
123
collar.cpp
123
collar.cpp
@ -14,53 +14,19 @@ const long interval = 5000;
|
||||
float lat = 0;
|
||||
float lng = 0;
|
||||
|
||||
bool sending = false;
|
||||
|
||||
TinyGPSPlus gps;
|
||||
|
||||
SoftwareSerial ss(6, 7);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
ss.begin(9600);
|
||||
typedef struct lora_status_s {
|
||||
int sleep;
|
||||
} lora_status_t;
|
||||
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("LoRa Transceiver");
|
||||
|
||||
if (!LoRa.begin(915E6)) {
|
||||
Serial.println("Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(7);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
int packetSize = LoRa.parsePacket();
|
||||
if (packetSize) {
|
||||
Serial.print("Received Packet: ");
|
||||
while (LoRa.available()) {
|
||||
Serial.print((char) LoRa.read());
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
if (ss.available() > 0)
|
||||
gps.encode(ss.read());
|
||||
|
||||
unsigned long currentMillis = millis();
|
||||
if (currentMillis - previousMillis >= interval) {
|
||||
previousMillis = currentMillis;
|
||||
|
||||
// Gather GPS data
|
||||
if (gps.location.isValid()) {
|
||||
Serial.println("Valid GPS");
|
||||
lat = gps.location.lat();
|
||||
lng = gps.location.lng();
|
||||
} else {
|
||||
lat = 0;
|
||||
lng = 0;
|
||||
}
|
||||
static lora_status_t lora_status;
|
||||
|
||||
void transmitLora() {
|
||||
// Encode as protobuf packet
|
||||
if (lat && lng) {
|
||||
uint8_t buffer[50] = {0};
|
||||
@ -85,8 +51,81 @@ void loop() {
|
||||
LoRa.print((char *) buffer);
|
||||
LoRa.endPacket();
|
||||
|
||||
}
|
||||
}
|
||||
void updateGPS() {
|
||||
// Gather GPS data
|
||||
if (gps.location.isValid()) {
|
||||
lat = gps.location.lat();
|
||||
lng = gps.location.lng();
|
||||
} else {
|
||||
Serial.println("GPS has not yet initialized");
|
||||
lat = 0;
|
||||
lng = 0;
|
||||
}
|
||||
}
|
||||
ISR(TIMER1_OVF_vect) {
|
||||
// handle timer overflow interrupt at 1 per second
|
||||
updateGPS();
|
||||
if(!gps.location.isValid()) {
|
||||
Serial.println("Seeking GPS");
|
||||
}
|
||||
if(sending && gps.location.isValid()) {
|
||||
if(lora_status.sleep) {
|
||||
}
|
||||
transmitLora();
|
||||
}
|
||||
}
|
||||
void initialize_timer() {
|
||||
TCCR1A = 0;
|
||||
TCCR1B = 0;
|
||||
TCNT1 = 34286; // timer preload
|
||||
TCCR1B |= (1<<CS12); // prescale: 256 bits
|
||||
TIMSK1 |= (1<<TOIE1); // overflow interrupt
|
||||
interrupts();
|
||||
}
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
ss.begin(9600);
|
||||
|
||||
while (!Serial);
|
||||
|
||||
Serial.println("LoRa Transceiver");
|
||||
|
||||
if (!LoRa.begin(915E6)) {
|
||||
Serial.println("Starting LoRa failed!");
|
||||
while (1);
|
||||
}
|
||||
LoRa.setSpreadingFactor(7);
|
||||
|
||||
lora_status.sleep = 1;
|
||||
//lora.sleep();
|
||||
|
||||
initialize_timer();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
/* Get user input
|
||||
*/
|
||||
if(Serial.available()) {
|
||||
char n = Serial.read();
|
||||
if(n=='p') {
|
||||
sending ? Serial.println("Sending is: disabled") : Serial.println("Sending is: enabled");
|
||||
sending = !sending;
|
||||
} else {
|
||||
Serial.println("Type the letter 'p' to toggle sending");
|
||||
}
|
||||
}
|
||||
/* GPS data recieved */
|
||||
while (ss.available() > 0) {
|
||||
gps.encode(ss.read());
|
||||
}
|
||||
/* Lora data recieved */
|
||||
int packetSize = LoRa.parsePacket();
|
||||
if (packetSize) {
|
||||
Serial.print("Received Packet: ");
|
||||
while (LoRa.available()) {
|
||||
Serial.print((char) LoRa.read());
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
|
2
generatetags.sh
Executable file
2
generatetags.sh
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/bash
|
||||
ctags -e -R --append ./
|
137
nothing.hex
Normal file
137
nothing.hex
Normal file
@ -0,0 +1,137 @@
|
||||
:100000000C9435000C945D000C945D000C945D0024
|
||||
:100010000C945D000C945D000C945D000C945D00EC
|
||||
:100020000C945D000C945D000C945D000C945D00DC
|
||||
:100030000C945D000C945D000C945D000C945D00CC
|
||||
:100040000C94E9010C945D000C94B7010C9491019F
|
||||
:100050000C945D000C945D000C945D000C945D00AC
|
||||
:100060000C945D000C945D00EB0211241FBECFEFD9
|
||||
:10007000D8E0DEBFCDBF11E0A0E0B1E0E0E4F6E003
|
||||
:1000800002C005900D92AE31B107D9F721E0AEE183
|
||||
:10009000B1E001C01D92A43CB207E1F710E0C5E356
|
||||
:1000A000D0E004C02197FE010E941803C433D10799
|
||||
:1000B000C9F70E9433020C941E030C940000AF9207
|
||||
:1000C000BF92CF92DF92EF92FF920F931F93CF9345
|
||||
:1000D000DF936C017B018B01040F151FEB015E01A7
|
||||
:1000E000AE18BF08C017D10759F06991D601ED913C
|
||||
:1000F000FC910190F081E02DC6010995892B79F7DB
|
||||
:10010000C501DF91CF911F910F91FF90EF90DF908C
|
||||
:10011000CF90BF90AF900895FC01538D448D252F53
|
||||
:1001200030E0842F90E0821B930B541710F0CF9691
|
||||
:10013000089501970895FC01918D828D981761F0C3
|
||||
:10014000A28DAE0FBF2FB11D5D968C91928D9F5FDA
|
||||
:100150009F73928F90E008958FEF9FEF0895FC01B9
|
||||
:10016000918D828D981731F0828DE80FF11D858D6C
|
||||
:1001700090E008958FEF9FEF0895FC01918D228DFF
|
||||
:10018000892F90E0805C9F4F821B91098F73992784
|
||||
:10019000089587E291E00E94BD0021E0892B09F4D7
|
||||
:1001A00020E0822F089580E090E0892B29F00E94C2
|
||||
:1001B000C90081110C9400000895FC01A48DA80FC2
|
||||
:1001C000B92FB11DA35ABF4F2C91848D90E0019699
|
||||
:1001D0008F739927848FA689B7892C93A089B189B9
|
||||
:1001E0008C91837080648C93938D848D981306C05A
|
||||
:1001F0000288F389E02D80818F7D80830895EF92BE
|
||||
:10020000FF920F931F93CF93DF93EC0181E0888FD0
|
||||
:100210009B8D8C8D98131AC0E889F989808185FFA0
|
||||
:1002200015C09FB7F894EE89FF896083E889F98942
|
||||
:1002300080818370806480839FBF81E090E0DF9144
|
||||
:10024000CF911F910F91FF90EF900895F62E0B8D97
|
||||
:1002500010E00F5F1F4F0F731127E02E8C8D8E1152
|
||||
:100260000CC00FB607FCFACFE889F989808185FFB9
|
||||
:10027000F5CFCE010E94DD00F1CFEB8DEC0FFD2F0D
|
||||
:10028000F11DE35AFF4FF0829FB7F8940B8FEA8974
|
||||
:10029000FB8980818062CFCFCF93DF93EC01888D83
|
||||
:1002A0008823B9F0AA89BB89E889F9898C9185FDF1
|
||||
:1002B00003C0808186FD0DC00FB607FCF7CF8C917F
|
||||
:1002C00085FFF2CF808185FFEDCFCE010E94DD005A
|
||||
:1002D000E9CFDF91CF9108953FB7F8948091230142
|
||||
:1002E00090912401A0912501B091260126B5A89BEB
|
||||
:1002F00005C02F3F19F00196A11DB11D3FBFBA2FB8
|
||||
:10030000A92F982F8827BC01CD01620F711D811D77
|
||||
:10031000911D42E0660F771F881F991F4A95D1F7FC
|
||||
:1003200008951F920F920FB60F9211242F933F93AF
|
||||
:100330004F935F936F937F938F939F93AF93BF93ED
|
||||
:10034000EF93FF9387E291E00E94DD00FF91EF9130
|
||||
:10035000BF91AF919F918F917F916F915F914F91DD
|
||||
:100360003F912F910F900FBE0F901F9018951F92E5
|
||||
:100370000F920FB60F9211242F938F939F93EF93A9
|
||||
:10038000FF93E0913701F09138018081E0913D01C8
|
||||
:10039000F0913E0182FD1BC09081809140018F5FF2
|
||||
:1003A0008F7320914101821741F0E0914001F0E00C
|
||||
:1003B000E95DFE4F958F80934001FF91EF919F91F2
|
||||
:1003C0008F912F910F900FBE0F901F9018958081E5
|
||||
:1003D000F4CF1F920F920FB60F9211242F933F93D9
|
||||
:1003E0008F939F93AF93BF9380911F0190912001B2
|
||||
:1003F000A0912101B091220130911E0123E0230F31
|
||||
:100400002D3758F50196A11DB11D20931E01809333
|
||||
:100410001F0190932001A0932101B09322018091AC
|
||||
:10042000230190912401A0912501B091260101960C
|
||||
:10043000A11DB11D8093230190932401A093250158
|
||||
:10044000B0932601BF91AF919F918F913F912F91D2
|
||||
:100450000F900FBE0F901F90189526E8230F02965D
|
||||
:10046000A11DB11DD2CF789484B5826084BD84B5BE
|
||||
:10047000816084BD85B5826085BD85B5816085BD9F
|
||||
:1004800080916E00816080936E0010928100809157
|
||||
:1004900081008260809381008091810081608093DF
|
||||
:1004A0008100809180008160809380008091B10004
|
||||
:1004B00084608093B1008091B00081608093B0002F
|
||||
:1004C00080917A00846080937A0080917A008260C3
|
||||
:1004D00080937A0080917A00816080937A00809185
|
||||
:1004E0007A00806880937A001092C100E091370111
|
||||
:1004F000F091380182E08083E0913301F091340182
|
||||
:100500001082E0913501F09136018FEC80831092DA
|
||||
:100510003F01E0913B01F0913C0186E08083E09156
|
||||
:100520003901F0913A01808180618083E091390145
|
||||
:10053000F0913A01808188608083E0913901F091E7
|
||||
:100540003A01808180688083E0913901F0913A011D
|
||||
:1005500080818F7D8083C0E0D0E047E050E062E1A1
|
||||
:1005600071E087E291E00E945F0042E050E06AE1C2
|
||||
:1005700071E087E291E00E945F000E946C014B01F4
|
||||
:100580005C0188EEC82E83E0D82EE12CF12C0E946D
|
||||
:100590006C01681979098A099B09683E73408105D5
|
||||
:1005A0009105A8F321E0C21AD108E108F10888EE0C
|
||||
:1005B000880E83E0981EA11CB11CC114D104E10473
|
||||
:1005C000F10429F7209749F20E94C900882329F2F3
|
||||
:1005D0000E940000C2CFE7E2F1E01382128288EEAF
|
||||
:1005E00093E0A0E0B0E084839583A683B78384E0A2
|
||||
:1005F00091E09183808385EC90E09587848784ECFB
|
||||
:1006000090E09787868780EC90E0918B808B81ECDF
|
||||
:1006100090E0938B828B82EC90E0958B848B86ECC0
|
||||
:1006200090E0978B868B118E128E138E148E089508
|
||||
:10063000EE0FFF1F0590F491E02D0994F894FFCF81
|
||||
:1006400000000000FF005F008C004C01BD009B001B
|
||||
:0E065000AF004E4F5448494E47000D0A0000BF
|
||||
:107E0000112484B714BE81FFF0D085E080938100F7
|
||||
:107E100082E08093C00088E18093C10086E0809377
|
||||
:107E2000C20080E18093C4008EE0C9D0259A86E02C
|
||||
:107E300020E33CEF91E0309385002093840096BBD3
|
||||
:107E4000B09BFECF1D9AA8958150A9F7CC24DD24C4
|
||||
:107E500088248394B5E0AB2EA1E19A2EF3E0BF2EE7
|
||||
:107E6000A2D0813461F49FD0082FAFD0023811F036
|
||||
:107E7000013811F484E001C083E08DD089C08234E0
|
||||
:107E800011F484E103C0853419F485E0A6D080C0E4
|
||||
:107E9000853579F488D0E82EFF2485D0082F10E0AE
|
||||
:107EA000102F00270E291F29000F111F8ED06801E7
|
||||
:107EB0006FC0863521F484E090D080E0DECF843638
|
||||
:107EC00009F040C070D06FD0082F6DD080E0C81688
|
||||
:107ED00080E7D80618F4F601B7BEE895C0E0D1E017
|
||||
:107EE00062D089930C17E1F7F0E0CF16F0E7DF06D8
|
||||
:107EF00018F0F601B7BEE89568D007B600FCFDCFD4
|
||||
:107F0000A601A0E0B1E02C9130E011968C91119780
|
||||
:107F100090E0982F8827822B932B1296FA010C0160
|
||||
:107F200087BEE89511244E5F5F4FF1E0A038BF0790
|
||||
:107F300051F7F601A7BEE89507B600FCFDCF97BE46
|
||||
:107F4000E89526C08437B1F42ED02DD0F82E2BD052
|
||||
:107F50003CD0F601EF2C8F010F5F1F4F84911BD097
|
||||
:107F6000EA94F801C1F70894C11CD11CFA94CF0C13
|
||||
:107F7000D11C0EC0853739F428D08EE10CD085E9AC
|
||||
:107F80000AD08FE07ACF813511F488E018D01DD067
|
||||
:107F900080E101D065CF982F8091C00085FFFCCF94
|
||||
:107FA0009093C60008958091C00087FFFCCF809118
|
||||
:107FB000C00084FD01C0A8958091C6000895E0E648
|
||||
:107FC000F0E098E1908380830895EDDF803219F02E
|
||||
:107FD00088E0F5DFFFCF84E1DECF1F93182FE3DFCA
|
||||
:107FE0001150E9F7F2DF1F91089580E0E8DFEE27F6
|
||||
:047FF000FF270994CA
|
||||
:027FFE00040479
|
||||
:0400000300007E007B
|
||||
:00000001FF
|
Loading…
Reference in New Issue
Block a user