mirror of
https://github.com/vshymanskyy/TinyGSM.git
synced 2026-05-15 04:06:10 +00:00
Support fetching hardware and firmware version and serial number
Signed-off-by: Sara Damiano <sdamiano@stroudcenter.org>
This commit is contained in:
@@ -161,6 +161,20 @@ class TinyGsmA6 : public TinyGsmModem<TinyGsmA6>,
|
||||
}
|
||||
}
|
||||
|
||||
// Gets the modem serial number
|
||||
String getModemSerialNumberImpl() {
|
||||
sendAT(GF("GSN")); // Not CGSN
|
||||
String res;
|
||||
if (waitResponse(1000L, res) != 1) { return ""; }
|
||||
// Do the replaces twice so we cover both \r and \r\n type endings
|
||||
res.replace("\r\nOK\r\n", "");
|
||||
res.replace("\rOK\r", "");
|
||||
res.replace("\r\n", " ");
|
||||
res.replace("\r", " ");
|
||||
res.trim();
|
||||
return res;
|
||||
}
|
||||
|
||||
bool factoryDefaultImpl() {
|
||||
sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||
waitResponse();
|
||||
|
||||
@@ -168,6 +168,25 @@ class TinyGsmESP8266 : public TinyGsmModem<TinyGsmESP8266>,
|
||||
return "ESP8266";
|
||||
}
|
||||
|
||||
// Gets the modem serial number
|
||||
String getModemSerialNumberImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
// Gets the modem hardware version
|
||||
String getModemHardwareVersionImpl() TINY_GSM_ATTR_NOT_AVAILABLE;
|
||||
|
||||
// Gets the modem firmware version
|
||||
String getModemFirmwareVersionImpl() {
|
||||
sendAT(GF("GMR")); // GMR instead of CGMR
|
||||
String res;
|
||||
if (waitResponse(1000L, res) != 1) { return ""; }
|
||||
// Do the replaces twice so we cover both \r and \r\n type endings
|
||||
res.replace("\r\nOK\r\n", "");
|
||||
res.replace("\rOK\r", "");
|
||||
res.replace("\r\n", " ");
|
||||
res.replace("\r", " ");
|
||||
res.trim();
|
||||
return res;
|
||||
}
|
||||
|
||||
void setBaudImpl(uint32_t baud) {
|
||||
sendAT(GF("+UART_CUR="), baud, "8,1,0,0");
|
||||
if (waitResponse() != 1) {
|
||||
|
||||
@@ -144,9 +144,28 @@ class TinyGsmM590 : public TinyGsmModem<TinyGsmM590>,
|
||||
}
|
||||
}
|
||||
|
||||
// Doesn't support CGMI
|
||||
// This is extracted from the modem info
|
||||
String getModemNameImpl() {
|
||||
return "Neoway M590";
|
||||
sendAT(GF("I"));
|
||||
String factory = stream.readStringUntil('\n'); // read the factory
|
||||
factory.trim();
|
||||
String model = stream.readStringUntil('\n'); // read the model
|
||||
model.trim();
|
||||
streamSkipUntil('\n'); // skip the revision
|
||||
waitResponse(); // wait for the OK
|
||||
return factory + String(" ") + model;
|
||||
}
|
||||
|
||||
// Gets the modem firmware version
|
||||
// This is extracted from the modem info
|
||||
String getModemFirmwareVersionImpl() {
|
||||
sendAT(GF("I"));
|
||||
streamSkipUntil('\n'); // skip the factory
|
||||
streamSkipUntil('\n'); // skip the model
|
||||
String res = stream.readStringUntil('\n'); // read the revision
|
||||
res.trim();
|
||||
waitResponse(); // wait for the OK
|
||||
return res;
|
||||
}
|
||||
|
||||
// Extra stuff here - pwr save, internal stack
|
||||
|
||||
@@ -382,6 +382,25 @@ class TinyGsmXBee : public TinyGsmModem<TinyGsmXBee>,
|
||||
return getBeeName();
|
||||
}
|
||||
|
||||
// Gets the modem serial number
|
||||
String getModemSerialNumberImpl() {
|
||||
String xbeeSnLow =
|
||||
sendATGetString(GF("SL")); // Request Module MAC/Serial Number Low
|
||||
String xbeeSnHigh =
|
||||
sendATGetString(GF("SH")); // Request Module MAC/Serial Number High
|
||||
return xbeeSnLow + String(" ") + xbeeSnHigh;
|
||||
}
|
||||
|
||||
// Gets the modem hardware version
|
||||
String getModemHardwareVersionImpl() {
|
||||
return sendATGetString(GF("HV"));
|
||||
}
|
||||
|
||||
// Gets the modem firmware version
|
||||
String getModemFirmwareVersionImpl() {
|
||||
return sendATGetString(GF("VR"));
|
||||
}
|
||||
|
||||
void setBaudImpl(uint32_t baud) {
|
||||
XBEE_COMMAND_START_DECORATOR(5, )
|
||||
bool changesMade = false;
|
||||
|
||||
@@ -100,6 +100,18 @@ class TinyGsmModem {
|
||||
String getModemName() {
|
||||
return thisModem().getModemNameImpl();
|
||||
}
|
||||
// Gets the modem serial number
|
||||
String getModemSerialNumber() {
|
||||
return thisModem().getModemSerialNumberImpl();
|
||||
}
|
||||
// Gets the modem hardware version
|
||||
String getModemHardwareVersion() {
|
||||
return thisModem().getModemHardwareVersionImpl();
|
||||
}
|
||||
// Gets the modem firmware version
|
||||
String getModemFirmwareVersion() {
|
||||
return thisModem().getModemFirmwareVersionImpl();
|
||||
}
|
||||
bool factoryDefault() {
|
||||
return thisModem().factoryDefaultImpl();
|
||||
}
|
||||
@@ -293,6 +305,48 @@ class TinyGsmModem {
|
||||
return name;
|
||||
}
|
||||
|
||||
// Gets the modem serial number
|
||||
String getModemSerialNumberImpl() {
|
||||
thisModem().sendAT(GF("CGSN"));
|
||||
String res;
|
||||
if (thisModem().waitResponse(1000L, res) != 1) { return ""; }
|
||||
// Do the replaces twice so we cover both \r and \r\n type endings
|
||||
res.replace("\r\nOK\r\n", "");
|
||||
res.replace("\rOK\r", "");
|
||||
res.replace("\r\n", " ");
|
||||
res.replace("\r", " ");
|
||||
res.trim();
|
||||
return res;
|
||||
}
|
||||
|
||||
// Gets the modem hardware version
|
||||
String getModemHardwareVersionImpl() {
|
||||
thisModem().sendAT(GF("CGMM"));
|
||||
String res;
|
||||
if (thisModem().waitResponse(1000L, res) != 1) { return ""; }
|
||||
// Do the replaces twice so we cover both \r and \r\n type endings
|
||||
res.replace("\r\nOK\r\n", "");
|
||||
res.replace("\rOK\r", "");
|
||||
res.replace("\r\n", " ");
|
||||
res.replace("\r", " ");
|
||||
res.trim();
|
||||
return res;
|
||||
}
|
||||
|
||||
// Gets the modem firmware version
|
||||
String getModemFirmwareVersionImpl() {
|
||||
thisModem().sendAT(GF("CGMR"));
|
||||
String res;
|
||||
if (thisModem().waitResponse(1000L, res) != 1) { return ""; }
|
||||
// Do the replaces twice so we cover both \r and \r\n type endings
|
||||
res.replace("\r\nOK\r\n", "");
|
||||
res.replace("\rOK\r", "");
|
||||
res.replace("\r\n", " ");
|
||||
res.replace("\r", " ");
|
||||
res.trim();
|
||||
return res;
|
||||
}
|
||||
|
||||
bool factoryDefaultImpl() {
|
||||
thisModem().sendAT(GF("&FZE0&W")); // Factory + Reset + Echo Off + Write
|
||||
thisModem().waitResponse();
|
||||
|
||||
Reference in New Issue
Block a user