0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

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

Last updated at Posted at 2023-01-13

こちらのプログラムを改造して、コマンドを連続で流せるようにしました。
ESP32: ATコマンドを使う

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

ATI
AT+CGMI
AT+CGMM

AT+CGSN
AT+CSUB
AT+CGMR

AT+CSQ
AT+CPIN?
AT+CNMP?

プログラム

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

実行結果

>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

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?