begin()
描述
連接到 GSM 網路。
語法
gsm.begin()
gsm.begin(pin)
gsm.begin(pin, restart)
gsm.begin(pin, restart, sync)
參數
pin:儲存 PIN 碼的字元陣列,預設為 0
restart :如果 restart 為 true 會重新啟動 Arduino GSM shield,接著再初始化,反之則不會重新啟動,直接初始化。restart 預設為 true,型態為 boolean
sync:如果 sync 為 true 則為同步(synchronous)模式,反之為非同步(asynchronous)模式,sync 預設為 true,型態為 boolean
回傳
char:如果是非同步狀態回傳 0;如果是同步狀態,回傳連線的狀態:ERROR, IDLE, CONNECTING, GSM_READY, GPRS_READY, TRANSPARENT_CONNECTED
範例
#include <GSM.h>
#define PINNUMBER ""
GSM gsm;
void setup()
{
// 初始化 Serial
Serial.begin(9600);
// 連線狀態
boolean notConnected = true;
// 啟動 Arduino GSM shield,如果你的 SIM 卡有 PIN 碼,請當作 begin() 的參數
while(notConnected)
{
if(gsm.begin(PINNUMBER)==GSM_READY)
notConnected = false;
else
{
Serial.println("Not connected");
delay(1000);
}
}
Serial.println("GSM initialized");
}
void loop()
{
// 不做任何事
}
See also
- GSM constructor
- shutdown()
The text of the 86Duino reference is a modification of the Arduino reference, and is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.
