Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

TinyGsmClientSIM808.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /**
  2. * file TinyGsmClientSIM808.h
  3. * author Volodymyr Shymanskyy
  4. * license LGPL-3.0
  5. * copyright Copyright (c) 2016 Volodymyr Shymanskyy
  6. * date Nov 2016
  7. */
  8. #ifndef TinyGsmClientSIM808_h
  9. #define TinyGsmClientSIM808_h
  10. #include "TinyGsmClientSIM800.h"
  11. class TinyGsmSim808: public TinyGsmSim800
  12. {
  13. public:
  14. explicit TinyGsmSim808(Stream& stream)
  15. : TinyGsmSim800(stream)
  16. {}
  17. /*
  18. * GPS location functions
  19. */
  20. // enable GPS
  21. bool enableGPS()
  22. {
  23. uint16_t state;
  24. sendAT(GF("+CGNSPWR=1"));
  25. if (waitResponse() != 1) {
  26. return false;
  27. }
  28. return true;
  29. }
  30. bool disableGPS()
  31. {
  32. uint16_t state;
  33. sendAT(GF("+CGNSPWR=0"));
  34. if (waitResponse() != 1) {
  35. return false;
  36. }
  37. return true;
  38. }
  39. // get the RAW GPS output
  40. // works only with ans SIM808 V2
  41. String getGPSraw()
  42. {
  43. sendAT(GF("+CGNSINF"));
  44. if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) {
  45. return "";
  46. }
  47. String res = stream.readStringUntil('\n');
  48. waitResponse();
  49. res.trim();
  50. return res;
  51. }
  52. // get GPS informations
  53. // works only with ans SIM808 V2
  54. bool getGPS(float *lat, float *lon, float *speed=0, int *alt=0, int *vsat=0, int *usat=0)
  55. {
  56. //String buffer = "";
  57. char chr_buffer[12];
  58. bool fix = false;
  59. sendAT(GF("+CGNSINF"));
  60. if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) {
  61. return false;
  62. }
  63. stream.readStringUntil(','); // mode
  64. if ( stream.readStringUntil(',').toInt() == 1 ) {
  65. fix = true;
  66. }
  67. stream.readStringUntil(','); //utctime
  68. *lat = stream.readStringUntil(',').toFloat(); //lat
  69. *lon = stream.readStringUntil(',').toFloat(); //lon
  70. if (alt != NULL) {
  71. *alt = stream.readStringUntil(',').toFloat(); //lon
  72. }
  73. if (speed != NULL) {
  74. *speed = stream.readStringUntil(',').toFloat(); //speed
  75. }
  76. stream.readStringUntil(',');
  77. stream.readStringUntil(',');
  78. stream.readStringUntil(',');
  79. stream.readStringUntil(',');
  80. stream.readStringUntil(',');
  81. stream.readStringUntil(',');
  82. stream.readStringUntil(',');
  83. if (vsat != NULL) {
  84. *vsat = stream.readStringUntil(',').toInt(); //viewed satelites
  85. }
  86. if (usat != NULL) {
  87. *usat = stream.readStringUntil(',').toInt(); //used satelites
  88. }
  89. stream.readStringUntil('\n');
  90. waitResponse();
  91. return fix;
  92. }
  93. // get GPS time
  94. // works only with SIM808 V2
  95. bool getGPSTime(int *year, int *month, int *day, int *hour, int *minute, int *second)
  96. {
  97. bool fix = false;
  98. char chr_buffer[12];
  99. sendAT(GF("+CGNSINF"));
  100. if (waitResponse(GF(GSM_NL "+CGNSINF:")) != 1) {
  101. return false;
  102. }
  103. for (int i = 0; i < 3; i++) {
  104. String buffer = stream.readStringUntil(',');
  105. buffer.toCharArray(chr_buffer, sizeof(chr_buffer));
  106. switch (i) {
  107. case 0:
  108. //mode
  109. break;
  110. case 1:
  111. //fixstatus
  112. if ( buffer.toInt() == 1 ) {
  113. fix = buffer.toInt();
  114. }
  115. break;
  116. case 2:
  117. *year = buffer.substring(0,4).toInt();
  118. *month = buffer.substring(4,6).toInt();
  119. *day = buffer.substring(6,8).toInt();
  120. *hour = buffer.substring(8,10).toInt();
  121. *minute = buffer.substring(10,12).toInt();
  122. *second = buffer.substring(12,14).toInt();
  123. break;
  124. default:
  125. // if nothing else matches, do the default
  126. // default is optional
  127. break;
  128. }
  129. }
  130. String res = stream.readStringUntil('\n');
  131. waitResponse();
  132. if (fix) {
  133. return true;
  134. } else {
  135. return false;
  136. }
  137. }
  138. };
  139. #endif