GSM 函式库

GSM 函式库从 86Duino Coding 103 开始支援。

如何连接 86Duino 和 Arduino GSM shield 可以参考这篇教学

86Duino 连接了 Arduino GSM shield 后,配合 GSM 函式库可以实现手机大部分的功能,像是播打/接听电话、收发简讯、连上 GPRS 网路。

Arduino GSM shield 上有一个数据机把从 86Duino 接收到的资料传送到 GSM 网路。Arduino GSM shield 的数据机上有串列埠(UART),要控制 Arduino GSM shield 时,必须传送 AT 指令到这个串列埠。GSM 函式库把 AT 指令包装成简单易懂的函式,像是播打电话如果用 AT 指令做,可能需要下好几个 AT 指令并且做额外的判断,使用 GSM 函式库只要用一个函式就可以打电话。

函式库结构

GSM 函式库有许多功能,这些功能可以区分为以下七大类别:

  • GSM 类别完成初始化 Arduino GSM shield 并连接上 GSM 网路的功能,接着才能使用其他的功能(如:收发简讯),因此要使用其他的 GSM/GPRS 功能之前必须先使用 GSM 类别完成基础的设定。
  • GSMVoiceCall 类别提供播打/接听电话相关的功能。
  • GSM_SMS 类别提供收发简讯相关的功能。
  • GPRSClass 类别用来连接网路。
  • GSMClient 实作用户端用来连线至伺服端,该函式库与 EthernetWiFi 函式库类似。
  • GSMServer 实作伺服端用来接收用户端的请求,该函式库与 EthernetWiFi 函式库类似。(注:如果你发现有些操作在内部网路可以,可是在外部网路不行,检视一下操作使用到的资料是否有限制)
  • 剩下还有几个可以拿来当工具用的类别,一共有四个:GSMModemGSMScannerGSMPINGSMBand

Ethernet 函式库相容

GSM 函式库试着相容于 Ethernet 函式库,如果要把原本使用 EthernetWiFi 函式库写成的程式移植成使用 GSM 函式库应该可以简单的完成。但有时没办法在完全不修改的情况下完成移植,做一些轻微的修改是必要的。

GSM 类别

该类别提供函式用来初始化 Arduino GSM shield

GSM
begin()
shutdown()

GSMVoiceCall 类别

该类别提供函式完成电话相关功能,使用电话功能时必须加上麦克风和喇叭

GSMVoiceCall
getVoiceCallStatus()
ready()
voiceCall()
answerCall()
hangCall()
retrieveCallingNumber()

GSM_SMS 类别

该类别提供函式完成简讯(Short Message Service, SMS)相关功能

GSM_SMS
beginSMS()
ready()
endSMS()
available()
remoteNumber()
read()
write()
print()
peek()
flush()

GPRS 类别

该类别提供函式以 TCP 协定连接网路

GPRS
attachGPRS()

GSMClient 类别

该类别实作用户端,藉以连接伺服端并与之沟通

GSMClient
ready()
connect()
beginWrite()
write()
endWrite()
connected()
read()
available()
peek()
flush()
stop()

GSMServer 类别

该类别实作伺服端,藉以处理用户端的请求

GSMServer
ready()
beginWrite()
write()
endWrite()
read()
available()
stop()

GSMModem 类别

该类别提供函式诊断 Arduino GSM shield 的状态

GSMModem
begin()
getIMEI()

GSMScanner 类别

该类别提供函式诊断电信网路的状态

GSMScanner
begin()
getCurrentCarrier()
getSignalStrength()
readNetworks()

GSMPIN 类别

该类别提供函式处理与 SIM 卡沟通的功能

GSMPIN
begin()
isPIN()
checkPIN()
checkPUK()
changePIN()
switchPIN()
checkReg()
getPINUsed()
setPINUsed()

GSMBand 类别

该类别提供函式设定和取得 Arduino GSM shield 目前使用的频段

GSMBand
begin()
getBand()
setBand()

范例

以下是 Arduino 使用 GSM 函式库的范例,这些范例在 86Duino 上都可以正常运作:

Make Voice Call:播打电话到透过序列埠监控视窗输入的电话号码
Receive Voice Call:监控是否有来电,如果侦测到有来电就接听
Send SMS:透过序列埠监控视窗输入电话号码和简讯内容,接着传送简讯
Receive SMS:监控是否有收到简讯,收到简讯时把简讯内容输出到序列埠监控视窗


函式库参考主页面

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.