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
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 using namespace mts; 00010 00011 int main() { 00012 #if CELL_SHIELD 00013 for (int i = 30; i >= 0; i = i - 2) { 00014 wait(2); 00015 printf("Waiting %d seconds...\n\r", i); 00016 } 00017 00018 MTSSerialFlowControl* serial = new MTSSerialFlowControl(PTD3, PTD2, PTA12, PTC8); 00019 serial->baud(115200); 00020 Transport::setTransport(Transport::CELLULAR); 00021 Cellular* cell = Cellular::getInstance(); 00022 cell->init(serial, PTA4, PTC9); 00023 00024 int max_tries = 5; 00025 int i; 00026 std::string apn = "wap.cingular"; 00027 00028 i = 0; 00029 while (i++ < max_tries) { 00030 if (cell->getRegistration() == Cellular::REGISTERED) { 00031 printf("registered with tower\n\r"); 00032 break; 00033 } else if (i >= max_tries) { 00034 printf("failed to register with tower\n\r"); 00035 } else { 00036 wait(3); 00037 } 00038 } 00039 00040 printf("signal strength: %d\n\r", cell->getSignalStrength()); 00041 00042 i = 0; 00043 printf("setting APN to %s\n\r", apn.c_str()); 00044 while (i++ < max_tries) { 00045 if (cell->setApn(apn) == SUCCESS) { 00046 printf("successfully set APN\n\r"); 00047 break; 00048 } else if (i >= max_tries) { 00049 printf("failed to set APN\n\r"); 00050 } else { 00051 wait(1); 00052 } 00053 } 00054 00055 i = 0; 00056 printf("bringing up PPP link\n\r"); 00057 while (i++ < max_tries) { 00058 if (cell->connect()) { 00059 printf("PPP link is up\n\r"); 00060 break; 00061 } else if (i >= max_tries) { 00062 printf("failed to bring PPP link up\n\r"); 00063 } else { 00064 wait(1); 00065 } 00066 } 00067 #else 00068 for (int i = 6; i >= 0; i = i - 2) { 00069 wait(2); 00070 printf("Waiting %d seconds...\n\r", i); 00071 } 00072 MTSSerial* serial = new MTSSerial(PTD3, PTD2, 256, 256); 00073 serial->baud(9600); 00074 Transport::setTransport(Transport::WIFI); 00075 Wifi* wifi = Wifi::getInstance(); 00076 printf("Init: %s\n\r", wifi->init(serial) ? "SUCCESS" : "FAILURE"); 00077 printf("Set Network: %s\n\r", getCodeNames(wifi->setNetwork("", Wifi::WPA2, "")).c_str()); 00078 printf("Set DHCP: %s\n\r", getCodeNames(wifi->setDeviceIP("DHCP")).c_str()); 00079 printf("Signal Strnegth (dBm): %d\n\r", wifi->getSignalStrength()); 00080 printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False"); 00081 printf("Connect: %s\n\r", wifi->connect() ? "Success" : "Failure"); 00082 printf("Is Connected: %s\n\r", wifi->isConnected() ? "True" : "False"); 00083 #endif 00084 00085 std::string serial_num = ""; 00086 AxedaWrapper* client = new AxedaWrapper(serial_num); 00087 //AxedaWrapper* client = new AxedaWrapper(serial_num, "mbed", "54.235.103.204"); 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 Mon Jul 25 2022 21:12:51 by
1.7.2