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:
jengbrecht
Date:
Wed Jan 22 23:26:00 2014 +0000
Revision:
7:fa654f793f27
Parent:
5:e1ac66f8cd26
Updated SocketModem library version.

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