Example program to demonstrate the use of the UbloxATCellularInterfaceExt class, providing FTP, HTTP, and CellLocate support. It may be used on the C027 and C030 (non-N2xx flavour) boards.
Dependencies: ublox-cellular-driver-gen gnss ublox-cellular-base ublox-at-cellular-interface-ext
main.cpp@27:bbd898975873, 2020-01-03 (annotated)
- Committer:
- fahimalavi
- Date:
- Fri Jan 03 16:29:58 2020 +0500
- Revision:
- 27:bbd898975873
- Parent:
- 20:3ca2d75614e6
Library version updated to fix test cases
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rob.meades@u-blox.com | 1:628f51c3511f | 1 | /* mbed Microcontroller Library |
rob.meades@u-blox.com | 1:628f51c3511f | 2 | * Copyright (c) 2017 u-blox |
rob.meades@u-blox.com | 1:628f51c3511f | 3 | * |
rob.meades@u-blox.com | 1:628f51c3511f | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
rob.meades@u-blox.com | 1:628f51c3511f | 5 | * you may not use this file except in compliance with the License. |
rob.meades@u-blox.com | 1:628f51c3511f | 6 | * You may obtain a copy of the License at |
rob.meades@u-blox.com | 1:628f51c3511f | 7 | * |
rob.meades@u-blox.com | 1:628f51c3511f | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
rob.meades@u-blox.com | 1:628f51c3511f | 9 | * |
rob.meades@u-blox.com | 1:628f51c3511f | 10 | * Unless required by applicable law or agreed to in writing, software |
rob.meades@u-blox.com | 1:628f51c3511f | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
rob.meades@u-blox.com | 1:628f51c3511f | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
rob.meades@u-blox.com | 1:628f51c3511f | 13 | * See the License for the specific language governing permissions and |
rob.meades@u-blox.com | 1:628f51c3511f | 14 | * limitations under the License. |
rob.meades@u-blox.com | 1:628f51c3511f | 15 | */ |
rob.meades@u-blox.com | 1:628f51c3511f | 16 | |
rob.meades@u-blox.com | 1:628f51c3511f | 17 | #include "mbed.h" |
rob.meades@u-blox.com | 1:628f51c3511f | 18 | #include "UbloxATCellularInterfaceExt.h" |
rob.meades@u-blox.com | 1:628f51c3511f | 19 | #include "gnss.h" |
rob.meades@u-blox.com | 1:628f51c3511f | 20 | |
rob.meades@u-blox.com | 1:628f51c3511f | 21 | // The credentials of the SIM in the board. If PIN checking is enabled |
rob.meades@u-blox.com | 1:628f51c3511f | 22 | // for your SIM card you must set this to the required PIN. |
rob.meades@u-blox.com | 1:628f51c3511f | 23 | #define PIN "0000" |
rob.meades@u-blox.com | 1:628f51c3511f | 24 | |
rob.meades@u-blox.com | 1:628f51c3511f | 25 | // Network credentials. You should set this according to your |
rob.meades@u-blox.com | 1:628f51c3511f | 26 | // network/SIM card. For C030 boards, leave the parameters as NULL |
rob.meades@u-blox.com | 1:628f51c3511f | 27 | // otherwise, if you do not know the APN for your network, you may |
rob.meades@u-blox.com | 4:13a84f6cc800 | 28 | // either try the fairly common "internet" for the APN (and leave the |
rob.meades@u-blox.com | 1:628f51c3511f | 29 | // username and password NULL), or you may leave all three as NULL and then |
rob.meades@u-blox.com | 1:628f51c3511f | 30 | // a lookup will be attempted for a small number of known networks |
rob.meades@u-blox.com | 1:628f51c3511f | 31 | // (see APN_db.h in mbed-os/features/netsocket/cellular/utils). |
rob.meades@u-blox.com | 1:628f51c3511f | 32 | #define APN NULL |
rob.meades@u-blox.com | 1:628f51c3511f | 33 | #define USERNAME NULL |
rob.meades@u-blox.com | 1:628f51c3511f | 34 | #define PASSWORD NULL |
rob.meades@u-blox.com | 1:628f51c3511f | 35 | |
rob.meades@u-blox.com | 1:628f51c3511f | 36 | // LEDs |
rob.meades@u-blox.com | 1:628f51c3511f | 37 | DigitalOut ledRed(LED1, 1); |
rob.meades@u-blox.com | 1:628f51c3511f | 38 | DigitalOut ledGreen(LED2, 1); |
rob.meades@u-blox.com | 1:628f51c3511f | 39 | DigitalOut ledBlue(LED3, 1); |
rob.meades@u-blox.com | 1:628f51c3511f | 40 | |
rob.meades@u-blox.com | 4:13a84f6cc800 | 41 | // The user button |
rob.meades@u-blox.com | 4:13a84f6cc800 | 42 | volatile bool buttonPressed = false; |
rob.meades@u-blox.com | 4:13a84f6cc800 | 43 | |
rob.meades@u-blox.com | 4:13a84f6cc800 | 44 | static void good() { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 45 | ledGreen = 0; |
rob.meades@u-blox.com | 4:13a84f6cc800 | 46 | ledBlue = 1; |
rob.meades@u-blox.com | 4:13a84f6cc800 | 47 | ledRed = 1; |
rob.meades@u-blox.com | 4:13a84f6cc800 | 48 | } |
rob.meades@u-blox.com | 4:13a84f6cc800 | 49 | |
rob.meades@u-blox.com | 4:13a84f6cc800 | 50 | static void bad() { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 51 | ledRed = 0; |
rob.meades@u-blox.com | 4:13a84f6cc800 | 52 | ledGreen = 1; |
rob.meades@u-blox.com | 4:13a84f6cc800 | 53 | ledBlue = 1; |
rob.meades@u-blox.com | 4:13a84f6cc800 | 54 | } |
rob.meades@u-blox.com | 4:13a84f6cc800 | 55 | |
rob.meades@u-blox.com | 4:13a84f6cc800 | 56 | static void event() { |
rob.meades@u-blox.com | 1:628f51c3511f | 57 | ledBlue = 0; |
rob.meades@u-blox.com | 1:628f51c3511f | 58 | ledRed = 1; |
rob.meades@u-blox.com | 1:628f51c3511f | 59 | ledGreen = 1; |
rob.meades@u-blox.com | 4:13a84f6cc800 | 60 | } |
rob.meades@u-blox.com | 4:13a84f6cc800 | 61 | |
rob.meades@u-blox.com | 4:13a84f6cc800 | 62 | static void pulseEvent() { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 63 | event(); |
rob.meades@u-blox.com | 1:628f51c3511f | 64 | wait_ms(500); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 65 | good(); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 66 | } |
rob.meades@u-blox.com | 4:13a84f6cc800 | 67 | |
rob.meades@u-blox.com | 4:13a84f6cc800 | 68 | static void ledOff() { |
rob.meades@u-blox.com | 1:628f51c3511f | 69 | ledBlue = 1; |
rob.meades@u-blox.com | 1:628f51c3511f | 70 | ledRed = 1; |
rob.meades@u-blox.com | 4:13a84f6cc800 | 71 | ledGreen = 1; |
rob.meades@u-blox.com | 1:628f51c3511f | 72 | } |
rob.meades@u-blox.com | 1:628f51c3511f | 73 | |
rob.meades@u-blox.com | 1:628f51c3511f | 74 | static void printCellLocateData(UbloxATCellularInterfaceExt::CellLocData *pData) |
rob.meades@u-blox.com | 1:628f51c3511f | 75 | { |
rob.meades@u-blox.com | 1:628f51c3511f | 76 | char timeString[25]; |
rob.meades@u-blox.com | 1:628f51c3511f | 77 | |
rob.meades@u-blox.com | 1:628f51c3511f | 78 | printf("Cell Locate data:\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 79 | if (strftime(timeString, sizeof(timeString), "%F %T", (const tm *) &(pData->time)) > 0) { |
rob.meades@u-blox.com | 1:628f51c3511f | 80 | printf(" time: %s\n", timeString); |
rob.meades@u-blox.com | 1:628f51c3511f | 81 | } |
rob.meades@u-blox.com | 1:628f51c3511f | 82 | printf(" longitude: %.6f\n", pData->longitude); |
rob.meades@u-blox.com | 1:628f51c3511f | 83 | printf(" latitude: %.6f\n", pData->latitude); |
rob.meades@u-blox.com | 1:628f51c3511f | 84 | printf(" altitude: %d metre(s)\n", pData->altitude); |
rob.meades@u-blox.com | 1:628f51c3511f | 85 | switch (pData->sensor) { |
rob.meades@u-blox.com | 1:628f51c3511f | 86 | case UbloxATCellularInterfaceExt::CELL_LAST: |
rob.meades@u-blox.com | 1:628f51c3511f | 87 | printf(" sensor type: last\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 88 | break; |
rob.meades@u-blox.com | 1:628f51c3511f | 89 | case UbloxATCellularInterfaceExt::CELL_GNSS: |
rob.meades@u-blox.com | 1:628f51c3511f | 90 | printf(" sensor type: GNSS\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 91 | break; |
rob.meades@u-blox.com | 1:628f51c3511f | 92 | case UbloxATCellularInterfaceExt::CELL_LOCATE: |
rob.meades@u-blox.com | 1:628f51c3511f | 93 | printf(" sensor type: Cell Locate\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 94 | break; |
rob.meades@u-blox.com | 1:628f51c3511f | 95 | case UbloxATCellularInterfaceExt::CELL_HYBRID: |
rob.meades@u-blox.com | 1:628f51c3511f | 96 | printf(" sensor type: hybrid\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 97 | break; |
rob.meades@u-blox.com | 1:628f51c3511f | 98 | default: |
rob.meades@u-blox.com | 1:628f51c3511f | 99 | printf(" sensor type: unknown\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 100 | break; |
rob.meades@u-blox.com | 1:628f51c3511f | 101 | } |
rob.meades@u-blox.com | 1:628f51c3511f | 102 | printf(" uncertainty: %d metre(s)\n", pData->uncertainty); |
rob.meades@u-blox.com | 1:628f51c3511f | 103 | printf(" speed: %d metre(s)/second\n", pData->speed); |
rob.meades@u-blox.com | 1:628f51c3511f | 104 | printf(" direction: %d degree(s)\n", pData->direction); |
rob.meades@u-blox.com | 1:628f51c3511f | 105 | printf(" vertical accuracy: %d metre(s)/second\n", pData->speed); |
rob.meades@u-blox.com | 1:628f51c3511f | 106 | printf(" satellite(s) used: %d\n", pData->svUsed); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 107 | printf("I am here: " |
rob.meades@u-blox.com | 1:628f51c3511f | 108 | "https://maps.google.com/?q=%.5f,%.5f\n", pData->latitude, pData->longitude); |
rob.meades@u-blox.com | 1:628f51c3511f | 109 | } |
rob.meades@u-blox.com | 1:628f51c3511f | 110 | |
rob.meades@u-blox.com | 4:13a84f6cc800 | 111 | static void cbButton() |
rob.meades@u-blox.com | 4:13a84f6cc800 | 112 | { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 113 | buttonPressed = true; |
rob.meades@u-blox.com | 4:13a84f6cc800 | 114 | pulseEvent(); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 115 | } |
rob.meades@u-blox.com | 4:13a84f6cc800 | 116 | |
rob.meades@u-blox.com | 1:628f51c3511f | 117 | /* This example program for the u-blox C030 and C027 boards instantiates |
RobMeades | 5:540b2d19fc5c | 118 | * the UbloxAtCellularInterfaceExt to do FTP, HTTP and CellLocate operations. |
RobMeades | 5:540b2d19fc5c | 119 | * It uses the site test.rebex.net for FTP testing and the site |
RobMeades | 5:540b2d19fc5c | 120 | * developer.mbed.org for HTTP GET testing. |
rob.meades@u-blox.com | 1:628f51c3511f | 121 | * Progress may be monitored with a serial terminal running at 9600 baud. |
rob.meades@u-blox.com | 1:628f51c3511f | 122 | * The LED on the C030 board will turn green when this program is |
rob.meades@u-blox.com | 1:628f51c3511f | 123 | * operating correctly, pulse blue when an FTP get, HTTP get or CellLocate |
rob.meades@u-blox.com | 1:628f51c3511f | 124 | * operation is completed and turn red if there is a failure. |
rob.meades@u-blox.com | 1:628f51c3511f | 125 | */ |
rob.meades@u-blox.com | 1:628f51c3511f | 126 | |
rob.meades@u-blox.com | 1:628f51c3511f | 127 | int main() |
rob.meades@u-blox.com | 1:628f51c3511f | 128 | { |
rob.meades@u-blox.com | 9:da9695394d5f | 129 | UbloxATCellularInterfaceExt *interface = new UbloxATCellularInterfaceExt(); |
rob.meades@u-blox.com | 8:11be5eb33196 | 130 | // If you need to debug the cellular interface, comment out the |
rob.meades@u-blox.com | 8:11be5eb33196 | 131 | // instantiation above and uncomment the one below. |
rob.meades@u-blox.com | 9:da9695394d5f | 132 | // UbloxATCellularInterfaceExt *interface = new UbloxATCellularInterfaceExt(MDMTXD, MDMRXD, |
rob.meades@u-blox.com | 9:da9695394d5f | 133 | // MBED_CONF_UBLOX_CELL_BAUD_RATE, |
rob.meades@u-blox.com | 9:da9695394d5f | 134 | // true); |
rob.meades@u-blox.com | 1:628f51c3511f | 135 | UbloxATCellularInterfaceExt::Error *err; |
rob.meades@u-blox.com | 1:628f51c3511f | 136 | UbloxATCellularInterfaceExt::CellLocData data; |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 137 | const int c_size_of_buffer = 2048; |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 138 | char *buf; |
rob.meades@u-blox.com | 1:628f51c3511f | 139 | int httpProfile; |
rob.meades@u-blox.com | 1:628f51c3511f | 140 | int numRes; |
RobMeades | 5:540b2d19fc5c | 141 | GnssSerial gnssSerial; // This needed purely to power on the GNSS chip in |
RobMeades | 5:540b2d19fc5c | 142 | // order that Cell Locate on the module can use it |
rob.meades@u-blox.com | 8:11be5eb33196 | 143 | #ifdef TARGET_UBLOX_C027 |
rob.meades@u-blox.com | 8:11be5eb33196 | 144 | // No user button on C027 |
rob.meades@u-blox.com | 8:11be5eb33196 | 145 | InterruptIn userButton(NC); |
rob.meades@u-blox.com | 8:11be5eb33196 | 146 | #else |
rob.meades@u-blox.com | 4:13a84f6cc800 | 147 | InterruptIn userButton(SW0); |
rob.meades@u-blox.com | 8:11be5eb33196 | 148 | #endif |
rob.meades@u-blox.com | 4:13a84f6cc800 | 149 | |
rob.meades@u-blox.com | 4:13a84f6cc800 | 150 | // Attach a function to the user button |
rob.meades@u-blox.com | 4:13a84f6cc800 | 151 | userButton.rise(&cbButton); |
rob.meades@u-blox.com | 1:628f51c3511f | 152 | |
RobMeades | 7:7781212f4bb4 | 153 | // Power up GNSS to assist with the Cell Locate bit |
rob.meades@u-blox.com | 1:628f51c3511f | 154 | gnssSerial.init(); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 155 | good(); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 156 | printf("Starting up, please wait up to 180 seconds for network registration to complete...\n"); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 157 | |
rob.meades@u-blox.com | 1:628f51c3511f | 158 | if (interface->init(PIN)) { |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 159 | int bytesRead = 0; |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 160 | |
rob.meades@u-blox.com | 4:13a84f6cc800 | 161 | pulseEvent(); |
RobMeades | 6:7a33376899e5 | 162 | interface->set_credentials(APN, USERNAME, PASSWORD); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 163 | printf("Registered, connecting to the packet network...\n"); |
RobMeades | 6:7a33376899e5 | 164 | for (int x = 0; interface->connect() != 0; x++) { |
rob.meades@u-blox.com | 1:628f51c3511f | 165 | if (x > 0) { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 166 | bad(); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 167 | printf("Retrying (have you checked that an antenna is plugged in and your APN is correct?)...\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 168 | } |
rob.meades@u-blox.com | 1:628f51c3511f | 169 | } |
rob.meades@u-blox.com | 4:13a84f6cc800 | 170 | pulseEvent(); |
rob.meades@u-blox.com | 1:628f51c3511f | 171 | |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 172 | buf = (char *) malloc(c_size_of_buffer); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 173 | |
rob.meades@u-blox.com | 1:628f51c3511f | 174 | // FTP OPERATIONS |
rob.meades@u-blox.com | 1:628f51c3511f | 175 | // Reset FTP parameters to default then set things up |
rob.meades@u-blox.com | 4:13a84f6cc800 | 176 | printf("=== FTP ===\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 177 | interface->ftpResetPar(); |
rob.meades@u-blox.com | 1:628f51c3511f | 178 | interface->ftpSetTimeout(60000); |
rob.meades@u-blox.com | 1:628f51c3511f | 179 | interface->ftpSetPar(UbloxATCellularInterfaceExt::FTP_SERVER_NAME, "test.rebex.net"); |
rob.meades@u-blox.com | 1:628f51c3511f | 180 | interface->ftpSetPar(UbloxATCellularInterfaceExt::FTP_USER_NAME, "demo"); |
rob.meades@u-blox.com | 1:628f51c3511f | 181 | interface->ftpSetPar(UbloxATCellularInterfaceExt::FTP_PASSWORD, "password"); |
rob.meades@u-blox.com | 1:628f51c3511f | 182 | interface->ftpSetPar(UbloxATCellularInterfaceExt::FTP_MODE, "1"); |
rob.meades@u-blox.com | 1:628f51c3511f | 183 | |
rob.meades@u-blox.com | 1:628f51c3511f | 184 | // Log into the FTP server |
rob.meades@u-blox.com | 4:13a84f6cc800 | 185 | printf("Logging into FTP server \"test.rebex.net\"...\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 186 | err = interface->ftpCommand(UbloxATCellularInterfaceExt::FTP_LOGIN); |
rob.meades@u-blox.com | 1:628f51c3511f | 187 | if (err == NULL) { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 188 | pulseEvent(); |
rob.meades@u-blox.com | 1:628f51c3511f | 189 | // Get a directory listing from the server |
rob.meades@u-blox.com | 1:628f51c3511f | 190 | if (interface->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS, |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 191 | NULL, NULL, buf, c_size_of_buffer) == NULL) { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 192 | pulseEvent(); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 193 | printf ("Directory listing of FTP server:\n" |
rob.meades@u-blox.com | 4:13a84f6cc800 | 194 | "--------------------------------\n%s" |
rob.meades@u-blox.com | 4:13a84f6cc800 | 195 | "--------------------------------\n", buf); |
rob.meades@u-blox.com | 1:628f51c3511f | 196 | } |
rob.meades@u-blox.com | 14:f531abed3446 | 197 | // FTP GET a file known to be on test.rebex.net into the module file system, |
rob.meades@u-blox.com | 14:f531abed3446 | 198 | // making sure it's not there to begin with |
rob.meades@u-blox.com | 14:f531abed3446 | 199 | interface->delFile("readme.txt"); |
rob.meades@u-blox.com | 1:628f51c3511f | 200 | if (interface->ftpCommand(UbloxATCellularInterfaceExt::FTP_GET_FILE, "readme.txt") == NULL) { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 201 | pulseEvent(); |
rob.meades@u-blox.com | 1:628f51c3511f | 202 | // Read the file from the module file system into buf |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 203 | bytesRead = interface->readFile("readme.txt", buf, c_size_of_buffer); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 204 | |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 205 | if (bytesRead) { |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 206 | if (bytesRead < c_size_of_buffer) { |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 207 | // Add null terminator |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 208 | *(buf + bytesRead) = 0; |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 209 | |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 210 | printf("FTP GET of file \"readme.txt\" completed. The file contained:\n" |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 211 | "------------------------------------------------------------\n%s" |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 212 | "------------------------------------------------------------\n", buf); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 213 | } |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 214 | else { |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 215 | printf("Error: buffer overflow...\n"); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 216 | } |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 217 | |
rob.meades@u-blox.com | 1:628f51c3511f | 218 | } |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 219 | else { |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 220 | printf("Error: data not read from module's FS...\n"); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 221 | } |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 222 | } |
rob.meades@u-blox.com | 1:628f51c3511f | 223 | } else { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 224 | bad(); |
rob.meades@u-blox.com | 1:628f51c3511f | 225 | printf ("Unable to log in, error class %d, error code %d.\n", err->eClass, err->eCode); |
rob.meades@u-blox.com | 1:628f51c3511f | 226 | } |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 227 | |
rob.meades@u-blox.com | 1:628f51c3511f | 228 | // HTTP OPERATIONS |
rob.meades@u-blox.com | 1:628f51c3511f | 229 | // Set up HTTP parameters |
rob.meades@u-blox.com | 4:13a84f6cc800 | 230 | printf("=== HTTP ===\n"); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 231 | printf("Performing HTTP GET on \"Github\"...\n"); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 232 | // Make sure bytesRead is equal to 0 |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 233 | bytesRead = 0; |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 234 | |
rob.meades@u-blox.com | 1:628f51c3511f | 235 | httpProfile = interface->httpAllocProfile(); |
rob.meades@u-blox.com | 1:628f51c3511f | 236 | interface->httpSetTimeout(httpProfile, 30000); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 237 | interface->httpSetPar(httpProfile, UbloxATCellularInterfaceExt::HTTP_SECURE, "1"); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 238 | interface->httpSetPar(httpProfile, UbloxATCellularInterfaceExt::HTTP_SERVER_NAME, "raw.githubusercontent.com"); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 239 | |
rob.meades@u-blox.com | 1:628f51c3511f | 240 | // Do the HTTP command |
rob.meades@u-blox.com | 1:628f51c3511f | 241 | err = interface->httpCommand(httpProfile, UbloxATCellularInterfaceExt::HTTP_GET, |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 242 | "/u-blox/mbed-os/master/features/cellular/mbed_lib.json", |
rob.meades@u-blox.com | 1:628f51c3511f | 243 | NULL, NULL, 0, NULL, |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 244 | buf, c_size_of_buffer, &bytesRead); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 245 | |
rob.meades@u-blox.com | 1:628f51c3511f | 246 | if (err == NULL) { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 247 | pulseEvent(); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 248 | |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 249 | if(bytesRead > 0 && bytesRead < c_size_of_buffer) { |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 250 | //Add null terminator |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 251 | *(buf + bytesRead) = 0; |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 252 | |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 253 | printf("HTTP GET of \"/u-blox/mbed-os/master/features/cellular/mbed_lib.json\" completed. The response contained:\n" |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 254 | "----------------------------------------------------------------------------------------\n%s" |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 255 | "----------------------------------------------------------------------------------------\n", buf); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 256 | } |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 257 | else { |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 258 | printf("Error: Bytes read is zero"); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 259 | } |
rob.meades@u-blox.com | 1:628f51c3511f | 260 | } else { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 261 | bad(); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 262 | printf("Unable to get \"/u-blox/mbed-os/master/features/cellular/mbed_lib.json\" from github, " |
rob.meades@u-blox.com | 4:13a84f6cc800 | 263 | "error class %d, error code %d.\n", err->eClass, err->eCode); |
rob.meades@u-blox.com | 1:628f51c3511f | 264 | } |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 265 | #ifndef TARGET_UBLOX_C030_R41XM |
rob.meades@u-blox.com | 1:628f51c3511f | 266 | // CELL LOCATE OPERATIONS (in a loop) |
rob.meades@u-blox.com | 4:13a84f6cc800 | 267 | printf("=== Cell Locate ===\n"); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 268 | |
rob.meades@u-blox.com | 8:11be5eb33196 | 269 | printf("Sending Cell Locate requests in a loop (until the user button is pressed on C030 or forever on C027)...\n"); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 270 | while (!buttonPressed) { |
rob.meades@u-blox.com | 1:628f51c3511f | 271 | interface->cellLocSrvUdp(); |
rob.meades@u-blox.com | 1:628f51c3511f | 272 | interface->cellLocConfig(1); // Deep scan mode |
rob.meades@u-blox.com | 4:13a84f6cc800 | 273 | printf("Sending Cell Locate request...\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 274 | if (interface->cellLocRequest(UbloxATCellularInterfaceExt::CELL_HYBRID, 10, 100, |
rob.meades@u-blox.com | 1:628f51c3511f | 275 | (UbloxATCellularInterfaceExt::CellRespType) 1, 1)) { |
rob.meades@u-blox.com | 1:628f51c3511f | 276 | // Wait for the response |
rob.meades@u-blox.com | 1:628f51c3511f | 277 | numRes = 0; |
rob.meades@u-blox.com | 1:628f51c3511f | 278 | for (int x = 0; (numRes == 0) && (x < 10); x++) { |
rob.meades@u-blox.com | 1:628f51c3511f | 279 | numRes = interface->cellLocGetRes(); |
rob.meades@u-blox.com | 1:628f51c3511f | 280 | } |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 281 | |
rob.meades@u-blox.com | 1:628f51c3511f | 282 | if (numRes > 0) { |
rob.meades@u-blox.com | 1:628f51c3511f | 283 | interface->cellLocGetData(&data); |
rob.meades@u-blox.com | 1:628f51c3511f | 284 | if (data.validData) { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 285 | pulseEvent(); |
rob.meades@u-blox.com | 1:628f51c3511f | 286 | printCellLocateData(&data); |
rob.meades@u-blox.com | 1:628f51c3511f | 287 | } |
rob.meades@u-blox.com | 1:628f51c3511f | 288 | } else { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 289 | bad(); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 290 | printf("No response from Cell Locate server.\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 291 | } |
rob.meades@u-blox.com | 1:628f51c3511f | 292 | } |
rob.meades@u-blox.com | 1:628f51c3511f | 293 | wait_ms(5000); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 294 | |
rob.meades@u-blox.com | 12:1e1c58088143 | 295 | #ifndef TARGET_UBLOX_C027 |
RobMeades | 6:7a33376899e5 | 296 | printf("[Checking if user button has been pressed]\n"); |
rob.meades@u-blox.com | 12:1e1c58088143 | 297 | #endif |
rob.meades@u-blox.com | 1:628f51c3511f | 298 | } |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 299 | |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 300 | free(buf); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 301 | |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 302 | #else |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 303 | while(!buttonPressed) { |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 304 | wait_ms(500); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 305 | // Shift the LED states |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 306 | int carry = ledBlue; |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 307 | ledBlue = ledRed; |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 308 | ledRed = ledGreen; |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 309 | ledGreen = carry; |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 310 | } |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 311 | #endif |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 312 | |
rob.meades@u-blox.com | 4:13a84f6cc800 | 313 | pulseEvent(); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 314 | printf("User button was pressed, stopping...\n"); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 315 | gnssSerial.powerOff(); |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 316 | |
rob.meades@u-blox.com | 4:13a84f6cc800 | 317 | interface->disconnect(); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 318 | interface->deinit(); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 319 | ledOff(); |
rob.meades@u-blox.com | 4:13a84f6cc800 | 320 | printf("Stopped.\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 321 | } else { |
rob.meades@u-blox.com | 4:13a84f6cc800 | 322 | bad(); |
rob.meades@u-blox.com | 1:628f51c3511f | 323 | printf("Unable to initialise the interface.\n"); |
rob.meades@u-blox.com | 1:628f51c3511f | 324 | } |
rob.meades@u-blox.com | 1:628f51c3511f | 325 | } |
rob.meades@u-blox.com | 1:628f51c3511f | 326 | |
fahim.alavi@u-blox.com | 20:3ca2d75614e6 | 327 | // End Of File |