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.
Dependencies: mbed SocketModem nanoservice_client_1_12
main.cpp
- Committer:
- zdshelby
- Date:
- 2014-02-17
- Revision:
- 1:5147d3fa7816
- Parent:
- 0:f739ace74102
- Child:
- 2:1592223f12e1
File content as of revision 1:5147d3fa7816:
#include "mbed.h"
#include "config.h"
#include "debug.h"
// Multitech Cellular includes
#include "Cellular.h"
#include "Endpoint.h"
#include "IPStack.h"
#include "MTSSerialFlowControl.h"
using namespace mts;
Cellular* cellular;
// ****************************************************************************
// Cellular initialization
static void cellular_init()
{
//Setup serial interface to radio
MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
serial->baud(115200);
//Setup Cellular class
cellular = Cellular::getInstance();
cellular->init(serial, PTA4, PTC9); //DCD and DTR pins for KL46Z
//Run status and configuration commands
DEBUG("\n\r////Start Status and Configuration Commands////");
DEBUG("Command Test: %s", getCodeNames(cellular->test()).c_str()); //Make sure you can talk to the radio
DEBUG("Signal Strength: %d", cellular->getSignalStrength()); //Check the signal strength should be above 8
//Makes sure you are reistered with cell
DEBUG("Registration State: %s", Cellular::getRegistrationNames(cellular->getRegistration()).c_str());
//Shows example of how to send other commands, look at AT command guide for more info
DEBUG("Send Basic Command (AT): %s", getCodeNames(cellular->sendBasicCommand("AT", 1000)).c_str());
DEBUG("Send Command (AT+CSQ): %s", cellular->sendCommand("AT+CSQ", 1000).c_str());
//Start Test
DEBUG("\n\r////Start Network Connectivity Test////");
DEBUG("Set APN: %s", getCodeNames(cellular->setApn(CELLULAR_APN)).c_str()); //Use APN from service provider!!!
//Setup a data connection
DEBUG("Attempting to Connect, this may take some time...");
while (!cellular->connect()) {
DEBUG("Failed to connect... Trying again.");
wait(1);
}
DEBUG("Connected to the Network!");
//Try pinging default server "8.8.8.8" (Google's DNS)
DEBUG("Ping Valid: %s", cellular->ping() ? "true" : "false");
wait(3);
}
// ****************************************************************************
// NSP initialization
static void nsp_init()
{
// Bind the port
cellular->bind(EP_PORT);
// Open a TCP connection
while (!cellular->open(NSP_ADDRESS, NSP_PORT, mts::IPStack::TCP))
{
DEBUG("TCP connection failed.");
wait(3);
}
DEBUG("TCP connection to NSP successful.");
cellular->write("test", 4, -1);
// nsp.set_address(NSP_ADDRESS, NSP_PORT);
// DEBUG("name: %s", endpoint_name);
// DEBUG("NSP=%s - port %d\n", NSP_ADDRESS, NSP_PORT);
}
int main()
{
printf("\r\n*****************************************************************************\r\n");
DEBUG("NanoService Example for KL46Z + Multitech Cellular");
// Inititalize the Cellular modem
cellular_init();
// Bind the socket and configure NSP settings
nsp_init();
}
