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: C027_Support SWO mbed-rtos mbed picojson
Fork of lpc4088_ebb_ublox_Cellular_PubNubDemo_rtos by
main.cpp
00001 #include "mbed.h" 00002 #include "rtos.h" 00003 #include "MDM.h" 00004 #include "GPS.h" 00005 #include "DeviceInfo.h" 00006 #include "DeviceMemory.h" 00007 #include "MbedAgent.h" 00008 #include "GPSTracker.h" 00009 #include "DeviceConfiguration.h" 00010 00011 #include <stdio.h> 00012 00013 // ---------------------------------------------------------------- 00014 // Cellular modem / SIM parameters 00015 // ---------------------------------------------------------------- 00016 #include "MDM.h" 00017 #define SIMPIN NULL //!< Set your secret SIM pin here (e.g. "1234"). Check your SIM manual. 00018 #define APN "internet" //!< The APN of your network operator SIM, sometimes it is "internet" 00019 #define USERNAME NULL //!< Set the user name for your APN, or NULL if not needed 00020 #define PASSWORD NULL //!< Set the password for your APN, or NULL if not needed 00021 00022 // ---------------------------------------------------------------- 00023 // PubNub Config 00024 // ---------------------------------------------------------------- 00025 //#include "PubNub.h" 00026 //const char pubkey[] = "pub-c-e3a95948-182a-46fd-b5f3-52c184eb3c12"; 00027 //const char subkey[] = "sub-c-0313f6b2-b2c0-11e4-ab0e-02ee2ddab7fe"; 00028 //const char channel[] = "mbed"; 00029 //const char channel_pub[] = "mbed_data"; 00030 //const char channel_sub[] = "mbed_cmd"; 00031 00032 int main() 00033 { 00034 MDMParser::DevStatus devStatus; 00035 uint8_t status = 0; 00036 00037 MDMRtos<MDMSerial> mdm; 00038 GPSI2C gps; 00039 00040 //mdm.setDebug(4); 00041 00042 if (!mdm.init(SIMPIN, &devStatus)) 00043 status = 1; 00044 else if (!gps.init()) 00045 status = 2; 00046 00047 DeviceIO io(gps); 00048 00049 /** For debugging, you may find it useful to print memory usage 00050 * stats. AvailableMemory may be flaky, but the following is nice. 00051 * It will get printed to the USB serial port interface. 00052 */ 00053 //io.debugPrint("%d: ", __LINE__); __heapstats((__heapprt)fprintf, stdout); 00054 00055 io.debugPrint("\r\nWiFi Scanner build " __DATE__ " " __TIME__ "\r\n"); 00056 //io.debugPrint("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock); 00057 00058 switch (status) { 00059 case 1: 00060 io.debugPrint("MODEM INIT FAILURE. CHECK SIM"); 00061 break; 00062 case 2: 00063 io.debugPrint("GPS INIT FAILURE"); 00064 break; 00065 } 00066 00067 if (status != 0) 00068 goto error; 00069 00070 io.debugPrint("DEVICE INIT"); 00071 00072 //io.debugPrint("REGISTER NETWORK. IMEI: %s", devStatus.imei); 00073 00074 if (!mdm.registerNet()) { 00075 io.debugPrint("NETWORK REG ERROR"); 00076 goto error; 00077 } 00078 00079 io.debugPrint("JOIN NETWORK"); 00080 #ifdef SIM_APN 00081 if (mdm.join(SIM_APN, SIM_USER, SIM_PASS) == NOIP) { 00082 #else 00083 if (mdm.join() == NOIP) { 00084 #endif 00085 io.debugPrint("NETWORK JOIN FAILURE"); 00086 goto error; 00087 } 00088 00089 { 00090 uint8_t tries; 00091 DeviceInfo deviceInfo(mdm, devStatus); 00092 DeviceMemory deviceMemory(mdm); 00093 00094 if (io.userButtonPressed()) { 00095 if (deviceMemory.resetConfiguration()) 00096 io.deviceFeedback().showSuccess(); 00097 else 00098 io.deviceFeedback().showFailure(); 00099 Thread::wait(1000); 00100 return 0; 00101 } 00102 00103 MbedAgent agent(io, mdm, deviceInfo, deviceMemory); 00104 00105 io.debugPrint("AGENT INIT"); 00106 if (!agent.init()) { 00107 io.debugPrint("AGENT INIT FAILURE"); 00108 goto error; 00109 } 00110 00111 tries = 3; 00112 do { 00113 io.debugPrint("AGENT RUN"); 00114 if (agent.run()) 00115 break; 00116 } while (--tries > 0); 00117 00118 if (tries == 0) { 00119 io.debugPrint("AGENT RUN FAILURE"); 00120 goto error; 00121 } 00122 } 00123 00124 mdm.disconnect(); 00125 return 0; 00126 00127 error: 00128 mdm.disconnect(); 00129 return 1; 00130 }
Generated on Sun Jul 17 2022 02:39:36 by
1.7.2
