ESP32: ATコマンドを使う (その２)

こちらのプログラムを改造して、コマンドを連続で流せるようにしました。
[ESP32: ATコマンドを使う](https://qiita.com/ekzemplaro/items/78339b09d9fa8c4281ee)

次のコマンドを実行します。

```text
ATI
AT+CGMI
AT+CGMM

AT+CGSN
AT+CSUB
AT+CGMR

AT+CSQ
AT+CPIN?
AT+CNMP?
```


## プログラム

```text:at_test.ino
// ---------------------------------------------------------------------
/*
	at_test.ino

						Jan/14/2023
*/
// ---------------------------------------------------------------------
#define SerialBB Serial1
// #define SerialBB Serial2

#define PIN_TX                  27
#define PIN_RX                  26
#define UART_BAUD               115200
#define PWR_PIN                 4
#define LED_PIN                 12
#define POWER_PIN               25
#define IND_PIN                 36
// ---------------------------------------------------------------------
boolean wait_ready_proc()
{
	boolean rvalue = false;

	int it = 0;

	char xxch[160];

	while (SerialBB.available()) {
		xxch[it] = SerialBB.read();
		it++;	
		}

	xxch[it] = '\0';

	String ssx = String(xxch);

	int llx = ssx.length();

	if (0< llx)
		{
		Serial.println(xxch);
		int ppx = ssx.indexOf('P');
		if (0 < ppx)
			{
			Serial.println(ppx);
			Serial.println(ssx[ppx]);
			Serial.println("*** P ***");
			Serial.println("*** PB DONE ***");
			rvalue = true;
			}
		}

	return rvalue;
}

// ---------------------------------------------------------------------
void setup()
{
	Serial.begin(115200);
	delay(500);
	Serial.println("*** setup() start	***");
	// Onboard LED light, it can be used freely
	pinMode(LED_PIN, OUTPUT);
	digitalWrite(LED_PIN, LOW);
	// POWER_PIN : This pin controls the power supply of the SIM7600
	pinMode(POWER_PIN, OUTPUT);
	digitalWrite(POWER_PIN, HIGH);
	// PWR_PIN ： This Pin is the PWR-KEY of the SIM7600
	// The time of active low level impulse of PWRKEY pin to power on module , type 500 ms
	pinMode(PWR_PIN, OUTPUT);
	digitalWrite(PWR_PIN, HIGH);
	delay(500);
	digitalWrite(PWR_PIN, LOW);
	delay(2000);
	SerialBB.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);
	delay(3000);
	Serial.println("*** setup() ppp	***"); 

	Serial.println("*** wait loop start ***");
	while(1)
		{
		if (wait_ready_proc())
			{
			break;
			}
		delay(2000);
		}
	Serial.println("*** wait loop end ***");

	delay(2000);
	Serial.println("*** setup() end	***");
}

// ---------------------------------------------------------------------
void loop()
{
	String commands[] = {"ATI","AT+CGMI","AT+CGMM","AT+CGSN","AT+CSUB",
		"AT+CGMR","AT+CSQ","AT+CPIN?","AT+CNMP?"};

	for (int it=0; it<9; it++)
		{
		Serial.print(">");
		Serial.println(commands[it]);
		SerialBB.println(commands[it]);
		delay(100);
		while (SerialBB.available()) {
			Serial.write(SerialBB.read());
			}
		Serial.println("-------------------");
		delay(3000);
		}

	Serial.println("-------------------");
	delay(8000);
}

// ---------------------------------------------------------------------
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/6ccfc44c-1b37-d1cf-939c-6b2d394de543.png)


## 実行結果

```text
>ATI
ATI
Manufacturer: SIMCOM INCORPORATED
Model: SIMCOM_SIM7600JC-H
Revision: SIM7600JC-H_V1.1
IMEI: 860371050882459
+GCAP: +CGSM

OK
-------------------
>AT+CGMI
AT+CGMI
SIMCOM INCORPORATED

OK
-------------------
>AT+CGMM
AT+CGMM
SIMCOM_SIM7600JC-H

OK
-------------------
>AT+CGSN
AT+CGSN
860371050882459

OK
-------------------
>AT+CSUB
AT+CSUB
+CSUB: B02V07
+CSUB: MDM9x07_JC-H_22_V1.07_190819

OK
-------------------
>AT+CGMR
AT+CGMR
+CGMR: LE11B02SIM7600JC-H

OK
-------------------
>AT+CSQ
AT+CSQ
+CSQ: 31,99

OK
-------------------
>AT+CPIN?
AT+CPIN?
+CPIN: READY

OK
-------------------
>AT+CNMP?
AT+CNMP?
+CNMP: 38

OK
-------------------
-------------------
```

## 参考情報
[Common AT Command](https://www.waveshare.com/wiki/SIM7600E-H_4G_HAT#Common_AT_Command)