Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ARCH_GPRS_Demo by
You are viewing an older revision! See the latest version
Homepage
GPRS¶
the GPRS interface is used to realize mobile communication. It offers APIs such as call up/ send SMS/ TCP connecting etc.
main.cpp¶
#include "mbed.h"
#include "string.h"
#include "gprs.h"
#define TRUE 1
#define FALSE 0
#define SERIAL_DEBUG 0
#define SEND_SMS_TEST 0
#define CALL_UP_TEST 0
#define ANSWER_TEST 0
#define READ_SMS_TEST 0
#define TCP_TEST 0
#define IP_ADDRSS "42.96.164.52"
#define PORT "80"
#define PINPWR P1_2 // power on EG 10, low enable
#define PINONOFF P1_7 // switch of EG10, low enable, low for 2s to turn on EG10
DigitalOut eg10_pwr(PINPWR);
DigitalOut eg10_on(PINONOFF);
gprs gprsTest(P0_19, P0_18, 115200,"139****7382");
void EG10_PowerUp(void)
{
eg10_pwr = 1;
eg10_on = 1;
wait(2);
eg10_pwr = 0;
eg10_on = 0;
wait(2);
eg10_on = 1;
wait(2);
}
int main(void)
{
EG10_PowerUp();
gprsTest.init();
wait(2);
#if CALL_UP_TEST
gprsTest.callUp("139****7382");
#endif
#if SEND_SMS_TEST
gprsTest.sendSMS("13925257382","hello,lawliet");
#endif
#if ANSWER_TEST || READ_SMS_TEST
gprsTest.loop(FALSE);
#endif
#if TCP_TEST
gprsTest.connectTCP(IP_ADDRSS,PORT);
#endif
#if SERIAL_DEBUG
gprsTest.serialDebug(USBTX,USBRX);
#endif
return 0;
}
APIS¶
Import library
Public Member Functions |
|
| GPRS (PinName tx, PinName rx, int baudRate, char *number) | |
|
Create
GPRS
instance.
|
|
| int | init (void) |
|
init
GPRS
module including SIM card check & signal strength & network check
|
|
| int | readBuffer (char *buffer, int count) |
|
read from
GPRS
module and save to buffer array
|
|
| void | sendCmd (char *cmd) |
|
send AT command to
GPRS
module
|
|
| int | waitForResp (char *resp, int timeout) |
|
check
GPRS
module response before timeout
|
|
| int | sendCmdAndWaitForResp (char *cmd, char *resp, int timeout) |
|
send AT command to
GPRS
module and wait for correct response
|
|
| int | checkSIMStatus (void) |
|
check SIM card' Status
|
|
| int | checkSignalStrength (void) |
|
check signal strength
|
|
| int | networkInit (void) |
|
check network is ok or not
|
|
| int | sendSMS (char *number, char *data) |
|
send text SMS
|
|
| int | readSMS (char *buffer, char *message, bool check) |
|
read SMS if get a SMS
|
|
| int | deleteSMS (int index) |
|
delete SMS message on SIM card
|
|
| int | callUp (char *number) |
|
call someone
|
|
| int | answer (void) |
|
auto answer if coming a call
|
|
| int | loop (bool check) |
|
a loop to wait for some event.
|
|
| int | connectTCP (char *ip, char *port) |
|
build TCP connect
|
|
| int | sendTCPData (char *data) |
|
send data to TCP server
|
|
| int | closeTCP (void) |
|
close TCP connection
|
|
| int | shutTCP (void) |
|
close TCP service
|
|
| void | serialDebug (PinName tx, PinName rx) |
|
used for serial debug, you can specify tx and rx pin and then communicate with
GPRS
module with common AT commands
|
|
