Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <Adafruit_GPS.h>
- #include <SPI.h>
- #include <pins_arduino.h>
- #include <LoRa.h>
- #define GPSSerial Serial2
- #define LORA_SCK 5
- #define LORA_MISO 19
- #define LORA_MOSI 27
- #define LORA_CS 18
- #define LORA_RST 14
- #define LORA_IRQ 26
- Adafruit_GPS GPS(&GPSSerial);
- /////////////////// Timer stuff
- hw_timer_t * timer = NULL;
- int counter = 0;
- void setup() {
- // Set the serial for printing to 115200
- // Be sure to include
- // monitor_speed = 115200
- // as an option in the platformio.ini file
- Serial.begin(115200);
- // 9600 baud is the default rate for the Adafruit Ultimate GPS module
- GPS.begin(9600);
- SPI.begin(LORA_SCK,LORA_MISO,LORA_MOSI,LORA_CS);
- LoRa.setSPI(SPI);
- LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
- while (!Serial);
- Serial.println("LoRa Sender");
- if (!LoRa.begin(915E6)) {
- Serial.println("Starting LoRa failed!");
- while (1);
- }
- // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
- GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
- // uncomment this line to turn on only the "minimum recommended" data
- GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
- // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
- // the parser doesn't care about other sentences at this time
- // Set the update rate
- GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
- // For the parsing code to work nicely and have time to sort thru the data, and
- // print it out we don't suggest using anything higher than 1 Hz
- Serial.println("Init done...");
- Serial.println("Initializing Timer");
- // For additional information on timers see the following link:
- // https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/
- // Add your timer interrupt here
- }
- void loop() {
- {
- Serial.print("Sending packet: ");
- Serial.println(counter);
- // send packet
- LoRa.beginPacket();
- LoRa.print("hello ");
- LoRa.print(counter);
- LoRa.endPacket();
- counter++;
- delay(5000);
- }
- if (GPSSerial.available()) {
- GPS.read();
- if (GPS.newNMEAreceived()) {
- GPS.parse(GPS.lastNMEA());
- Serial.println(GPS.lastNMEA());
- Serial.print("\nTime: ");
- Serial.print(GPS.hour, DEC); Serial.print(':');
- Serial.print(GPS.minute, DEC); Serial.print(':');
- Serial.print(GPS.seconds, DEC); Serial.print('.');
- 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);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement