default folder relocation

Dependencies:   ublox-cellular-driver-gen gnss ublox-cellular-base ublox-at-cellular-interface-ext

Committer:
rob.meades@u-blox.com
Date:
Wed Jun 07 23:54:52 2017 +0100
Revision:
1:628f51c3511f
Child:
4:13a84f6cc800
Flesh out example properly.
Update UbloxATCellularInterfaceExt library.

Who changed what in which revision?

UserRevisionLine numberNew 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 1:628f51c3511f 28 // either try the failry 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 1:628f51c3511f 41 static void pulseBlue() {
rob.meades@u-blox.com 1:628f51c3511f 42 ledBlue = 0;
rob.meades@u-blox.com 1:628f51c3511f 43 ledRed = 1;
rob.meades@u-blox.com 1:628f51c3511f 44 ledGreen = 1;
rob.meades@u-blox.com 1:628f51c3511f 45 wait_ms(500);
rob.meades@u-blox.com 1:628f51c3511f 46 ledGreen = 0;
rob.meades@u-blox.com 1:628f51c3511f 47 ledBlue = 1;
rob.meades@u-blox.com 1:628f51c3511f 48 ledRed = 1;
rob.meades@u-blox.com 1:628f51c3511f 49 }
rob.meades@u-blox.com 1:628f51c3511f 50
rob.meades@u-blox.com 1:628f51c3511f 51 static void printCellLocateData(UbloxATCellularInterfaceExt::CellLocData *pData)
rob.meades@u-blox.com 1:628f51c3511f 52 {
rob.meades@u-blox.com 1:628f51c3511f 53 char timeString[25];
rob.meades@u-blox.com 1:628f51c3511f 54
rob.meades@u-blox.com 1:628f51c3511f 55 printf("Cell Locate data:\n");
rob.meades@u-blox.com 1:628f51c3511f 56 if (strftime(timeString, sizeof(timeString), "%F %T", (const tm *) &(pData->time)) > 0) {
rob.meades@u-blox.com 1:628f51c3511f 57 printf(" time: %s\n", timeString);
rob.meades@u-blox.com 1:628f51c3511f 58 }
rob.meades@u-blox.com 1:628f51c3511f 59 printf(" longitude: %.6f\n", pData->longitude);
rob.meades@u-blox.com 1:628f51c3511f 60 printf(" latitude: %.6f\n", pData->latitude);
rob.meades@u-blox.com 1:628f51c3511f 61 printf(" altitude: %d metre(s)\n", pData->altitude);
rob.meades@u-blox.com 1:628f51c3511f 62 switch (pData->sensor) {
rob.meades@u-blox.com 1:628f51c3511f 63 case UbloxATCellularInterfaceExt::CELL_LAST:
rob.meades@u-blox.com 1:628f51c3511f 64 printf(" sensor type: last\n");
rob.meades@u-blox.com 1:628f51c3511f 65 break;
rob.meades@u-blox.com 1:628f51c3511f 66 case UbloxATCellularInterfaceExt::CELL_GNSS:
rob.meades@u-blox.com 1:628f51c3511f 67 printf(" sensor type: GNSS\n");
rob.meades@u-blox.com 1:628f51c3511f 68 break;
rob.meades@u-blox.com 1:628f51c3511f 69 case UbloxATCellularInterfaceExt::CELL_LOCATE:
rob.meades@u-blox.com 1:628f51c3511f 70 printf(" sensor type: Cell Locate\n");
rob.meades@u-blox.com 1:628f51c3511f 71 break;
rob.meades@u-blox.com 1:628f51c3511f 72 case UbloxATCellularInterfaceExt::CELL_HYBRID:
rob.meades@u-blox.com 1:628f51c3511f 73 printf(" sensor type: hybrid\n");
rob.meades@u-blox.com 1:628f51c3511f 74 break;
rob.meades@u-blox.com 1:628f51c3511f 75 default:
rob.meades@u-blox.com 1:628f51c3511f 76 printf(" sensor type: unknown\n");
rob.meades@u-blox.com 1:628f51c3511f 77 break;
rob.meades@u-blox.com 1:628f51c3511f 78 }
rob.meades@u-blox.com 1:628f51c3511f 79 printf(" uncertainty: %d metre(s)\n", pData->uncertainty);
rob.meades@u-blox.com 1:628f51c3511f 80 printf(" speed: %d metre(s)/second\n", pData->speed);
rob.meades@u-blox.com 1:628f51c3511f 81 printf(" direction: %d degree(s)\n", pData->direction);
rob.meades@u-blox.com 1:628f51c3511f 82 printf(" vertical accuracy: %d metre(s)/second\n", pData->speed);
rob.meades@u-blox.com 1:628f51c3511f 83 printf(" satellite(s) used: %d\n", pData->svUsed);
rob.meades@u-blox.com 1:628f51c3511f 84 printf("I am here: "
rob.meades@u-blox.com 1:628f51c3511f 85 "https://maps.google.com/?q=%.5f,%.5f\n", pData->latitude, pData->longitude);
rob.meades@u-blox.com 1:628f51c3511f 86 }
rob.meades@u-blox.com 1:628f51c3511f 87
rob.meades@u-blox.com 1:628f51c3511f 88 /* This example program for the u-blox C030 and C027 boards instantiates
rob.meades@u-blox.com 1:628f51c3511f 89 * the UbloxAtCellularInterface to do FTP, HTTP and CellLocate operations.
rob.meades@u-blox.com 1:628f51c3511f 90 * It uses test.rebex.net for FTP testing and mbed.org for HTTP GET testing.
rob.meades@u-blox.com 1:628f51c3511f 91 * Progress may be monitored with a serial terminal running at 9600 baud.
rob.meades@u-blox.com 1:628f51c3511f 92 * The LED on the C030 board will turn green when this program is
rob.meades@u-blox.com 1:628f51c3511f 93 * operating correctly, pulse blue when an FTP get, HTTP get or CellLocate
rob.meades@u-blox.com 1:628f51c3511f 94 * operation is completed and turn red if there is a failure.
rob.meades@u-blox.com 1:628f51c3511f 95 */
rob.meades@u-blox.com 1:628f51c3511f 96
rob.meades@u-blox.com 1:628f51c3511f 97 int main()
rob.meades@u-blox.com 1:628f51c3511f 98 {
rob.meades@u-blox.com 1:628f51c3511f 99 UbloxATCellularInterfaceExt *interface = new UbloxATCellularInterfaceExt();
rob.meades@u-blox.com 1:628f51c3511f 100 UbloxATCellularInterfaceExt::Error *err;
rob.meades@u-blox.com 1:628f51c3511f 101 UbloxATCellularInterfaceExt::CellLocData data;
rob.meades@u-blox.com 1:628f51c3511f 102 char buf[1024];
rob.meades@u-blox.com 1:628f51c3511f 103 int httpProfile;
rob.meades@u-blox.com 1:628f51c3511f 104 int numRes;
rob.meades@u-blox.com 1:628f51c3511f 105 GnssSerial gnssSerial;
rob.meades@u-blox.com 1:628f51c3511f 106
rob.meades@u-blox.com 1:628f51c3511f 107 // Power up GNSS for the Cell Locate bit
rob.meades@u-blox.com 1:628f51c3511f 108 gnssSerial.init();
rob.meades@u-blox.com 1:628f51c3511f 109
rob.meades@u-blox.com 1:628f51c3511f 110 ledGreen = 0;
rob.meades@u-blox.com 1:628f51c3511f 111 ledBlue = 1;
rob.meades@u-blox.com 1:628f51c3511f 112 ledRed = 1;
rob.meades@u-blox.com 1:628f51c3511f 113
rob.meades@u-blox.com 1:628f51c3511f 114 printf ("Starting up, please wait up to 180 seconds for network registration to complete...\n");
rob.meades@u-blox.com 1:628f51c3511f 115 if (interface->init(PIN)) {
rob.meades@u-blox.com 1:628f51c3511f 116 pulseBlue();
rob.meades@u-blox.com 1:628f51c3511f 117 printf ("Connecting to the packet network...\n");
rob.meades@u-blox.com 1:628f51c3511f 118 for (int x = 0; interface->connect(PIN, APN, USERNAME, PASSWORD) != 0; x++) {
rob.meades@u-blox.com 1:628f51c3511f 119 if (x > 0) {
rob.meades@u-blox.com 1:628f51c3511f 120 printf ("Retrying (have you checked that an antenna is plugged in and your APN is correct?)...\n");
rob.meades@u-blox.com 1:628f51c3511f 121 ledRed = 0;
rob.meades@u-blox.com 1:628f51c3511f 122 ledGreen = 1;
rob.meades@u-blox.com 1:628f51c3511f 123 ledBlue = 1;
rob.meades@u-blox.com 1:628f51c3511f 124 }
rob.meades@u-blox.com 1:628f51c3511f 125 }
rob.meades@u-blox.com 1:628f51c3511f 126 pulseBlue();
rob.meades@u-blox.com 1:628f51c3511f 127
rob.meades@u-blox.com 1:628f51c3511f 128 // FTP OPERATIONS
rob.meades@u-blox.com 1:628f51c3511f 129 // Reset FTP parameters to default then set things up
rob.meades@u-blox.com 1:628f51c3511f 130 interface->ftpResetPar();
rob.meades@u-blox.com 1:628f51c3511f 131 interface->ftpSetTimeout(60000);
rob.meades@u-blox.com 1:628f51c3511f 132 interface->ftpSetPar(UbloxATCellularInterfaceExt::FTP_SERVER_NAME, "test.rebex.net");
rob.meades@u-blox.com 1:628f51c3511f 133 interface->ftpSetPar(UbloxATCellularInterfaceExt::FTP_USER_NAME, "demo");
rob.meades@u-blox.com 1:628f51c3511f 134 interface->ftpSetPar(UbloxATCellularInterfaceExt::FTP_PASSWORD, "password");
rob.meades@u-blox.com 1:628f51c3511f 135 interface->ftpSetPar(UbloxATCellularInterfaceExt::FTP_MODE, "1");
rob.meades@u-blox.com 1:628f51c3511f 136
rob.meades@u-blox.com 1:628f51c3511f 137 // Log into the FTP server
rob.meades@u-blox.com 1:628f51c3511f 138 printf ("Logging into FTP server \"test.rebex.net\"...\n");
rob.meades@u-blox.com 1:628f51c3511f 139 err = interface->ftpCommand(UbloxATCellularInterfaceExt::FTP_LOGIN);
rob.meades@u-blox.com 1:628f51c3511f 140 if (err == NULL) {
rob.meades@u-blox.com 1:628f51c3511f 141 pulseBlue();
rob.meades@u-blox.com 1:628f51c3511f 142 // Get a directory listing from the server
rob.meades@u-blox.com 1:628f51c3511f 143 if (interface->ftpCommand(UbloxATCellularInterfaceExt::FTP_LS,
rob.meades@u-blox.com 1:628f51c3511f 144 NULL, NULL, 0, buf, sizeof (buf)) == NULL) {
rob.meades@u-blox.com 1:628f51c3511f 145 pulseBlue();
rob.meades@u-blox.com 1:628f51c3511f 146 printf ("Directory listing of FTP server:\n%s", buf);
rob.meades@u-blox.com 1:628f51c3511f 147 }
rob.meades@u-blox.com 1:628f51c3511f 148 // FTP GET a file known to be on test.rebex.net into the module file system
rob.meades@u-blox.com 1:628f51c3511f 149 if (interface->ftpCommand(UbloxATCellularInterfaceExt::FTP_GET_FILE, "readme.txt") == NULL) {
rob.meades@u-blox.com 1:628f51c3511f 150 pulseBlue();
rob.meades@u-blox.com 1:628f51c3511f 151 // Read the file from the module file system into buf
rob.meades@u-blox.com 1:628f51c3511f 152 if (interface->readFile("readme.txt", buf, sizeof (buf))) {
rob.meades@u-blox.com 1:628f51c3511f 153 printf ("FTP GET of file \"readme.txt\" completed. The file contains:\n"
rob.meades@u-blox.com 1:628f51c3511f 154 "-------------------------------------------------------------\n%s"
rob.meades@u-blox.com 1:628f51c3511f 155 "-------------------------------------------------------------\n", buf);
rob.meades@u-blox.com 1:628f51c3511f 156 }
rob.meades@u-blox.com 1:628f51c3511f 157 }
rob.meades@u-blox.com 1:628f51c3511f 158 } else {
rob.meades@u-blox.com 1:628f51c3511f 159 printf ("Unable to log in, error class %d, error code %d.\n", err->eClass, err->eCode);
rob.meades@u-blox.com 1:628f51c3511f 160 ledRed = 0;
rob.meades@u-blox.com 1:628f51c3511f 161 ledGreen = 1;
rob.meades@u-blox.com 1:628f51c3511f 162 ledBlue = 1;
rob.meades@u-blox.com 1:628f51c3511f 163 }
rob.meades@u-blox.com 1:628f51c3511f 164
rob.meades@u-blox.com 1:628f51c3511f 165 // HTTP OPERATIONS
rob.meades@u-blox.com 1:628f51c3511f 166 // Set up HTTP parameters
rob.meades@u-blox.com 1:628f51c3511f 167 printf ("Performing HTTP GET on \"mbed.org\"...\n");
rob.meades@u-blox.com 1:628f51c3511f 168 httpProfile = interface->httpAllocProfile();
rob.meades@u-blox.com 1:628f51c3511f 169 interface->httpSetTimeout(httpProfile, 30000);
rob.meades@u-blox.com 1:628f51c3511f 170 interface->httpSetPar(httpProfile, UbloxATCellularInterfaceExt::HTTP_SERVER_NAME, "mbed.org");
rob.meades@u-blox.com 1:628f51c3511f 171
rob.meades@u-blox.com 1:628f51c3511f 172 // Do the HTTP command
rob.meades@u-blox.com 1:628f51c3511f 173 err = interface->httpCommand(httpProfile, UbloxATCellularInterfaceExt::HTTP_GET,
rob.meades@u-blox.com 1:628f51c3511f 174 "/media/uploads/mbed_official/hello.txt",
rob.meades@u-blox.com 1:628f51c3511f 175 NULL, NULL, 0, NULL,
rob.meades@u-blox.com 1:628f51c3511f 176 buf, sizeof (buf));
rob.meades@u-blox.com 1:628f51c3511f 177 if (err == NULL) {
rob.meades@u-blox.com 1:628f51c3511f 178 pulseBlue();
rob.meades@u-blox.com 1:628f51c3511f 179 printf ("HTTP GET of \"/media/uploads/mbed_official/hello.txt\" completed. The file contains:\n"
rob.meades@u-blox.com 1:628f51c3511f 180 "------------------------------------------------------------------------------------\n%s"
rob.meades@u-blox.com 1:628f51c3511f 181 "------------------------------------------------------------------------------------\n", buf);
rob.meades@u-blox.com 1:628f51c3511f 182 } else {
rob.meades@u-blox.com 1:628f51c3511f 183 printf ("Unable to get \"/media/uploads/mbed_official/hello.txt\" from \"mbed.org\", "
rob.meades@u-blox.com 1:628f51c3511f 184 "error class %d, error code %d.\n", err->eClass, err->eCode);
rob.meades@u-blox.com 1:628f51c3511f 185 ledRed = 0;
rob.meades@u-blox.com 1:628f51c3511f 186 ledGreen = 1;
rob.meades@u-blox.com 1:628f51c3511f 187 ledBlue = 1;
rob.meades@u-blox.com 1:628f51c3511f 188 }
rob.meades@u-blox.com 1:628f51c3511f 189
rob.meades@u-blox.com 1:628f51c3511f 190 // CELL LOCATE OPERATIONS (in a loop)
rob.meades@u-blox.com 1:628f51c3511f 191 printf ("Sending Cell Locate requests in a loop...\n");
rob.meades@u-blox.com 1:628f51c3511f 192 while (1) {
rob.meades@u-blox.com 1:628f51c3511f 193 interface->cellLocSrvUdp();
rob.meades@u-blox.com 1:628f51c3511f 194 interface->cellLocConfig(1); // Deep scan mode
rob.meades@u-blox.com 1:628f51c3511f 195 printf ("Sending Cell Locate request...\n");
rob.meades@u-blox.com 1:628f51c3511f 196 if (interface->cellLocRequest(UbloxATCellularInterfaceExt::CELL_HYBRID, 10, 100,
rob.meades@u-blox.com 1:628f51c3511f 197 (UbloxATCellularInterfaceExt::CellRespType) 1, 1)) {
rob.meades@u-blox.com 1:628f51c3511f 198 // Wait for the response
rob.meades@u-blox.com 1:628f51c3511f 199 numRes = 0;
rob.meades@u-blox.com 1:628f51c3511f 200 for (int x = 0; (numRes == 0) && (x < 10); x++) {
rob.meades@u-blox.com 1:628f51c3511f 201 numRes = interface->cellLocGetRes();
rob.meades@u-blox.com 1:628f51c3511f 202 }
rob.meades@u-blox.com 1:628f51c3511f 203
rob.meades@u-blox.com 1:628f51c3511f 204 if (numRes > 0) {
rob.meades@u-blox.com 1:628f51c3511f 205 interface->cellLocGetData(&data);
rob.meades@u-blox.com 1:628f51c3511f 206 if (data.validData) {
rob.meades@u-blox.com 1:628f51c3511f 207 pulseBlue();
rob.meades@u-blox.com 1:628f51c3511f 208 printCellLocateData(&data);
rob.meades@u-blox.com 1:628f51c3511f 209 }
rob.meades@u-blox.com 1:628f51c3511f 210 } else {
rob.meades@u-blox.com 1:628f51c3511f 211 printf ("No response from Cell Locate server.\n");
rob.meades@u-blox.com 1:628f51c3511f 212 ledRed = 0;
rob.meades@u-blox.com 1:628f51c3511f 213 ledGreen = 1;
rob.meades@u-blox.com 1:628f51c3511f 214 ledBlue = 1;
rob.meades@u-blox.com 1:628f51c3511f 215 }
rob.meades@u-blox.com 1:628f51c3511f 216 }
rob.meades@u-blox.com 1:628f51c3511f 217 wait_ms(5000);
rob.meades@u-blox.com 1:628f51c3511f 218 }
rob.meades@u-blox.com 1:628f51c3511f 219
rob.meades@u-blox.com 1:628f51c3511f 220 } else {
rob.meades@u-blox.com 1:628f51c3511f 221 printf("Unable to initialise the interface.\n");
rob.meades@u-blox.com 1:628f51c3511f 222 }
rob.meades@u-blox.com 1:628f51c3511f 223
rob.meades@u-blox.com 1:628f51c3511f 224 ledRed = 0;
rob.meades@u-blox.com 1:628f51c3511f 225 ledGreen = 1;
rob.meades@u-blox.com 1:628f51c3511f 226 ledBlue = 1;
rob.meades@u-blox.com 1:628f51c3511f 227 printf("Should never get here.\n");
rob.meades@u-blox.com 1:628f51c3511f 228 MBED_ASSERT(false);
rob.meades@u-blox.com 1:628f51c3511f 229 }
rob.meades@u-blox.com 1:628f51c3511f 230
rob.meades@u-blox.com 1:628f51c3511f 231 // End Of File