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 MTS-Cellular by
Diff: Cellular/Cellular.h
- Revision:
- 53:1aee5fe47adb
- Parent:
- 52:2cb58398a4f9
- Child:
- 56:43205bd2752a
--- a/Cellular/Cellular.h Mon Aug 11 16:03:19 2014 +0000 +++ b/Cellular/Cellular.h Mon Aug 11 16:27:27 2014 +0000 @@ -28,124 +28,210 @@ * status AT commands with the radio, create a data connection and test it: * @code * #include "mbed.h" -* #include "mtech.h" -* -* using namespace mts; -* -* main() { -* //Setup serial interface to radio -* MTSSerialFlowControl* serial = new MTSSerialFlowControl(YOUR_TXD, YOUR_RXD, YOUR_RTS, YOUR_CTS); -* serial->baud(YOUR_BAUD); -* -* //Setup Cellular class - Select your radio type -* Cellular* cellular = new UniversalIP(); -* //Cellular cellular = new TelitIP(); -* cellular->init(serial); -* -* //Run status and configuration commands -* printf("\n\r////Start Status and Configuration Commands////\n\r"); -* printf("Command Test: %s\n\r", getCodeNames(cellular->test()).c_str()); -* wait(1); -* printf("Signal Strength: %d\n\r", cellular->getSignalStrength()); -* wait(1); -* printf("Registration State: %s\n\r", Cellular::getRegistrationNames(cellular->getRegistration()).c_str()); -* wait(1); -* printf("Send Basic Command (AT): %s\n\r", getCodeNames(cellular->sendBasicCommand("AT", 1000)).c_str()); -* wait(1); -* printf("Send Command (AT+CSQ): %s\n\r", cellular->sendCommand("AT+CSQ", 1000).c_str()); -* wait(1); -* -* //Start Test -* printf("\n\r////Start Network Connectivity Test////\n\r"); -* printf("Set APN: %s\n\r", getCodeNames(cellular->setApn("wap.cingular")).c_str()); //Use APN from service provider!!! +* #include "mtsas.h" * -* //Setup a data connection -* printf("Attempting to Connect, this may take some time...\n\r"); -* while (!cellular->connect()) { -* printf("Failed to connect... Trying again.\n\r"); -* wait(1); -* } -* printf("Connected to the Network!\n\r"); -* -* //Try pinging default server "8.8.8.8" -* printf("Ping Valid: %s\n\r", cellular->ping() ? "true" : "false"); +* int main(){ +* //Modify to match your apn if you are using an HSPA radio with a SIM card +* const char APN[] = ""; +* +* //Sets the log level to INFO, higher log levels produce more log output. +* //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE +* MTSLog::setLogLevel(MTSLog::INFO_LEVEL); +* +* // STMicro Nucelo F401RE +* // The supported jumper configurations of the MTSAS do not line up with +* // the pin mapping of the Nucleo F401RE. Therefore, the MTSAS serial TX +* // pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2) +* // and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to +* // Serial1 TX (Shield pin D8). +* // Uncomment the following line to use the STMicro Nuceleo F401RE +* // +* MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6); +* +* // Freescale KL46Z +* // To configure the pins for the Freescale KL46Z board, use configuration B +* // Uncomment the following line to use the Freescale KL46Z board +* // +* //MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6); +* +* // Freescale K64F +* // To configure the pins for the Freescale KL46Z board, use configuration A +* // Uncomment the following line to use the Freescale KL46F board +* // +* //MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6); +* +* //Sets the baud rate for communicating with the radio +* io->baud(115200); +* +* //Create radio object +* Cellular* radio = CellularFactory::create(io); +* radio->configureSignals(D4,D7,RESET); +* Transport::setTransport(radio); +* +* if (! radio) { +* logFatal("Failed to initialize radio"); +* return 1; +* } +* +* //Set radio APN +* for (int i = 0; i < 10; i++) { +* if (i >= 10) { +* logError("Failed to set APN to %s", APN); +* } +* if (radio->setApn(APN) == MTS_SUCCESS) { +* logInfo("Successfully set APN to %s", APN); +* break; +* } else { +* wait(1); +* } +* } +* +* //Establish PPP link +* for (int i = 0; i < 10; i++) { +* if (i >= 10) { +* logError("Failed to establish PPP link"); +* } +* if (radio->connect() == true) { +* logInfo("Successfully established PPP link"); +* break; +* } else { +* wait(1); +* } +* } +* +* //Ping google.com +* for (int i = 0; i < 10; i++) { +* if (i >= 10) { +* logError("Failed to ping www.google.com"); +* } +* if (radio->ping("www.google.com") == true) { +* logInfo("Successfully pinged www.google.com"); +* break; +* } else { +* wait(1); +* } +* } +* +* //Disconnect ppp link +* radio->disconnect(); +* +* logInfo("End of example code"); +* return 0; +* } * -* //Perform HTTP transfer over TCP socket connection -* printf("Open Connection: %s\n\r", cellular->open("echo.200please.com", 80, IPStack::TCP) ? "Success" : "Failure"); -* printf("Performing HTTP GET on echo.200please.com\n\r"); -* string httpGET = "GET / HTTP/1.1\r\nHost: echo.200please.com\r\nConnection: keep-alive\r\n\r\n"; -* printf("Wrote %d of %d bytes\n\r", cellular->write(httpGET.data(), httpGET.size(), 2000), httpGET.size()); -* char buffer[256]; -* buffer[255] = '\0'; -* printf("Read %d bytes\n\r", cellular->read(buffer, 255, 2000)); -* printf("HTTP Response:\n\r %s", buffer); -* wait(1); -* printf("Close Connection: %s\n\r", cellular->close() ? "Success" : "Failure"); -* -* //Disconnect from network -* printf("Disconnecting...\n\r"); -* cellular->disconnect(); -* printf("Is Connected: %s\n\r", cellular->isConnected() ? "True" : "False"); -* -* printf("End Program\n\r"); -* } * @endcode * -* The following set of example code demonstrates how process SMS messages: +* The following set of example code demonstrates how to process SMS messages: * @code * #include "mbed.h" -* #include "mtech.h" -* -* using namespace mts; -* -* main() { -* //Setup serial interface to radio -* MTSSerialFlowControl* serial = new MTSSerialFlowControl(YOUR_TXD, YOUR_RXD, YOUR_RTS, YOUR_CTS); -* serial->baud(YOUR_BAUD); -* -* //Setup Cellular class -* //Setup Cellular class - Select your radio type -* Cellular* cellular = new UniversalIP(); -* //Cellular cellular = new TelitIP(); -* cellular->init(serial); -* -* //Start test -* printf("AT Test: %s\n\r", getCodeNames(cellular->test()).c_str()); -* -* //Waiting for network registration -* printf("Checking Network Registration, this may take some time...\n\r"); -* while (cellular->getRegistration() != Cellular::REGISTERED) { -* printf("Still waiting... Checking again.\n\r"); -* wait(1); -* } -* printf("Connected to the Network!\n\r"); +* #include "mtsas.h" * -* //Send SMS Message -* Code code; -* std::string sMsg("Hello from Multi-Tech MBED!"); -* std::string sPhoneNum("16128675309"); //Put your phone number here or leave Jenny's... -* -* printf("Sending message [%s] to [%s]\r\n", sMsg.c_str(), sPhoneNum.c_str()); -* code = cellular->sendSMS(sPhoneNum, sMsg); -* -* if(code != SUCCESS) { -* printf("Error during SMS send [%s]\r\n", getCodeNames(code).c_str()); -* } else { -* printf("Success!\r\n"); -* } -* -* //Try and receive SMS messages -* //To determine your radio's phone number send yourself an SMS and check the received # -* printf("Checking Received Messages\r\n"); -* while (true) { -* std::vector<Cellular::Sms> vSms = cellular->getReceivedSms(); -* printf("\r\n"); -* for(unsigned int i = 0; i < vSms.size(); i++) { -* printf("[%d][%s][%s][%s]\r\n", i, vSms[i].timestamp.c_str(), -* vSms[i].phoneNumber.c_str(), vSms[i].message.c_str()); -* } -* wait(10); -* } +* int main(){ +* +* //Sets the log level to INFO, higher log levels produce more log output. +* //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE +* MTSLog::setLogLevel(MTSLog::INFO_LEVEL); +* +* //Modify to match your apn if you are using an HSPA radio with a SIM card +* const char APN[] = ""; +* +* //Phone number to send to and receive from. Must be in the form "1xxxxxxxxxx" +* string PHONE_NUMBER = ""; +* +* Cellular::Sms txtmsg; +* txtmsg.phoneNumber = PHONE_NUMBER; +* txtmsg.message = "Hello World! MTSAS is up and running!"; +* +* // STMicro Nucelo F401RE +* // The supported jumper configurations of the MTSAS do not line up with +* // the pin mapping of the Nucleo F401RE. Therefore, the MTSAS serial TX +* // pin (JP8 Pin 2) must be manually jumped to Serial1 RX (Shield pin D2) +* // and the MTSAS serial RX pin (JP9 Pin 2) pin must be manually jumped to +* // Serial1 TX (Shield pin D8). +* // Uncomment the following line to use the STMicro Nuceleo F401RE +* // +* MTSSerialFlowControl* io = new MTSSerialFlowControl(D8, D2, D3, D6); +* +* // Freescale KL46Z +* // To configure the pins for the Freescale KL46Z board, use configuration B +* // Uncomment the following line to use the Freescale KL46Z board +* // +* //MTSSerialFlowControl* io = new MTSSerialFlowControl(D2, D9, D3, D6); +* +* // Freescale K64F +* // To configure the pins for the Freescale KL46Z board, use configuration A +* // Uncomment the following line to use the Freescale KL46F board +* // +* //MTSSerialFlowControl* io = new MTSSerialFlowControl(D1, D0, D3, D6); +* +* //Sets the baudrate for communicating with the radio +* io->baud(115200); +* +* //Creates a radio object +* Cellular* radio = CellularFactory::create(io); +* radio->configureSignals(D4,D7,RESET); +* Transport::setTransport(radio); +* +* if (! radio) { +* logFatal("Failed to initialize radio"); +* return 1; +* } +* +* //Set radio APN +* for (int i = 0; i < 10; i++) { +* if (i >= 10) { +* logError("Failed to set APN\n"); +* } +* if (radio->setApn(APN) == MTS_SUCCESS) { +* logInfo("Successfully set APN\n"); +* break; +* } else { +* wait(1); +* } +* } +* +* //Delete any previously received SMS messages +* for (int i = 0; i < 10; i++) { +* if (i >= 10) { +* logError("Failed to delete SMS messages\n"); +* } +* if (radio->deleteAllReceivedSms() == MTS_SUCCESS) { +* logInfo("Deleted all SMS messages\n"); +* break; +* } else { +* wait(1); +* } +* } +* +* // Send SMS message to phone +* for (int i = 1; i < 10; i++) { +* if(radio->sendSMS(txtmsg) == MTS_SUCCESS) { +* logInfo("Sent SMS successfully:<%s>\n", txtmsg.message.c_str()); +* break; +* } else { +* logError("Failed to send SMS<%s>\n", txtmsg.message.c_str()); +* } +* } +* +* //Checking for received SMS messages +* while (true) { +* logInfo("Checking for received messages"); +* vector<Cellular::Sms> recv = radio->getReceivedSms(); +* if(recv.size() > 0) { +* int size = recv.size(); +* for (int i = 0; i < size; i++) { +* logInfo("Message %d: [%s] [%s] [%s]", i, recv[i].phoneNumber.c_str(), recv[i].timestamp.c_str(), recv[i].message.c_str()); +* } +* } +* +* if(radio->deleteOnlyReceivedReadSms() != MTS_SUCCESS) { +* logError("Failed to delete received and read SMS messages"); +* } +* wait(10); +* } +* +* logDebug("End of example code\n"); +* return 0; * } * @endcode */ @@ -321,9 +407,9 @@ * @param state Echo mode is off (an argument of 1 turns echos off, anything else turns echo on) * @returns standard Code enumeration */ - virtual Code echo(bool state)=0; //Implemented the same way in both UIP and EasyIP, + virtual Code echo(bool state) = 0; //Implemented the same way in both UIP and EasyIP, //and thus could be moved to cellular class - virtual Code setSocketCloseable(bool enabled)=0; + virtual Code setSocketCloseable(bool enabled) = 0; protected: MTSBufferedIO* io; //IO interface obect that the radio is accessed through.