ESP32: ATコマンドを使う

こちらのページを参考にしました。
[LILYGO® TTGO T-PCIEを購入](https://lang-ship.com/blog/work/lilygo-ttgo-t-pcie/)

[SIM7600JCｰH](http://www.cathay.jp/product/lte/sim7600jc-h.html)
で確認しました。
![SIM7600JC-H.jpg](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/42f7b9b2-5ff4-5b87-a051-626043831bd3.jpeg)


## [プログラム]

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

						Jan/12/2023
*/
// ---------------------------------------------------------------------
#define SerialAT Serial1
#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
// ---------------------------------------------------------------------
void setup()
{
	Serial.begin(115200);
	delay(100);
	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(3000);
	SerialAT.begin(UART_BAUD, SERIAL_8N1, PIN_RX, PIN_TX);
	Serial.println("*** setup end	***");
}

// ---------------------------------------------------------------------
void loop()
{
	while (Serial.available()) {
		String command = Serial.readStringUntil('\n');
		Serial.print(">");
		Serial.println(command);
		SerialAT.println(command);
	}

	while (SerialAT.available()) {
		Serial.write(SerialAT.read());
	}
}

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

## [初期化]
電源投入後、次のメッセージがシリアルポートに流れます。

```text
RDY

+CPIN: READY

SMS DONE

PB DONE
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/c81320a9-97b1-fb95-2288-d03c01d05e5f.png)

## [動作確認]
AT

```text
>AT
AT

OK
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/2075f5cd-8c84-784f-a360-32377302f7ce.png)

## [情報表示]
ATI

```text
>ATI
ATI

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

OK
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/7e5c1a22-f380-0b2a-b288-9f45590b5d39.png)


## [電波状況確認]
AT+CSQ

```text
>AT+CSQ
AT+CSQ

+CSQ: 31,99

OK
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/70fdea8f-28d0-b87b-6582-83bb876ba8ca.png)

## [基地局確認]
AT+COPS=?

```text
>AT+COPS=?
AT+COPS=?

+COPS: (2,"IIJ","IIJ","44010",7),(3,"440 52","440 52","44052",7),(3,"441 00","441 00","44100",7),(3,"SoftBank","SoftBank","44020",7),(3,"KDDI","KDDI","44050",7),(3,"440 11","440 11","44011",7),(1,"440 54","440 54","44054",7),(3,"KDDI","KDDI","44051",7),(3,"440 00","440 00","44000",7),,(0,1,2,3,4,5),(0,1,2)

OK
```

![image.png](https://qiita-image-store.s3.ap-northeast-1.amazonaws.com/0/179446/822db1c8-9ef0-c7c5-27f6-d970561d24bd.png)

## [接続確認]
AT+CPSI?

```text
>AT+CPSI?
AT+CPSI?
+CPSI: LTE,Online,440-10,0x1705,45640784,291,EUTRAN-BAND3,1850,5,5,-97,-774,-478,17

OK
```

## [PING確認]
AT+CPING=”www.baidu.com”,1,4,64,1000,10000,255

```text
>AT+CPING="www.baidu.com",1,4,64,1000,10000,255
AT+CPING="www.baidu.com",1,4,64,1000,10000,255
OK

+CPING: 1,119.63.197.151,64,89,255

+CPING: 1,119.63.197.151,64,75,255

+CPING: 1,119.63.197.151,64,75,255

+CPING: 1,119.63.197.151,64,74,255

+CPING: 3,4,4,0,74,89,77
```

## [HTTPS通信]

```text
AT+HTTPINIT
AT+HTTPPARA="URL","https://ekzemplaro.org"
AT+HTTPACTION=0
AT+HTTPHEAD
AT+HTTPTERM
```

```text
AT+HTTPINIT
AT+HTTPPARA="URL","https://yahoo.co.jp"
AT+HTTPACTION=0
AT+HTTPHEAD
AT+HTTPTERM
```

```text
AT+HTTPINIT
AT+HTTPPARA="URL","https://asahi.com"
AT+HTTPACTION=0
AT+HTTPHEAD
AT+HTTPTERM
```

実行結果

```text
>AT+HTTPINIT
AT+HTTPINIT
OK
>
>AT+HTTPPARA="URL","https://ekzemplaro.org"
AT+HTTPPARA="URL","https://ekzemplaro.org"
OK
>AT+HTTPACTION=0
AT+HTTPACTION=0
OK

+HTTPACTION: 0,200,2327
>AT+HTTPHEAD
AT+HTTPHEAD
+HTTPHEAD: DATA,234
HTTP/1.1 200 OK
Server: nginx/1.22.1
Date: Thu, 12 Jan 2023 04:29:18 GMT
Content-Type: text/html
Content-Length: 2327
Last-Modified: Sat, 12 Nov 2022 22:30:25 GMT
Connection: close
ETag: "63701e81-917"
Accept-Ranges: bytes


OK
>AT+HTTPTERM
AT+HTTPTERM
OK
```