Last active
May 4, 2020 16:55
-
-
Save bprobbins/b50dceeb5fed2288d4df1f612294ae8c to your computer and use it in GitHub Desktop.
Particle argon lora gps client
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
#include <Adafruit_GPS.h> | |
#include <RF9X-RK.h> //https://github.com/rickkas7/RF9X-RK | |
#include <RHReliableDatagram.h> | |
#include <RH_RF95.h> | |
#include <SPI.h> | |
#define CLIENT_ADDRESS 1 | |
#define SERVER_ADDRESS 2 | |
#define RFM95_CS D6 | |
#define RFM95_RST A5 | |
#define RFM95_INT D2 | |
#define RF95_FREQ 915.0 | |
SYSTEM_MODE(AUTOMATIC); | |
RH_RF95 driver(D6, D2); | |
RHReliableDatagram manager(driver, CLIENT_ADDRESS); | |
#define GPSSerial Serial1 | |
Adafruit_GPS GPS(&GPSSerial); | |
#define GPSECHO false | |
uint32_t timer = millis(); | |
char data[20]; | |
uint8_t buf[RH_RF95_MAX_MESSAGE_LEN]; | |
int logRate = 10000; | |
float frequency = 915.0; | |
void setup() { | |
pinMode(RFM95_RST, OUTPUT); | |
digitalWrite(RFM95_RST, HIGH); | |
Serial.begin(115200); | |
// manual reset | |
digitalWrite(RFM95_RST, LOW); | |
delay(10); | |
digitalWrite(RFM95_RST, HIGH); | |
delay(10); | |
if (!manager.init()) | |
Serial.println("init failed"); | |
driver.setFrequency(frequency); | |
driver.setTxPower(23, false); | |
GPS.begin(9600); | |
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA); | |
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); | |
delay(1000); | |
GPSSerial.println(PMTK_Q_RELEASE); | |
}//setup | |
int counter = 0; | |
unsigned long packetnum = 0; | |
char BATstr[11]; | |
char LATstr[12]; | |
char LONstr[12]; | |
char ALTstr[12]; | |
byte sendLen; | |
char radiopacket[100]; | |
double myfLAT; | |
double myfLON; | |
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 (timer > millis()) timer = millis(); | |
if (millis() - timer > logRate) { | |
timer = millis(); | |
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"); | |
if (manager.sendtoWait((uint8_t*)radiopacket, sizeof(radiopacket), SERVER_ADDRESS)) { | |
uint8_t len = sizeof(buf); | |
uint8_t from; | |
if (manager.recvfromAckTimeout(buf, &len, 2000, &from)) { | |
buf[len] = 0; | |
Serial.printlnf("got reply from 0x%02x rssi=%d %s", from, driver.lastRssi(), (char *) buf); | |
} | |
else | |
{ | |
Serial.println("No reply, is rf95_reliable_datagram_server running?"); | |
} | |
} | |
else | |
Serial.println("sendtoWait failed"); | |
delay(500); | |
}//if gps.fix | |
}//if (millis() - timer > 2000) | |
}//loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment