Example program for MTS Universal Socked Modem Shield and WiFi Shield. Test that you can connect to Axeda with your account.

Dependencies:   AxedaWrapper SocketModem mbed

Fork of axeda_wrapper_dev by Mike Fiore

Committer:
mfiore
Date:
Sun Jan 05 05:56:03 2014 +0000
Revision:
4:bb9bfd6be913
Parent:
2:8c58dd4197c6
Child:
5:e1ac66f8cd26
update SocketModem library; remove wait before calling Cellular::init()

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mfiore 0:5b04479914b6 1 #include "mbed.h"
mfiore 0:5b04479914b6 2 #include "include_me.h"
mfiore 0:5b04479914b6 3 #include "AxedaWrapper.h"
mfiore 0:5b04479914b6 4
mfiore 0:5b04479914b6 5 // set to 1 for cellular shield board
mfiore 0:5b04479914b6 6 // set to 0 for wifi shield board
sam_grove 2:8c58dd4197c6 7 #define CELL_SHIELD 0
sam_grove 2:8c58dd4197c6 8
sam_grove 2:8c58dd4197c6 9 std::string ssid = "belkin54g";
mfiore 0:5b04479914b6 10
mfiore 0:5b04479914b6 11 using namespace mts;
mfiore 0:5b04479914b6 12
mfiore 0:5b04479914b6 13 int main() {
mfiore 0:5b04479914b6 14 #if CELL_SHIELD
mfiore 0:5b04479914b6 15 MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8);
mfiore 0:5b04479914b6 16 serial->baud(115200);
mfiore 0:5b04479914b6 17 Transport::setTransport(Transport::CELLULAR);
mfiore 0:5b04479914b6 18 Cellular* cell = Cellular::getInstance();
mfiore 1:f0b38aa21aaf 19 cell->init(serial, PTA4, PTC9);
mfiore 0:5b04479914b6 20
mfiore 0:5b04479914b6 21 int max_tries = 5;
mfiore 0:5b04479914b6 22 int i;
mfiore 0:5b04479914b6 23 std::string apn = "wap.cingular";
mfiore 0:5b04479914b6 24
mfiore 0:5b04479914b6 25 i = 0;
mfiore 0:5b04479914b6 26 while (i++ < max_tries) {
mfiore 0:5b04479914b6 27 if (cell->getRegistration() == Cellular::REGISTERED) {
mfiore 0:5b04479914b6 28 printf("registered with tower\n\r");
mfiore 0:5b04479914b6 29 break;
mfiore 0:5b04479914b6 30 } else if (i >= max_tries) {
mfiore 0:5b04479914b6 31 printf("failed to register with tower\n\r");
mfiore 0:5b04479914b6 32 } else {
mfiore 0:5b04479914b6 33 wait(3);
mfiore 0:5b04479914b6 34 }
mfiore 0:5b04479914b6 35 }
mfiore 0:5b04479914b6 36
mfiore 0:5b04479914b6 37 printf("signal strength: %d\n\r", cell->getSignalStrength());
mfiore 0:5b04479914b6 38
mfiore 0:5b04479914b6 39 i = 0;
mfiore 0:5b04479914b6 40 printf("setting APN to %s\n\r", apn.c_str());
mfiore 0:5b04479914b6 41 while (i++ < max_tries) {
mfiore 0:5b04479914b6 42 if (cell->setApn(apn) == SUCCESS) {
mfiore 0:5b04479914b6 43 printf("successfully set APN\n\r");
mfiore 0:5b04479914b6 44 break;
mfiore 0:5b04479914b6 45 } else if (i >= max_tries) {
mfiore 0:5b04479914b6 46 printf("failed to set APN\n\r");
mfiore 0:5b04479914b6 47 } else {
mfiore 0:5b04479914b6 48 wait(1);
mfiore 0:5b04479914b6 49 }
mfiore 0:5b04479914b6 50 }
mfiore 0:5b04479914b6 51
mfiore 0:5b04479914b6 52 i = 0;
mfiore 0:5b04479914b6 53 printf("bringing up PPP link\n\r");
mfiore 0:5b04479914b6 54 while (i++ < max_tries) {
mfiore 0:5b04479914b6 55 if (cell->connect()) {
mfiore 0:5b04479914b6 56 printf("PPP link is up\n\r");
mfiore 0:5b04479914b6 57 break;
mfiore 0:5b04479914b6 58 } else if (i >= max_tries) {
mfiore 0:5b04479914b6 59 printf("failed to bring PPP link up\n\r");
mfiore 0:5b04479914b6 60 } else {
mfiore 0:5b04479914b6 61 wait(1);
mfiore 0:5b04479914b6 62 }
mfiore 0:5b04479914b6 63 }
mfiore 0:5b04479914b6 64 #else
mfiore 0:5b04479914b6 65 for (int i = 6; i >= 0; i = i - 2) {
mfiore 0:5b04479914b6 66 wait(2);
mfiore 0:5b04479914b6 67 printf("Waiting %d seconds...\n\r", i);
mfiore 0:5b04479914b6 68 }
mfiore 0:5b04479914b6 69 MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256);
mfiore 0:5b04479914b6 70 serial->baud(9600);
mfiore 0:5b04479914b6 71 Transport::setTransport(Transport::WIFI);
mfiore 0:5b04479914b6 72 Wifi* wifi = Wifi::getInstance();
mfiore 0:5b04479914b6 73 printf("Init: %s\n\r", wifi->init(serial) ? "SUCCESS" : "FAILURE");
sam_grove 2:8c58dd4197c6 74 printf("Set Network: %s\n\r", getCodeNames(wifi->setNetwork(ssid, Wifi::NONE, "")).c_str());
mfiore 0:5b04479914b6 75 printf("Set DHCP: %s\n\r", getCodeNames(wifi->setDeviceIP("DHCP")).c_str());
mfiore 0:5b04479914b6 76 printf("Signal Strnegth (dBm): %d\n\r", wifi->getSignalStrength());
mfiore 0:5b04479914b6 77 printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False");
mfiore 0:5b04479914b6 78 printf("Connect: %s\n\r", wifi->connect() ? "Success" : "Failure");
mfiore 0:5b04479914b6 79 printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False");
mfiore 0:5b04479914b6 80 #endif
mfiore 0:5b04479914b6 81
sam_grove 2:8c58dd4197c6 82 std::string serial_num = "MWF-0001";
mfiore 0:5b04479914b6 83 AxedaWrapper* client = new AxedaWrapper(serial_num);
mfiore 0:5b04479914b6 84 bool retval;
mfiore 0:5b04479914b6 85 while (true) {
mfiore 0:5b04479914b6 86 int val = rand();
mfiore 0:5b04479914b6 87 printf("sending %d\r\n", val);
mfiore 0:5b04479914b6 88 retval = client->send("test", val);
mfiore 0:5b04479914b6 89 printf("%s\n\r", retval ? "succeeded" : "failed");
mfiore 0:5b04479914b6 90 wait(5);
mfiore 0:5b04479914b6 91 }
mfiore 0:5b04479914b6 92
mfiore 0:5b04479914b6 93 return 0;
mfiore 0:5b04479914b6 94 }