Advertisement
Guest User

Untitled

a guest
Feb 24th, 2020
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.30 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <Adafruit_GPS.h>
  3. #include <SPI.h>
  4. #include <pins_arduino.h>
  5. #include <LoRa.h>
  6.  
  7. #define GPSSerial Serial2
  8. #define LORA_SCK 5
  9. #define LORA_MISO 19
  10. #define LORA_MOSI 27
  11. #define LORA_CS 18
  12. #define LORA_RST 14
  13. #define LORA_IRQ 26
  14. Adafruit_GPS GPS(&GPSSerial);
  15.  
  16. /////////////////// Timer stuff
  17. hw_timer_t * timer = NULL;
  18. int counter = 0;
  19.  
  20. void setup() {
  21.  
  22. // Set the serial for printing to 115200
  23. // Be sure to include
  24. // monitor_speed = 115200
  25. // as an option in the platformio.ini file
  26. Serial.begin(115200);
  27.  
  28. // 9600 baud is the default rate for the Adafruit Ultimate GPS module
  29. GPS.begin(9600);
  30. SPI.begin(LORA_SCK,LORA_MISO,LORA_MOSI,LORA_CS);
  31. LoRa.setSPI(SPI);
  32. LoRa.setPins(LORA_CS, LORA_RST, LORA_IRQ);
  33.  
  34. while (!Serial);
  35.  
  36. Serial.println("LoRa Sender");
  37.  
  38.  
  39. if (!LoRa.begin(915E6)) {
  40. Serial.println("Starting LoRa failed!");
  41. while (1);
  42. }
  43. // uncomment this line to turn on RMC (recommended minimum) and GGA (fix data) including altitude
  44. GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
  45. // uncomment this line to turn on only the "minimum recommended" data
  46. GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCONLY);
  47.  
  48. // For parsing data, we don't suggest using anything but either RMC only or RMC+GGA since
  49. // the parser doesn't care about other sentences at this time
  50. // Set the update rate
  51. GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
  52. // For the parsing code to work nicely and have time to sort thru the data, and
  53. // print it out we don't suggest using anything higher than 1 Hz
  54.  
  55. Serial.println("Init done...");
  56.  
  57. Serial.println("Initializing Timer");
  58. // For additional information on timers see the following link:
  59. // https://techtutorialsx.com/2017/10/07/esp32-arduino-timer-interrupts/
  60.  
  61. // Add your timer interrupt here
  62.  
  63. }
  64.  
  65.  
  66. void loop() {
  67. {
  68. Serial.print("Sending packet: ");
  69. Serial.println(counter);
  70.  
  71. // send packet
  72. LoRa.beginPacket();
  73. LoRa.print("hello ");
  74. LoRa.print(counter);
  75. LoRa.endPacket();
  76.  
  77. counter++;
  78.  
  79. delay(5000);
  80. }
  81.  
  82. if (GPSSerial.available()) {
  83. GPS.read();
  84. if (GPS.newNMEAreceived()) {
  85. GPS.parse(GPS.lastNMEA());
  86.  
  87. Serial.println(GPS.lastNMEA());
  88. Serial.print("\nTime: ");
  89. Serial.print(GPS.hour, DEC); Serial.print(':');
  90. Serial.print(GPS.minute, DEC); Serial.print(':');
  91. Serial.print(GPS.seconds, DEC); Serial.print('.');
  92. Serial.println(GPS.milliseconds);
  93. Serial.print("Date: ");
  94. Serial.print(GPS.day, DEC); Serial.print('/');
  95. Serial.print(GPS.month, DEC); Serial.print("/20");
  96. Serial.println(GPS.year, DEC);
  97. Serial.print("Fix: "); Serial.print((int)GPS.fix);
  98. Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
  99. if (GPS.fix) {
  100. Serial.print("Location: ");
  101. Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
  102. Serial.print(", ");
  103. Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
  104. Serial.print("Speed (knots): "); Serial.println(GPS.speed);
  105. Serial.print("Angle: "); Serial.println(GPS.angle);
  106. Serial.print("Altitude: "); Serial.println(GPS.altitude);
  107. Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
  108. }
  109.  
  110. }
  111. }
  112.  
  113. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement