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:
sam_grove
Date:
Sat Jan 04 21:09:42 2014 +0000
Revision:
3:7ba95d6503e4
Parent:
2:8c58dd4197c6
Child:
5:e1ac66f8cd26
Getting starting with Axeda

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