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: AxedaWrapper SocketModem mbed
Fork of axeda_wrapper_dev by
main.cpp
00001 #include "mbed.h" 00002 #include "include_me.h" 00003 #include "AxedaWrapper.h" 00004 00005 // set to 1 for cellular shield board 00006 // set to 0 for wifi shield board 00007 #define CELL_SHIELD 1 00008 00009 // wifi ssid and phrase for event 00010 std::string ssid = "belkin54g"; 00011 std::string phrase = "hackathon"; 00012 00013 // https://connect.axeda.com/apps/connectiontest/index.html#login 00014 std::string serial_num = "ATT_Summit_Hackathon"; // add your serial number here but test with this 00015 00016 using namespace mts; 00017 00018 int main() { 00019 #if CELL_SHIELD 00020 MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8); 00021 serial->baud(115200); 00022 Transport::setTransport(Transport::CELLULAR); 00023 Cellular* cell = Cellular::getInstance(); 00024 cell->init(serial, PTA4, PTC9); 00025 00026 int max_tries = 5; 00027 int i; 00028 std::string apn = "wap.cingular"; 00029 00030 i = 0; 00031 while (i++ < max_tries) { 00032 if (cell->getRegistration() == Cellular::REGISTERED) { 00033 printf("registered with tower\n\r"); 00034 break; 00035 } else if (i >= max_tries) { 00036 printf("failed to register with tower\n\r"); 00037 } else { 00038 wait(3); 00039 } 00040 } 00041 00042 printf("signal strength: %d\n\r", cell->getSignalStrength()); 00043 00044 i = 0; 00045 printf("setting APN to %s\n\r", apn.c_str()); 00046 while (i++ < max_tries) { 00047 if (cell->setApn(apn) == SUCCESS) { 00048 printf("successfully set APN\n\r"); 00049 break; 00050 } else if (i >= max_tries) { 00051 printf("failed to set APN\n\r"); 00052 } else { 00053 wait(1); 00054 } 00055 } 00056 00057 i = 0; 00058 printf("bringing up PPP link\n\r"); 00059 while (i++ < max_tries) { 00060 if (cell->connect()) { 00061 printf("PPP link is up\n\r"); 00062 break; 00063 } else if (i >= max_tries) { 00064 printf("failed to bring PPP link up\n\r"); 00065 } else { 00066 wait(1); 00067 } 00068 } 00069 #else 00070 for (int i = 6; i >= 0; i = i - 2) { 00071 wait(2); 00072 printf("Waiting %d seconds...\n\r", i); 00073 } 00074 MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256); 00075 serial->baud(9600); 00076 Transport::setTransport(Transport::WIFI); 00077 Wifi* wifi = Wifi::getInstance(); 00078 printf("Init: %s\n\r", wifi->init(serial) ? "SUCCESS" : "FAILURE"); 00079 printf("Set Network: %s\n\r", getCodeNames(wifi->setNetwork(ssid, Wifi::WPA, phrase)).c_str()); 00080 printf("Set DHCP: %s\n\r", getCodeNames(wifi->setDeviceIP("DHCP")).c_str()); 00081 printf("Signal Strnegth (dBm): %d\n\r", wifi->getSignalStrength()); 00082 printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False"); 00083 printf("Connect: %s\n\r", wifi->connect() ? "Success" : "Failure"); 00084 printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False"); 00085 #endif 00086 00087 AxedaWrapper* client = new AxedaWrapper(serial_num); 00088 bool retval; 00089 while (true) { 00090 int val = rand(); 00091 printf("sending %d\r\n", val); 00092 retval = client->send("test", val); 00093 printf("%s\n\r", retval ? "succeeded" : "failed"); 00094 wait(5); 00095 } 00096 00097 return 0; 00098 }
Generated on Sun Jul 17 2022 01:40:56 by
1.7.2
