silenius

Untitled

Feb 11th, 2021
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. #include "heltec.h"
  2. #include <SPI.h>
  3. #include <TinyGPS++.h>
  4. #include <HardwareSerial.h>
  5. #include <arduino.h>
  6.  
  7. #define RXPin 35
  8. #define TXPin 34
  9. #define GPSBaud 9600
  10. #define BAND 868E6 //you can set band here directly,e.g. 868E6,915E6
  11.  
  12. TinyGPSPlus gps;
  13. HardwareSerial ss(1);
  14.  
  15. unsigned int appDataSize;
  16. uint8_t appData[9];
  17. uint32_t LatitudeBinary, LongitudeBinary;
  18. uint16_t altitudeGps;
  19. uint8_t hdopGps;
  20. unsigned int counter;
  21. String rssi = "RSSI --";
  22. String packSize = "--";
  23. String packet ;
  24. String LatHex;
  25. String LongHex;
  26. uint8_t txBuffer[6];
  27.  
  28. void setup()
  29. {
  30. counter = 0;
  31. Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.Heltec.Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
  32. ss.begin(GPSBaud, SERIAL_8N1, RXPin, TXPin);
  33. Heltec.display->init();
  34. Heltec.display->flipScreenVertically();
  35. Heltec.display->setFont(ArialMT_Plain_10);
  36. Heltec.display->clear();
  37. Heltec.display->drawString(0, 0, "Heltec.LoRa Initial success!");
  38. Heltec.display->display();
  39. delay(1000);
  40. Serial.begin(115200);
  41.  
  42. //######################################################
  43. LoRa.setTxPower(20,RF_PACONFIG_PASELECT_PABOOST);
  44. LoRa.setSpreadingFactor(12);
  45. // LoRa.setSignalBandwidth(500E3);
  46. LoRa.setCodingRate4(8); // 4/8
  47. //LoRa.setPreambleLengh(long length);
  48. //######################################################
  49. }
  50.  
  51. void loop()
  52. {
  53. LatitudeBinary = ((gps_latitude() + 90) / 180) * 16777215;
  54. LatHex = String(LatitudeBinary, HEX);
  55. LongitudeBinary = ((gps_longitude() + 180) / 360) * 16777215;
  56. LongHex = String(LatitudeBinary, HEX);
  57. altitudeGps = gps_meters();
  58. hdopGps = gps_HDOP() * 10;
  59.  
  60. while (ss.available() > 0) gps.encode(ss.read());
  61. Heltec.display->clear();
  62. Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
  63. Heltec.display->setFont(ArialMT_Plain_10);
  64. Heltec.display->drawString(0, 0, "Sending packet: ");
  65. Heltec.display->drawString(90, 0, String(counter));
  66. Heltec.display->drawString(0, 10, String(LatitudeBinary) + " " + LatHex);
  67. Heltec.display->drawString(0, 20, String(LongitudeBinary) + " " + LongHex);
  68. Heltec.display->drawString(0, 30, String(gps_latitude(), 10));
  69. Heltec.display->drawString(0, 40, String(gps_longitude(), 10));
  70. Heltec.display->display();
  71.  
  72. // send packet
  73. LoRa.beginPacket();
  74. txBuffer[0] = ( LatitudeBinary >> 16 ) & 0xFF;
  75. txBuffer[1] = ( LatitudeBinary >> 8 ) & 0xFF;
  76. txBuffer[2] = LatitudeBinary & 0xFF;
  77. txBuffer[3] = ( LongitudeBinary >> 16 ) & 0xFF;
  78. txBuffer[4] = ( LongitudeBinary >> 8 ) & 0xFF;
  79. txBuffer[5] = LongitudeBinary & 0xFF;
  80. // txBuffer[6] = ( altitudeGps >> 8 ) & 0xFF;
  81. // txBuffer[7] = altitudeGps & 0xFF;
  82. // txBuffer[8] = hdopGps & 0xFF;
  83. LoRa.write(txBuffer, sizeof(txBuffer));
  84. LoRa.endPacket();
  85.  
  86. counter++;
  87. digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
  88. delay(1000); // wait for a second
  89. digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
  90. delay(4000); // wait for a jiffy
  91. }
  92.  
  93. float gps_latitude()
  94. {
  95. if (gps.location.isValid()){
  96. return gps.location.lat();
  97. }
  98. else
  99. {
  100. return 88;
  101. }
  102. }
  103. float gps_longitude(){
  104. if (gps.location.isValid()){
  105. return gps.location.lng();
  106. }
  107. else{
  108. return 88;
  109. }
  110. }
  111. float gps_meters() {
  112. return gps.altitude.meters();
  113. }
  114. float gps_HDOP(){
  115. return gps.hdop.hdop();
  116. }
Advertisement
Add Comment
Please, Sign In to add comment