Last active
October 14, 2022 18:58
-
-
Save bprobbins/308c7cf0d7b6cce9563b402e51a35b84 to your computer and use it in GitHub Desktop.
Xenon GPS LoRa Sender using https://github.com/sandeepmistry/arduino-LoRa.
This file contains 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
//Employs Particle Xenon, Adafruit Ultimate GPS Feather, | |
//and Adafruit RF95 Feather Radio | |
#include <Adafruit_GPS.h> | |
#include <Particle.h> | |
#include <SPI.h> | |
#include <LoRa.h> //https://github.com/sandeepmistry/arduino-LoRa | |
SYSTEM_MODE(MANUAL); | |
SYSTEM_THREAD(ENABLED); | |
/* | |
Adafruit rf95 feather wiring: | |
CS->A | |
RST->F | |
IRQ->E | |
*/ | |
const int csPin = D6; // LoRa radio chip select | |
const int resetPin = A5; // LoRa radio reset | |
const int irqPin = D2; // change for your board; must be a hardware interrupt pin | |
// what's the name of the hardware serial port? | |
#define GPSSerial Serial1 | |
// Connect to the GPS on the hardware port | |
Adafruit_GPS GPS(&GPSSerial); | |
// Set GPSECHO to 'false' to turn off echoing the GPS data to the Serial console | |
// Set to 'true' if you want to debug and listen to the raw GPS sentences | |
#define GPSECHO false | |
uint32_t timer = millis(); | |
int logRate = 15000; | |
void setup() { | |
Mesh.disconnect(); | |
Mesh.off(); | |
Particle.disconnect(); | |
pinMode(resetPin, OUTPUT); | |
digitalWrite(resetPin, HIGH); | |
Serial.begin(115200) ; | |
// manual reset | |
digitalWrite(resetPin, LOW); | |
delay(10); | |
digitalWrite(resetPin, HIGH); | |
delay(10); | |
Serial.println("LoRa Sender"); | |
// override the default CS, reset, and IRQ pins | |
LoRa.setPins(csPin, resetPin, irqPin);// set CS, reset, IRQ pin | |
if (!LoRa.begin(915E6)) { | |
Serial.println("Starting LoRa failed!"); | |
while (1) { Serial.println("Starting LoRa failed!"); } | |
} | |
LoRa.setSignalBandwidth(125000); | |
LoRa.setSpreadingFactor(12); | |
LoRa.setCodingRate4(5); | |
LoRa.setPreambleLength(8); | |
LoRa.enableCrc(); | |
LoRa.setFrequency(915E6); | |
LoRa.setTxPower(20, true); | |
GPS.begin(9600); | |
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); | |
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate | |
delay(1000); | |
GPSSerial.println(PMTK_Q_RELEASE); | |
}//setup | |
unsigned long packetnum = 0; // packet counter | |
byte sendLen; | |
char radiopacket[100]; | |
void loop() { | |
char c = GPS.read(); | |
if (GPSECHO) | |
if (c) Serial.print(c); | |
if (GPS.newNMEAreceived()) { | |
Serial.println(GPS.lastNMEA()); | |
if (!GPS.parse(GPS.lastNMEA())) | |
return; | |
} | |
if (millis() - timer > logRate) { //2000 | |
timer = millis(); // reset the timer | |
Serial.print("\nTime: "); | |
if (GPS.hour < 10) { Serial.print('0'); } | |
Serial.print(GPS.hour, DEC); Serial.print(':'); | |
if (GPS.minute < 10) { Serial.print('0'); } | |
Serial.print(GPS.minute, DEC); Serial.print(':'); | |
if (GPS.seconds < 10) { Serial.print('0'); } | |
Serial.print(GPS.seconds, DEC); Serial.print('.'); | |
if (GPS.milliseconds < 10) { | |
Serial.print("00"); | |
} else if (GPS.milliseconds > 9 && GPS.milliseconds < 100) { | |
Serial.print("0"); | |
} | |
Serial.println(GPS.milliseconds); | |
Serial.print("Date: "); | |
Serial.print(GPS.day, DEC); Serial.print('/'); | |
Serial.print(GPS.month, DEC); Serial.print("/20"); | |
Serial.println(GPS.year, DEC); | |
Serial.print("Fix: "); Serial.print((int)GPS.fix); | |
Serial.print(" quality: "); Serial.println((int)GPS.fixquality); | |
if (GPS.fix) { | |
Serial.print("Location: "); | |
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat); | |
Serial.print(", "); | |
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon); | |
Serial.print("Speed (knots): "); Serial.println(GPS.speed); | |
Serial.print("Angle: "); Serial.println(GPS.angle); | |
Serial.print("Altitude: "); Serial.println(GPS.altitude); | |
Serial.print("Satellites: "); Serial.println((int)GPS.satellites); | |
packetnum++; | |
float measuredvbat = analogRead(BATT) * 0.0011224; | |
snprintf(radiopacket, sizeof(radiopacket), | |
"vBAT:,%1.2f,LAT:,%4.6f,%c,LON:,%4.6f,%c,SATS:,%i,ALT:,%4.6f,%u", | |
measuredvbat, GPS.latitudeDegrees, GPS.lat, GPS.longitudeDegrees, | |
GPS.lon, (int)GPS.satellites, GPS.altitude, packetnum); | |
sendLen = strlen(radiopacket); | |
radiopacket[sendLen] = '\0'; | |
Serial.println("Sending to rf95_reliable_datagram_server"); | |
Serial.print("Sending packet: "); | |
Serial.print(radiopacket); | |
Serial.print(","); | |
Serial.println(packetnum); | |
// send packet | |
LoRa.beginPacket(); | |
LoRa.print(radiopacket); | |
LoRa.endPacket(); | |
}//if gps.fix | |
}//if (millis() - timer > logRate) | |
}//loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment