An application to log WiFi SSIDs for position lookup testing

Dependencies:   C027_Support SWO mbed-rtos mbed picojson

Fork of lpc4088_ebb_ublox_Cellular_PubNubDemo_rtos by EmbeddedArtists AB

Committer:
rosterloh84
Date:
Sun Feb 15 22:04:12 2015 +0000
Revision:
1:cac9b2960637
Parent:
PubNubDemo.cpp@0:713518ea5028
First working version. Lots to do still.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:713518ea5028 1 #include "mbed.h"
embeddedartists 0:713518ea5028 2 #include "rtos.h"
embeddedartists 0:713518ea5028 3 #include "MDM.h"
rosterloh84 1:cac9b2960637 4 #include "GPS.h"
rosterloh84 1:cac9b2960637 5 #include "DeviceInfo.h"
rosterloh84 1:cac9b2960637 6 #include "DeviceMemory.h"
rosterloh84 1:cac9b2960637 7 #include "MbedAgent.h"
rosterloh84 1:cac9b2960637 8 #include "GPSTracker.h"
rosterloh84 1:cac9b2960637 9 #include "DeviceConfiguration.h"
embeddedartists 0:713518ea5028 10
rosterloh84 1:cac9b2960637 11 #include <stdio.h>
embeddedartists 0:713518ea5028 12
rosterloh84 1:cac9b2960637 13 // ----------------------------------------------------------------
rosterloh84 1:cac9b2960637 14 // Cellular modem / SIM parameters
rosterloh84 1:cac9b2960637 15 // ----------------------------------------------------------------
rosterloh84 1:cac9b2960637 16 #include "MDM.h"
rosterloh84 1:cac9b2960637 17 #define SIMPIN NULL //!< Set your secret SIM pin here (e.g. "1234"). Check your SIM manual.
rosterloh84 1:cac9b2960637 18 #define APN "internet" //!< The APN of your network operator SIM, sometimes it is "internet"
rosterloh84 1:cac9b2960637 19 #define USERNAME NULL //!< Set the user name for your APN, or NULL if not needed
rosterloh84 1:cac9b2960637 20 #define PASSWORD NULL //!< Set the password for your APN, or NULL if not needed
embeddedartists 0:713518ea5028 21
rosterloh84 1:cac9b2960637 22 // ----------------------------------------------------------------
rosterloh84 1:cac9b2960637 23 // PubNub Config
rosterloh84 1:cac9b2960637 24 // ----------------------------------------------------------------
rosterloh84 1:cac9b2960637 25 //#include "PubNub.h"
rosterloh84 1:cac9b2960637 26 //const char pubkey[] = "pub-c-e3a95948-182a-46fd-b5f3-52c184eb3c12";
rosterloh84 1:cac9b2960637 27 //const char subkey[] = "sub-c-0313f6b2-b2c0-11e4-ab0e-02ee2ddab7fe";
rosterloh84 1:cac9b2960637 28 //const char channel[] = "mbed";
rosterloh84 1:cac9b2960637 29 //const char channel_pub[] = "mbed_data";
rosterloh84 1:cac9b2960637 30 //const char channel_sub[] = "mbed_cmd";
embeddedartists 0:713518ea5028 31
embeddedartists 0:713518ea5028 32 int main()
embeddedartists 0:713518ea5028 33 {
rosterloh84 1:cac9b2960637 34 MDMParser::DevStatus devStatus;
rosterloh84 1:cac9b2960637 35 uint8_t status = 0;
rosterloh84 1:cac9b2960637 36
rosterloh84 1:cac9b2960637 37 MDMRtos<MDMSerial> mdm;
rosterloh84 1:cac9b2960637 38 GPSI2C gps;
rosterloh84 1:cac9b2960637 39
rosterloh84 1:cac9b2960637 40 //mdm.setDebug(4);
rosterloh84 1:cac9b2960637 41
rosterloh84 1:cac9b2960637 42 if (!mdm.init(SIMPIN, &devStatus))
rosterloh84 1:cac9b2960637 43 status = 1;
rosterloh84 1:cac9b2960637 44 else if (!gps.init())
rosterloh84 1:cac9b2960637 45 status = 2;
rosterloh84 1:cac9b2960637 46
rosterloh84 1:cac9b2960637 47 DeviceIO io(gps);
rosterloh84 1:cac9b2960637 48
rosterloh84 1:cac9b2960637 49 /** For debugging, you may find it useful to print memory usage
rosterloh84 1:cac9b2960637 50 * stats. AvailableMemory may be flaky, but the following is nice.
rosterloh84 1:cac9b2960637 51 * It will get printed to the USB serial port interface.
rosterloh84 1:cac9b2960637 52 */
rosterloh84 1:cac9b2960637 53 //io.debugPrint("%d: ", __LINE__); __heapstats((__heapprt)fprintf, stdout);
rosterloh84 1:cac9b2960637 54
rosterloh84 1:cac9b2960637 55 io.debugPrint("\r\nWiFi Scanner build " __DATE__ " " __TIME__ "\r\n");
rosterloh84 1:cac9b2960637 56 //io.debugPrint("CPU SystemCoreClock is %d Hz\r\n", SystemCoreClock);
rosterloh84 1:cac9b2960637 57
rosterloh84 1:cac9b2960637 58 switch (status) {
rosterloh84 1:cac9b2960637 59 case 1:
rosterloh84 1:cac9b2960637 60 io.debugPrint("MODEM INIT FAILURE. CHECK SIM");
rosterloh84 1:cac9b2960637 61 break;
rosterloh84 1:cac9b2960637 62 case 2:
rosterloh84 1:cac9b2960637 63 io.debugPrint("GPS INIT FAILURE");
rosterloh84 1:cac9b2960637 64 break;
embeddedartists 0:713518ea5028 65 }
embeddedartists 0:713518ea5028 66
rosterloh84 1:cac9b2960637 67 if (status != 0)
rosterloh84 1:cac9b2960637 68 goto error;
rosterloh84 1:cac9b2960637 69
rosterloh84 1:cac9b2960637 70 io.debugPrint("DEVICE INIT");
embeddedartists 0:713518ea5028 71
rosterloh84 1:cac9b2960637 72 //io.debugPrint("REGISTER NETWORK. IMEI: %s", devStatus.imei);
embeddedartists 0:713518ea5028 73
rosterloh84 1:cac9b2960637 74 if (!mdm.registerNet()) {
rosterloh84 1:cac9b2960637 75 io.debugPrint("NETWORK REG ERROR");
rosterloh84 1:cac9b2960637 76 goto error;
embeddedartists 0:713518ea5028 77 }
embeddedartists 0:713518ea5028 78
rosterloh84 1:cac9b2960637 79 io.debugPrint("JOIN NETWORK");
rosterloh84 1:cac9b2960637 80 #ifdef SIM_APN
rosterloh84 1:cac9b2960637 81 if (mdm.join(SIM_APN, SIM_USER, SIM_PASS) == NOIP) {
rosterloh84 1:cac9b2960637 82 #else
rosterloh84 1:cac9b2960637 83 if (mdm.join() == NOIP) {
rosterloh84 1:cac9b2960637 84 #endif
rosterloh84 1:cac9b2960637 85 io.debugPrint("NETWORK JOIN FAILURE");
rosterloh84 1:cac9b2960637 86 goto error;
rosterloh84 1:cac9b2960637 87 }
rosterloh84 1:cac9b2960637 88
rosterloh84 1:cac9b2960637 89 {
rosterloh84 1:cac9b2960637 90 uint8_t tries;
rosterloh84 1:cac9b2960637 91 DeviceInfo deviceInfo(mdm, devStatus);
rosterloh84 1:cac9b2960637 92 DeviceMemory deviceMemory(mdm);
rosterloh84 1:cac9b2960637 93
rosterloh84 1:cac9b2960637 94 if (io.userButtonPressed()) {
rosterloh84 1:cac9b2960637 95 if (deviceMemory.resetConfiguration())
rosterloh84 1:cac9b2960637 96 io.deviceFeedback().showSuccess();
rosterloh84 1:cac9b2960637 97 else
rosterloh84 1:cac9b2960637 98 io.deviceFeedback().showFailure();
rosterloh84 1:cac9b2960637 99 Thread::wait(1000);
rosterloh84 1:cac9b2960637 100 return 0;
rosterloh84 1:cac9b2960637 101 }
rosterloh84 1:cac9b2960637 102
rosterloh84 1:cac9b2960637 103 MbedAgent agent(io, mdm, deviceInfo, deviceMemory);
rosterloh84 1:cac9b2960637 104
rosterloh84 1:cac9b2960637 105 io.debugPrint("AGENT INIT");
rosterloh84 1:cac9b2960637 106 if (!agent.init()) {
rosterloh84 1:cac9b2960637 107 io.debugPrint("AGENT INIT FAILURE");
rosterloh84 1:cac9b2960637 108 goto error;
rosterloh84 1:cac9b2960637 109 }
rosterloh84 1:cac9b2960637 110
rosterloh84 1:cac9b2960637 111 tries = 3;
rosterloh84 1:cac9b2960637 112 do {
rosterloh84 1:cac9b2960637 113 io.debugPrint("AGENT RUN");
rosterloh84 1:cac9b2960637 114 if (agent.run())
rosterloh84 1:cac9b2960637 115 break;
rosterloh84 1:cac9b2960637 116 } while (--tries > 0);
rosterloh84 1:cac9b2960637 117
rosterloh84 1:cac9b2960637 118 if (tries == 0) {
rosterloh84 1:cac9b2960637 119 io.debugPrint("AGENT RUN FAILURE");
rosterloh84 1:cac9b2960637 120 goto error;
embeddedartists 0:713518ea5028 121 }
embeddedartists 0:713518ea5028 122 }
embeddedartists 0:713518ea5028 123
rosterloh84 1:cac9b2960637 124 mdm.disconnect();
rosterloh84 1:cac9b2960637 125 return 0;
embeddedartists 0:713518ea5028 126
rosterloh84 1:cac9b2960637 127 error:
embeddedartists 0:713518ea5028 128 mdm.disconnect();
rosterloh84 1:cac9b2960637 129 return 1;
embeddedartists 0:713518ea5028 130 }