Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "heltec.h"
- #include <SPI.h>
- #include <TinyGPS++.h>
- #include <HardwareSerial.h>
- #include <arduino.h>
- #define RXPin 35
- #define TXPin 34
- #define GPSBaud 9600
- #define BAND 868E6 //you can set band here directly,e.g. 868E6,915E6
- TinyGPSPlus gps;
- HardwareSerial ss(1);
- unsigned int appDataSize;
- uint8_t appData[9];
- uint32_t LatitudeBinary, LongitudeBinary;
- uint16_t altitudeGps;
- uint8_t hdopGps;
- unsigned int counter;
- String rssi = "RSSI --";
- String packSize = "--";
- String packet ;
- String LatHex;
- String LongHex;
- uint8_t txBuffer[6];
- void setup()
- {
- counter = 0;
- Heltec.begin(true /*DisplayEnable Enable*/, true /*Heltec.Heltec.Heltec.LoRa Disable*/, true /*Serial Enable*/, true /*PABOOST Enable*/, BAND /*long BAND*/);
- ss.begin(GPSBaud, SERIAL_8N1, RXPin, TXPin);
- Heltec.display->init();
- Heltec.display->flipScreenVertically();
- Heltec.display->setFont(ArialMT_Plain_10);
- Heltec.display->clear();
- Heltec.display->drawString(0, 0, "Heltec.LoRa Initial success!");
- Heltec.display->display();
- delay(1000);
- Serial.begin(115200);
- //######################################################
- LoRa.setTxPower(20,RF_PACONFIG_PASELECT_PABOOST);
- LoRa.setSpreadingFactor(12);
- // LoRa.setSignalBandwidth(500E3);
- LoRa.setCodingRate4(8); // 4/8
- //LoRa.setPreambleLengh(long length);
- //######################################################
- }
- void loop()
- {
- LatitudeBinary = ((gps_latitude() + 90) / 180) * 16777215;
- LatHex = String(LatitudeBinary, HEX);
- LongitudeBinary = ((gps_longitude() + 180) / 360) * 16777215;
- LongHex = String(LatitudeBinary, HEX);
- altitudeGps = gps_meters();
- hdopGps = gps_HDOP() * 10;
- while (ss.available() > 0) gps.encode(ss.read());
- Heltec.display->clear();
- Heltec.display->setTextAlignment(TEXT_ALIGN_LEFT);
- Heltec.display->setFont(ArialMT_Plain_10);
- Heltec.display->drawString(0, 0, "Sending packet: ");
- Heltec.display->drawString(90, 0, String(counter));
- Heltec.display->drawString(0, 10, String(LatitudeBinary) + " " + LatHex);
- Heltec.display->drawString(0, 20, String(LongitudeBinary) + " " + LongHex);
- Heltec.display->drawString(0, 30, String(gps_latitude(), 10));
- Heltec.display->drawString(0, 40, String(gps_longitude(), 10));
- Heltec.display->display();
- // send packet
- LoRa.beginPacket();
- txBuffer[0] = ( LatitudeBinary >> 16 ) & 0xFF;
- txBuffer[1] = ( LatitudeBinary >> 8 ) & 0xFF;
- txBuffer[2] = LatitudeBinary & 0xFF;
- txBuffer[3] = ( LongitudeBinary >> 16 ) & 0xFF;
- txBuffer[4] = ( LongitudeBinary >> 8 ) & 0xFF;
- txBuffer[5] = LongitudeBinary & 0xFF;
- // txBuffer[6] = ( altitudeGps >> 8 ) & 0xFF;
- // txBuffer[7] = altitudeGps & 0xFF;
- // txBuffer[8] = hdopGps & 0xFF;
- LoRa.write(txBuffer, sizeof(txBuffer));
- LoRa.endPacket();
- counter++;
- digitalWrite(LED, HIGH); // turn the LED on (HIGH is the voltage level)
- delay(1000); // wait for a second
- digitalWrite(LED, LOW); // turn the LED off by making the voltage LOW
- delay(4000); // wait for a jiffy
- }
- float gps_latitude()
- {
- if (gps.location.isValid()){
- return gps.location.lat();
- }
- else
- {
- return 88;
- }
- }
- float gps_longitude(){
- if (gps.location.isValid()){
- return gps.location.lng();
- }
- else{
- return 88;
- }
- }
- float gps_meters() {
- return gps.altitude.meters();
- }
- float gps_HDOP(){
- return gps.hdop.hdop();
- }
Advertisement
Add Comment
Please, Sign In to add comment