mirror of
				https://github.com/KevinMidboe/TinyGSM.git
				synced 2025-10-29 18:00:18 +00:00 
			
		
		
		
	@@ -253,6 +253,54 @@ public:
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  String getIMEI() {
 | 
			
		||||
    sendAT(GF("+GSN"));
 | 
			
		||||
    if (waitResponse(GF(GSM_NL)) != 1) {
 | 
			
		||||
      return "";
 | 
			
		||||
    }
 | 
			
		||||
    String res = stream.readStringUntil('\n');
 | 
			
		||||
    waitResponse();
 | 
			
		||||
    res.trim();
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int getSignalQuality() {
 | 
			
		||||
    sendAT(GF("+CSQ"));
 | 
			
		||||
    if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
 | 
			
		||||
      return 99;
 | 
			
		||||
    }
 | 
			
		||||
    int res = stream.readStringUntil(',').toInt();
 | 
			
		||||
    waitResponse();
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool callAnswer() {
 | 
			
		||||
    sendAT(GF("A"));
 | 
			
		||||
    return waitResponse() == 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool callNumber(const String& number) {
 | 
			
		||||
    sendAT(GF("D"), number);
 | 
			
		||||
    return waitResponse() == 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool callHangup(const String& number) {
 | 
			
		||||
    sendAT(GF("H"), number);
 | 
			
		||||
    return waitResponse() == 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool sendSMS(const String& number, const String& text) {
 | 
			
		||||
    sendAT(GF("+CMGF=1"));
 | 
			
		||||
    waitResponse();
 | 
			
		||||
    sendAT(GF("+CMGS=\""), number, GF("\""));
 | 
			
		||||
    if (waitResponse(GF(">")) != 1) {
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
    stream.print(text);
 | 
			
		||||
    stream.write((char)0x1A);
 | 
			
		||||
    return waitResponse(60000L) == 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  SimStatus getSimStatus(unsigned long timeout = 10000L) {
 | 
			
		||||
    for (unsigned long start = millis(); millis() - start < timeout; ) {
 | 
			
		||||
      sendAT(GF("+CPIN?"));
 | 
			
		||||
 
 | 
			
		||||
@@ -54,7 +54,6 @@ class GsmClient : public Client
 | 
			
		||||
  typedef TinyGsmFifo<uint8_t, TINY_GSM_RX_BUFFER> RxFifo;
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
  GsmClient() {}
 | 
			
		||||
 | 
			
		||||
  GsmClient(TinyGsm& modem, uint8_t mux = 1) {
 | 
			
		||||
@@ -260,6 +259,96 @@ public:
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  String getIMEI() {
 | 
			
		||||
    sendAT(GF("+GSN"));
 | 
			
		||||
    if (waitResponse(GF(GSM_NL)) != 1) {
 | 
			
		||||
      return "";
 | 
			
		||||
    }
 | 
			
		||||
    String res = stream.readStringUntil('\n');
 | 
			
		||||
    waitResponse();
 | 
			
		||||
    res.trim();
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  int getSignalQuality() {
 | 
			
		||||
    sendAT(GF("+CSQ"));
 | 
			
		||||
    if (waitResponse(GF(GSM_NL "+CSQ:")) != 1) {
 | 
			
		||||
      return 99;
 | 
			
		||||
    }
 | 
			
		||||
    int res = stream.readStringUntil(',').toInt();
 | 
			
		||||
    waitResponse();
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  String getGsmLocation() {
 | 
			
		||||
    sendAT(GF("+CIPGSMLOC=1,1"));
 | 
			
		||||
    if (waitResponse(GF(GSM_NL "+CIPGSMLOC:")) != 1) {
 | 
			
		||||
      return "";
 | 
			
		||||
    }
 | 
			
		||||
    String res = stream.readStringUntil('\n');
 | 
			
		||||
    waitResponse();
 | 
			
		||||
    res.trim();
 | 
			
		||||
    return res;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool setGsmBusy(bool busy = true) {
 | 
			
		||||
    sendAT(GF("+GSMBUSY="), busy ? 1 : 0);
 | 
			
		||||
    return waitResponse() == 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool callAnswer() {
 | 
			
		||||
    sendAT(GF("A"));
 | 
			
		||||
    return waitResponse() == 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool callNumber(const String& number) {
 | 
			
		||||
    sendAT(GF("D"), number);
 | 
			
		||||
    return waitResponse() == 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool callHangup(const String& number) {
 | 
			
		||||
    sendAT(GF("H"), number);
 | 
			
		||||
    return waitResponse() == 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool sendSMS(const String& number, const String& text) {
 | 
			
		||||
    sendAT(GF("+CMGF=1"));
 | 
			
		||||
    waitResponse();
 | 
			
		||||
    sendAT(GF("+CMGS=\""), number, GF("\""));
 | 
			
		||||
    if (waitResponse(GF(">")) != 1) {
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
    stream.print(text);
 | 
			
		||||
    stream.write((char)0x1A);
 | 
			
		||||
    return waitResponse(60000L) == 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  bool sendSMS_UTF16(const String& number, const void* text, size_t len) {
 | 
			
		||||
    sendAT(GF("+CMGF=1"));
 | 
			
		||||
    waitResponse();
 | 
			
		||||
    sendAT(GF("+CSCS=\"HEX\""));
 | 
			
		||||
    waitResponse();
 | 
			
		||||
    sendAT(GF("+CSMP=17,167,0,8"));
 | 
			
		||||
    waitResponse();
 | 
			
		||||
 | 
			
		||||
    sendAT(GF("+CMGS=\""), number, GF("\""));
 | 
			
		||||
    if (waitResponse(GF(">")) != 1) {
 | 
			
		||||
      return false;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    uint16_t* t = (uint16_t*)text;
 | 
			
		||||
    for (size_t i=0; i<len; i++) {
 | 
			
		||||
      uint8_t c = t[i] >> 8;
 | 
			
		||||
      if (c < 0x10) { stream.print('0'); }
 | 
			
		||||
      stream.print(c, HEX);
 | 
			
		||||
      c = t[i] & 0xFF;
 | 
			
		||||
      if (c < 0x10) { stream.print('0'); }
 | 
			
		||||
      stream.print(c, HEX);
 | 
			
		||||
    }
 | 
			
		||||
    stream.write((char)0x1A);
 | 
			
		||||
    return waitResponse(60000L) == 1;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  SimStatus getSimStatus(unsigned long timeout = 10000L) {
 | 
			
		||||
    for (unsigned long start = millis(); millis() - start < timeout; ) {
 | 
			
		||||
      sendAT(GF("+CPIN?"));
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user