#include #include #include #include #include "pb_common.h" #include "pb.h" #include "pb_encode.h" #include "gateway/message.pb.h" unsigned long previousMillis = 0; const long interval = 5000; float lat = 0; float lng = 0; bool sending = false; TinyGPSPlus gps; SoftwareSerial ss(6, 7); typedef struct lora_status_s { int sleep; } lora_status_t; static lora_status_t lora_status; void transmitLora() { // Encode as protobuf packet if (lat && lng) { uint8_t buffer[50] = {0}; Fenceless_CollarResponse m = Fenceless_CollarResponse_init_zero; pb_ostream_t stream = pb_ostream_from_buffer(buffer, sizeof(buffer)); m.loc.x = lat; m.loc.y = lng; int status = pb_encode(&stream, Fenceless_CollarResponse_fields, &m); if (!status) { Serial.println("Failed to encode"); } Serial.print("Sending packet Lat / Long: "); Serial.println(lat); Serial.println(lng); // send packet LoRa.beginPacket(); LoRa.print((char *) buffer); LoRa.endPacket(); } } void updateGPS() { // Gather GPS data if (gps.location.isValid()) { lat = gps.location.lat(); lng = gps.location.lng(); } else { 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< 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(); } }