Помогите найти библиотеку или написать свою функцию, чтобы определять нижеперечисленные параметры сотовой сети: MobileCountryCode MobileNetworkCode carrier cellId locationAreaCode Связка arduino uno и sim900R (GPRS shield)
Теоретически выдать в последовательный порт, на котором сидит модуль: AT+CENG=2 дождаться OK AT+CENG? Если команды модулем поддерживаются, то из последовательного порта модуля будет непрерывно валить такая информация: Первая строка выдачи (похоже - данные по БС, к которой подключен модуль): Код (Text): +CENG: <cell>,”<arfcn>,<rxl>,<rxq>,<mcc>,<mnc>,<bsic>,<cellid>,<lac>,<rla>,<txp>,<TA>” Последующие (похоже - остальные видимые БС) Код (Text): +CENG: <cell>,”<arfcn>,<rxl>,<bsic>,<Lac>” где Код (Text): <Ncell> - 0 un-display neighbor cell ID, 1 display neighbor cell ID <cell> - 0 the serving cell, 1-6 the index of the neighboring cell. <arfcn> - absolute radio frequency channel number. <rxl> - receive level. <rxq> - receive quality. <mcc> - mobile country code. <mnc> - mobile network code. <bsic> - base station identity code <cellid> - cell id. <lac> - location area code <rla> - receive level access minimum. <txp> - transmit power maximum CCCH. <TA> - Timing Advance Чтобы остановить выдачу - AT+CENG=0 в последовательный порт модуля
Самый простой способ -ручками в терминале. ☺ В примерах есть как отправить АТ команду это просто, а вот получить ответ и потом его разложить тут будет проблема.
Код для искры нео и амперковского GPRS шилда. Для других ардуин и шилдов все примерно так же с поправкой на особенности плат. В частности, тут для инициализации использована амперковская библиотека. Вместо этого у вас может использоваться непосредственная отправка инициализирующих команд и проверка их результатов (или просто паузы после команд на включение, выполнение соединения с сетью и завершение инициализации) в соответствии с тем, как оно обычно делается для имеющихся у вас ардуины и шилда. Код написан в предположении, что cellid шестнадцатеричное число, а остальные параметры - десятичные числа. Возможно, что это предположение неверно, и некоторые параметры придется интерпретировать так же, как и cellid. Спойлер: Код Код (C): #include <SoftwareSerial.h> #include <GPRS_Shield_Arduino.h> GPRS gprs(9600); void setup() { // put your setup code here, to run once: Serial.begin(115200); // порт для обмена с ПК //Serial1.begin(9600); // порт для обмена с шилдом if (!gprs.checkPowerUp()) { // включение шилда, если он выключен gprs.powerUpDown(); } while (!gprs.init()) { // инициализация шилда delay(1000); Serial.print("Init error"); } Serial.println("Init OK"); delay(100); Serial1.println("AT+CENG=2"); // включение инженерного режима delay(100); Serial1.println("AT+CENG?"); delay(100); while (Serial1.available()) Serial.read(); } String str = ""; void loop() { // put your main code here, to run repeatedly: if (Serial1.available()) { char c = Serial1.read(); if ((c != '\n') && (c != '\r')) { str += c; } else { if (str.startsWith("+CENG:")) // выдача инженерного режима { //<cell>,”<arfcn>,<rxl>,<rxq>,<mcc>,<mnc>,<bsic>,<cellid>,<lac>,<rla>,<txp>,<TA>” //<cell>,”<arfcn>,<rxl>,<bsic>,<Lac>” int cell; int arfcn; int rxl; int rxq; int mcc; int mnc; int bsic; int cellid; int lac; int rla; int txp; int TA; str = str.substring(6); Serial.println(str); // <cell> int tmppos = str.indexOf(','); cell = str.substring(0, tmppos).toInt(); Serial.print("cell="); Serial.println(cell); // arfcn int tmppos2 = str.indexOf(',', tmppos + 1); arfcn = str.substring(tmppos + 2, tmppos2).toInt(); Serial.print("arfcn="); Serial.println(arfcn); tmppos = tmppos2; // rxl tmppos2 = str.indexOf(',', tmppos + 1); rxl = str.substring(tmppos + 1, tmppos2).toInt(); Serial.print("rxl="); Serial.println(rxl); tmppos = tmppos2; if (cell) { // short string // bsic tmppos2 = str.indexOf(',', tmppos + 1); bsic = str.substring(tmppos + 1, tmppos2).toInt(); Serial.print("bsic="); Serial.println(bsic); tmppos = tmppos2; // Lac tmppos2 = str.indexOf('"', tmppos + 1); lac = str.substring(tmppos + 1, tmppos2).toInt(); Serial.print("lac="); Serial.println(lac); tmppos = tmppos2; } else { // long string // rxq tmppos2 = str.indexOf(',', tmppos + 1); rxq = str.substring(tmppos + 1, tmppos2).toInt(); Serial.print("rxq="); Serial.println(rxq); tmppos = tmppos2; // mcc tmppos2 = str.indexOf(',', tmppos + 1); mcc = str.substring(tmppos + 1, tmppos2).toInt(); Serial.print("mcc="); Serial.println(mcc); tmppos = tmppos2; // mnc tmppos2 = str.indexOf(',', tmppos + 1); mnc = str.substring(tmppos + 1, tmppos2).toInt(); Serial.print("mnc="); Serial.println(mnc); tmppos = tmppos2; // bsic tmppos2 = str.indexOf(',', tmppos + 1); bsic = str.substring(tmppos + 1, tmppos2).toInt(); Serial.print("bsic="); Serial.println(bsic); tmppos = tmppos2; // cellid tmppos2 = str.indexOf(',', tmppos + 1); cellid = HexStrToInt(str.substring(tmppos + 1, tmppos2)); Serial.print("cellid="); Serial.print(cellid); Serial.print(" ("); Serial.print(str.substring(tmppos + 1, tmppos2)); Serial.println(")"); tmppos = tmppos2; // lac tmppos2 = str.indexOf(',', tmppos + 1); lac = str.substring(tmppos + 1, tmppos2).toInt(); Serial.print("lac="); Serial.println(lac); tmppos = tmppos2; // rla tmppos2 = str.indexOf(',', tmppos + 1); rla = str.substring(tmppos + 1, tmppos2).toInt(); Serial.print("rla="); Serial.println(rla); tmppos = tmppos2; // txp tmppos2 = str.indexOf(',', tmppos + 1); txp = str.substring(tmppos + 1, tmppos2).toInt(); Serial.print("txp="); Serial.println(txp); tmppos = tmppos2; // TA tmppos2 = str.indexOf('"', tmppos + 1); TA = str.substring(tmppos + 1, tmppos2).toInt(); Serial.print("TA="); Serial.println(TA); } } str = ""; } } } int HexStrToInt(String S) { int res = 0; for (byte i = 0; i < S.length(); ++i) { if (('0' <= S.charAt(i)) && ((S.charAt(i) <= '9'))) { res = res * 16 + (S.charAt(i) - '0'); } if (('a' <= S.charAt(i)) && ((S.charAt(i) <= 'f'))) { res = res * 16 + (S.charAt(i) - 'a' + 10); } if (('A' <= S.charAt(i)) && ((S.charAt(i) <= 'F'))) { res = res * 16 + (S.charAt(i) - 'A' + 10); } } return (res); }