Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Arduino.h"
- #include "heltec.h"
- long lastReceiveTime = 0;
- unsigned int counter = 0;
- float snr = 0;
- String nema;
- int rssi;
- String packSize = "--";
- String packet;
- double latconv = 0;
- double longconv = 0;
- float dirtylong = 0;
- float dirtylat = 0;
- void setup(){
- Heltec.begin(true /*DisplayEnable Enable*/, true /*LoRa Enable*/, true /*Serial Enable*/, true /*LoRa use PABOOST*/, 868E6 /*LoRa RF working band*/);
- LoRa.setSpreadingFactor(12);
- LoRa.onReceive(onReceive);
- LoRa.receive();
- }
- void loop(){
- delay(1000);
- LoRa.receive();
- displaySendReceive();
- }
- void displaySendReceive()
- {
- Heltec.display -> drawString(0, 0, "Received Size " + String(packSize));
- Heltec.display -> drawString(0, 10, String(latconv,10));
- Heltec.display -> drawString(0, 20, String(longconv,20));
- Heltec.display -> drawString(0, 40, "RSSI" + String(rssi) + "db " + " SNR " + String(snr, 2));
- Heltec.display -> drawString(0, 50, "Counter: " + (String)(counter-1));
- Heltec.display -> display();
- Heltec.display -> clear();
- }
- void onReceive(int packetSize){
- packet = "";
- packSize = String(packetSize,DEC);
- while (LoRa.available()){
- packet += (char) LoRa.read();
- }
- snr = LoRa.packetSnr();
- rssi = LoRa.packetRssi();
- convert();
- counter++;
- makestring();
- }
- void convert(){
- short degLo = 0;
- short degLat =0;
- double minLat = 0;
- double minLo = 0;
- unsigned long latitude = 0;
- unsigned long longitude = 0;
- latitude = uint8_t(packet[0])*65536 + uint8_t(packet[1])*256 + uint8_t(packet[2]);
- latconv = (latitude / 93206.75) - 90;
- degLat = latconv;
- minLat = (latconv - degLat)*60;
- dirtylat = (degLat*100) + minLat;
- longitude = uint8_t(packet[3])*65536 + uint8_t(packet[4])*256 + uint8_t(packet[5]);
- longconv = (longitude / 46603.375) - 180;
- degLo = longconv;
- minLo = (longconv - degLo)*60;
- dirtylong = (degLo*100) + minLo;
- }
- void makestring(){
- char toSend[100];
- int Time = 0; //time, what is time
- int ndx=0;
- char lat[9];
- char lon[11];
- // dtostrf(altf, 1, 1, alt); //skipping that for now
- dtostrf(dirtylat, 1, 6, lat);
- dtostrf(dirtylong, 1, 5, lon);
- toSend[ndx++] = 'ยง';
- toSend[ndx++] = 'G';
- toSend[ndx++] = 'P';
- toSend[ndx++] = 'R';
- toSend[ndx++] = 'M';
- toSend[ndx++] = 'C';
- toSend[ndx++] = ',';
- int hours = Time/3600; //all that time bollocks
- if(hours>9){
- toSend[ndx++] = '0' +(hours/10);
- toSend[ndx++] = '0' +(hours%10);
- }
- else{
- toSend[ndx++] = '0';
- toSend[ndx++] = '0' + hours;
- }
- int minutes = (Time%3600)/60;
- if(minutes>9){
- toSend[ndx++] = '0' +(minutes/10);
- toSend[ndx++] = '0' +(minutes%10);
- }
- else{
- toSend[ndx++] = '0';
- toSend[ndx++] = '0' + minutes;
- }
- int seconds = (Time%60);
- if(seconds>9){
- toSend[ndx++] = '0' +(seconds/10);
- toSend[ndx++] = '0' +(seconds%10);
- }
- else{
- toSend[ndx++] = '0';
- toSend[ndx++] = '0' + seconds;
- }
- toSend[ndx++]='.';
- for(int i = 0;i<2;i++){
- toSend[ndx++] = '0';
- }
- toSend[ndx++]= ',';
- if(dirtylat<1000){ //latitude: first see if we need to add a zero
- toSend[ndx++] = '0';
- }
- if(dirtylat<100){ //and maybe another
- toSend[ndx++] = '0';
- }
- if(dirtylat<10){ //while we are at it..
- toSend[ndx++] = '0';
- }
- for(int i = 0;i<8;i++){
- toSend[ndx++] = lat[i];
- }
- toSend[ndx++] = ',';
- toSend[ndx++] = 'N'; //I'm gonna hardcode north because lazy
- toSend[ndx++] = ',';
- if(dirtylong<10000){ //same for long
- toSend[ndx++] = '0';
- }
- if(dirtylong<1000){
- toSend[ndx++] = '0';
- }
- if(dirtylong<100){
- toSend[ndx++] = '0';
- }
- if(dirtylong<10){
- toSend[ndx++] = '0';
- }
- for(int i = 0; i<10; i++){
- if(lon[i]!=NULL){
- toSend[ndx++] = lon[i];
- }
- }
- toSend[ndx++] = ',';
- toSend[ndx++] = 'E'; //hardcoded as well
- toSend[ndx++] = ',';
- toSend[ndx++] = '1';
- toSend[ndx++] = ',';
- toSend[ndx++] = '5'; //next up is the number of satellites, anything between 4 and 10 willl do
- toSend[ndx++] = ',';
- toSend[ndx++] = '1'; //now we send the relative accuracy. 1.5 is common
- toSend[ndx++] = '.';
- toSend[ndx++]= '5';
- toSend[ndx++]= ',';
- //for(int i = 0; i<10;i++){ //heres this biggie. the altitude in meters
- // if(alt[i]!=NULL){
- // toSend[ndx++] = alt[i];
- // }
- //}
- toSend[ndx++] = '2'; // jk, I'm gonna hardcode that as well
- toSend[ndx++] = '0';
- toSend[ndx++] = '.';
- toSend[ndx++] = '0';
- toSend[ndx++] = '0';
- toSend[ndx++] = ',';
- toSend[ndx++] = 'M';
- toSend[ndx++] = ',';
- toSend[ndx++] = '-'; //next up is the altitude above elisoidal. -34.2 seems to be the standard.
- toSend[ndx++] = '3';
- toSend[ndx++] = '4';
- toSend[ndx++] = '.';
- toSend[ndx++] = '2';
- toSend[ndx++] = ',';
- toSend[ndx++] = 'M';
- toSend[ndx++] = ',';
- toSend[ndx++] = '0';
- toSend[ndx++] = '.';
- toSend[ndx++] = '1';
- toSend[ndx++] = ',';
- //Serial.println(String(toSend));
- /*
- for(int i = ndx; i<100;i++){ //remove empty chars
- toSend[i] = NULL;
- }
- */
- /*
- makeCheck(toSend, ndx); //do checksum
- ndx+=3;
- toSend[ndx] = '\0';
- */
- }
Advertisement
Add Comment
Please, Sign In to add comment