silenius

Untitled

Feb 11th, 2021
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.71 KB | None | 0 0
  1. #include "Arduino.h"
  2. #include "heltec.h"
  3.  
  4.  
  5. //long lastReceiveTime = 0;
  6. unsigned int counter = 0;
  7. float snr = 0;
  8. String nema;
  9. short rssi;
  10. short packSize;
  11. String packet;
  12. double latconv = 0;
  13. double longconv = 0;
  14. float dirtylong = 0;
  15. float dirtylat = 0;
  16. volatile bool recieveflag = false;
  17.  
  18. void setup(){
  19. Heltec.begin(true /*DisplayEnable Enable*/, true /*LoRa Enable*/, true /*Serial Enable*/, true /*LoRa use PABOOST*/, 868E6 /*LoRa RF working band*/);
  20. DisplayEnable=true;
  21. LoRaEnable=true;
  22. LoRa.setSpreadingFactor(12);
  23. LoRa.onReceive(onReceive);
  24. }
  25.  
  26. void loop(){
  27. LoRa.receive();
  28. if(recieveflag = true){
  29. recieveflag = false;
  30. counter++;
  31. convert();
  32. makestring();
  33. Heltec.display -> drawString(0, 0, "Received Size " + String(packSize));
  34. Heltec.display -> drawString(0, 10, String(latconv,10));
  35. Heltec.display -> drawString(0, 20, String(longconv,10));
  36. Heltec.display -> drawString(0, 40, "RSSI" + String(rssi) + "db " + " SNR " + String(snr, 2));
  37. Heltec.display -> drawString(0, 50, "Counter: " + (String)(counter-1));
  38. Heltec.display -> display();
  39. Heltec.display -> clear();
  40. }
  41. }
  42.  
  43. void onReceive(int packetSize){
  44. if (packetSize == 0) return;
  45. recieveflag = true;
  46. packSize = packetSize;
  47. snr = LoRa.packetSnr();
  48. rssi = LoRa.packetRssi();
  49. while (LoRa.available()){
  50. packet += (char) LoRa.read();
  51. }
  52. }
  53.  
  54. void convert(){
  55. short degLo = 0;
  56. short degLat =0;
  57. double minLat = 0;
  58. double minLo = 0;
  59. unsigned long latitude = 0;
  60. unsigned long longitude = 0;
  61.  
  62. latitude = uint8_t(packet[0])*65536 + uint8_t(packet[1])*256 + uint8_t(packet[2]);
  63. latconv = (latitude / 93206.75) - 90;
  64. degLat = latconv;
  65. minLat = (latconv - degLat)*60;
  66. dirtylat = (degLat*100) + minLat;
  67. longitude = uint8_t(packet[3])*65536 + uint8_t(packet[4])*256 + uint8_t(packet[5]);
  68. longconv = (longitude / 46603.375) - 180;
  69. degLo = longconv;
  70. minLo = (longconv - degLo)*60;
  71. dirtylong = (degLo*100) + minLo;
  72. }
  73.  
  74. void makestring(){
  75. char toSend[90];
  76. int Time = 0; //time, what is time
  77. int ndx=0;
  78. char lat[9];
  79. char lon[11];
  80. // dtostrf(altf, 1, 1, alt); //skipping that for now
  81. dtostrf(dirtylat, 1, 6, lat);
  82. dtostrf(dirtylong, 1, 5, lon);
  83.  
  84. char timeC[10] = "000000.00" ;
  85.  
  86. Serial.println(timeC); //###################################
  87. /* toSend[ndx++] = 'ยง';
  88. toSend[ndx++] = 'G';
  89. toSend[ndx++] = 'P';
  90. toSend[ndx++] = 'G';
  91. toSend[ndx++] = 'G';
  92. toSend[ndx++] = 'A';
  93. toSend[ndx++] = ',';
  94.  
  95. short hours = Time/3600; //all that time bollocks
  96. if(hours>9){
  97. toSend[ndx++] = '0' +(hours/10);
  98. toSend[ndx++] = '0' +(hours%10);
  99. }
  100. else{
  101. toSend[ndx++] = '0';
  102. toSend[ndx++] = '0' + hours;
  103. }
  104. short minutes = (Time%3600)/60;
  105. if(minutes>9){
  106. toSend[ndx++] = '0' +(minutes/10);
  107. toSend[ndx++] = '0' +(minutes%10);
  108. }
  109. else{
  110. toSend[ndx++] = '0';
  111. toSend[ndx++] = '0' + minutes;
  112. }
  113. short seconds = (Time%60);
  114. if(seconds>9){
  115. toSend[ndx++] = '0' +(seconds/10);
  116. toSend[ndx++] = '0' +(seconds%10);
  117. }
  118. else{
  119. toSend[ndx++] = '0';
  120. toSend[ndx++] = '0' + seconds;
  121. }
  122. toSend[ndx++]='.';
  123. for(int i = 0;i<2;i++){
  124. toSend[ndx++] = '0';
  125. }
  126. toSend[ndx++]= ',';
  127.  
  128.  
  129. if(dirtylat<1000){ //latitude: first see if we need to add a zero
  130. toSend[ndx++] = '0';
  131. }
  132. if(dirtylat<100){ //and maybe another
  133. toSend[ndx++] = '0';
  134. }
  135. if(dirtylat<10){ //while we are at it..
  136. toSend[ndx++] = '0';
  137. }
  138. for(int i = 0;i<8;i++){
  139. toSend[ndx++] = lat[i];
  140. }
  141. toSend[ndx++] = ',';
  142. toSend[ndx++] = 'N'; //I'm gonna hardcode north because lazy
  143. toSend[ndx++] = ',';
  144.  
  145.  
  146. if(dirtylong<10000){ //same for long
  147. toSend[ndx++] = '0';
  148. }
  149. if(dirtylong<1000){
  150. toSend[ndx++] = '0';
  151. }
  152. if(dirtylong<100){
  153. toSend[ndx++] = '0';
  154. }
  155. if(dirtylong<10){
  156. toSend[ndx++] = '0';
  157. }
  158. for(int i = 0; i<10; i++){
  159. if(lon[i]!=NULL){
  160. toSend[ndx++] = lon[i];
  161. }
  162. }
  163. toSend[ndx++] = ',';
  164. toSend[ndx++] = 'E'; //hardcoded as well
  165. toSend[ndx++] = ',';
  166. toSend[ndx++] = '1';
  167. toSend[ndx++] = ',';
  168. toSend[ndx++] = '5'; //next up is the number of satellites, anything between 4 and 10 willl do
  169. toSend[ndx++] = ',';
  170. toSend[ndx++] = '1'; //now we send the relative accuracy. 1.5 is common
  171. toSend[ndx++] = '.';
  172. toSend[ndx++]= '5';
  173. toSend[ndx++]= ',';
  174. //for(int i = 0; i<10;i++){ //heres this biggie. the altitude in meters
  175. // if(alt[i]!=NULL){
  176. // toSend[ndx++] = alt[i];
  177. // }
  178. //}
  179. /* toSend[ndx++] = '2'; // jk, I'm gonna hardcode that as well
  180. toSend[ndx++] = '0';
  181. toSend[ndx++] = '.';
  182. toSend[ndx++] = '0';
  183. toSend[ndx++] = '0';
  184. toSend[ndx++] = ',';
  185. toSend[ndx++] = 'M';
  186. toSend[ndx++] = ',';
  187. toSend[ndx++] = '-'; //next up is the altitude above elisoidal. -34.2 seems to be the standard.
  188. toSend[ndx++] = '3';
  189. toSend[ndx++] = '4';
  190. toSend[ndx++] = '.';
  191. toSend[ndx++] = '2';
  192. toSend[ndx++] = ',';
  193. toSend[ndx++] = 'M';
  194. toSend[ndx++] = ',';
  195. toSend[ndx++] = '0';
  196. toSend[ndx++] = '.';
  197. toSend[ndx++] = '1';
  198. toSend[ndx++] = ',';
  199. for(int i = ndx; i<90;i++){ //remove empty chars
  200. toSend[i] = NULL;
  201. }
  202. */
  203.  
  204. //Serial.println(toSend);
  205.  
  206.  
  207.  
  208. /*
  209. makeCheck(toSend, ndx); //do checksum
  210. ndx+=3;
  211. toSend[ndx] = '\0';
  212. */
  213. // nema = String(toSend);
  214. }
Advertisement
Add Comment
Please, Sign In to add comment