MultiTech Dragonfly with ROHM Sensor board sending data to IBM BlueMix Quickstart

Dependencies:   mbed mtsas FXAS21002 FXOS8700 mbed-rtos

Fork of AvnetWorking_IBM_QuickStart by Paul Jaeger

Committer:
BlueShadow
Date:
Tue Aug 23 00:34:17 2016 +0000
Revision:
5:dbedb2422089
Parent:
4:d16e07588838
Child:
6:8f1ad9d2193e
migration to Freescale sensor - may not work;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BlueShadow 5:dbedb2422089 1 /* Copyright (c) 2015 NXP Semiconductors. MIT License
BlueShadow 5:dbedb2422089 2 *
BlueShadow 5:dbedb2422089 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
BlueShadow 5:dbedb2422089 4 * and associated documentation files (the "Software"), to deal in the Software without
BlueShadow 5:dbedb2422089 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
BlueShadow 5:dbedb2422089 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
BlueShadow 5:dbedb2422089 7 * Software is furnished to do so, subject to the following conditions:
BlueShadow 5:dbedb2422089 8 *
BlueShadow 5:dbedb2422089 9 * The above copyright notice and this permission notice shall be included in all copies or
BlueShadow 5:dbedb2422089 10 * substantial portions of the Software.
BlueShadow 5:dbedb2422089 11 *
BlueShadow 5:dbedb2422089 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
BlueShadow 5:dbedb2422089 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
BlueShadow 5:dbedb2422089 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
BlueShadow 5:dbedb2422089 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
BlueShadow 5:dbedb2422089 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
BlueShadow 5:dbedb2422089 17
BlueShadow 5:dbedb2422089 18 * 8/12/2016 I will be making mistakes in this code.
BlueShadow 5:dbedb2422089 19 * 8/15/2016 I2C bus in the code is on D14/D15 Arduino Pinout. FRDM-STBD-AGM01 board is jumpered
BlueShadow 5:dbedb2422089 20 * to use the wrong pins vs the code. Move the Jumpers from I2C-SCL1 to 0 and I2C-SDA1 to 0
BlueShadow 5:dbedb2422089 21 */
BlueShadow 5:dbedb2422089 22 /** Combination of MultiTech HTTPS Example
BlueShadow 2:1df4b48824b1 23 *
BlueShadow 2:1df4b48824b1 24 * Configures the Sensor board for Ambient Light, cellular radio, brings up the cellular link,
BlueShadow 2:1df4b48824b1 25 * and does HTTPS POST requests.
mfiore 0:6ce1803b7a03 26 * To do HTTPS requests with a certain server, the root certificate used to validate that server's certificate must be installed. See ssl_certificates.h for information on how to get the proper root certificate.
mfiore 0:6ce1803b7a03 27 *
BlueShadow 2:1df4b48824b1 28 *
BlueShadow 2:1df4b48824b1 29 *
BlueShadow 2:1df4b48824b1 30 * The following hardware is required to successfully run this program:
BlueShadow 2:1df4b48824b1 31 * - MultiTech UDK2 (4" square white PCB with Arduino headers, antenna
BlueShadow 2:1df4b48824b1 32 * connector, micro USB ports, and 40-pin connector for Dragonfly)
BlueShadow 2:1df4b48824b1 33 * - MultiTech Dragonfly (1"x2" green PCB with Telit radio)
BlueShadow 5:dbedb2422089 34 * - NXP Freesclae FRDM-STBC-AGM01
BlueShadow 5:dbedb2422089 35 * 3-axis accelerometer + 3-axis magnetometer, 3-axis gyroscope,
BlueShadow 2:1df4b48824b1 36 *
BlueShadow 2:1df4b48824b1 37 * What this program does:
BlueShadow 5:dbedb2422089 38 * - reads data from all sensors
BlueShadow 2:1df4b48824b1 39 * - prints all sensor data to debug port on a periodic basis
BlueShadow 2:1df4b48824b1 40 * - optionally send data to BlueMix
BlueShadow 2:1df4b48824b1 41 * - All data is sent to a specific location determined by the student login.
BlueShadow 2:1df4b48824b1 42 * - BlueMix cloud platform (user must create own account and configure a device
BlueShadow 2:1df4b48824b1 43 *
BlueShadow 2:1df4b48824b1 44 * Setup:
BlueShadow 2:1df4b48824b1 45 * - Correctly insert SIM card into Dragonfly
BlueShadow 2:1df4b48824b1 46 * - Seat the Dragonfly on the UDK2 board
BlueShadow 2:1df4b48824b1 47 * - Connect an antenna to the connector on the Dragonfly labled "M"
BlueShadow 2:1df4b48824b1 48 * - Stack the Base Shield on the UDK2 Arduino headers
BlueShadow 2:1df4b48824b1 49 * - Stack the MEMs board on top of the Base Shield
BlueShadow 2:1df4b48824b1 50 * - Plug in the power cable
BlueShadow 2:1df4b48824b1 51 * - Plug a micro USB cable into the port below and slightly to the
BlueShadow 2:1df4b48824b1 52 * left of the Dragonfly (NOT the port on the Dragonfly)
BlueShadow 2:1df4b48824b1 53 *
BlueShadow 2:1df4b48824b1 54 * Go have fun and make something cool!
BlueShadow 2:1df4b48824b1 55 *
BlueShadow 2:1df4b48824b1 56 ************************************************************************/
BlueShadow 2:1df4b48824b1 57 /*
BlueShadow 5:dbedb2422089 58 * Sample Program Description:
BlueShadow 5:dbedb2422089 59 * This Program will enable to Multi-Tech Dragonfly platform to utilize NXP Freescale FRDM-STBC-AGM01 Shield Board.
BlueShadow 5:dbedb2422089 60 * This program will initialize sensors on the shield and then read back the sensor data.
BlueShadow 5:dbedb2422089 61 * Data will then be output to the UART Debug Terminal.
mfiore 0:6ce1803b7a03 62 */
mfiore 0:6ce1803b7a03 63
mfiore 0:6ce1803b7a03 64 #include "mbed.h"
mfiore 0:6ce1803b7a03 65 #include "mtsas.h"
mfiore 0:6ce1803b7a03 66 #include "ssl_certificates.h"
BlueShadow 2:1df4b48824b1 67 #include <string> // added for string manipulation
BlueShadow 5:dbedb2422089 68 #include <vector> // added for SMS example
BlueShadow 5:dbedb2422089 69 #include <iterator> // added for SMS example
BlueShadow 5:dbedb2422089 70 #include <sstream> // added for HTTP
BlueShadow 5:dbedb2422089 71 #include "FXAS21002.h" // added for nxp (freescale) sensor board
BlueShadow 5:dbedb2422089 72 #include "FXOS8700.h" // added for nxp (freescale) sensor board
BlueShadow 2:1df4b48824b1 73
BlueShadow 2:1df4b48824b1 74 //-------- Customise these values -----------
BlueShadow 2:1df4b48824b1 75
BlueShadow 2:1df4b48824b1 76 #define ORG "quickstart" // your organization or "quickstart"
BlueShadow 2:1df4b48824b1 77 #define DEVICE_TYPE "dragonflytype" // use this default for quickstart or customize to your registered device type
BlueShadow 2:1df4b48824b1 78 #define DEVICE_ID "dragonfly01" // use this default for quickstart or customize to your registered device id
BlueShadow 5:dbedb2422089 79 #define TOKEN "token" // not used with "quickstart"
BlueShadow 2:1df4b48824b1 80 #define EVENT "myEvent" // use this default or customize to your event type
BlueShadow 2:1df4b48824b1 81 //-------- Customise the above values --------
BlueShadow 2:1df4b48824b1 82
BlueShadow 2:1df4b48824b1 83
BlueShadow 2:1df4b48824b1 84 //*****************************************************************************************************************************************************
BlueShadow 2:1df4b48824b1 85 DigitalOut Led1Out(LED1);
BlueShadow 2:1df4b48824b1 86
mfiore 1:26b8af61d0ac 87 DigitalOut bc_nce(PB_2);
mfiore 1:26b8af61d0ac 88
mfiore 0:6ce1803b7a03 89 bool init_mtsas();
mfiore 0:6ce1803b7a03 90 char* httpResToStr(HTTPResult res);
mfiore 0:6ce1803b7a03 91
mfiore 0:6ce1803b7a03 92 // The MTSSerialFlowControl object represents the physical serial link between the processor and the cellular radio.
mfiore 0:6ce1803b7a03 93 mts::MTSSerialFlowControl* io;
mfiore 0:6ce1803b7a03 94 // The Cellular object represents the cellular radio.
mfiore 0:6ce1803b7a03 95 mts::Cellular* radio;
mfiore 0:6ce1803b7a03 96
mfiore 0:6ce1803b7a03 97 // An APN is required for GSM radios.
BlueShadow 2:1df4b48824b1 98 static const char apn[] = "iot.aer.net";
mfiore 0:6ce1803b7a03 99
mfiore 0:6ce1803b7a03 100 bool radio_ok = false;
mfiore 0:6ce1803b7a03 101
BlueShadow 2:1df4b48824b1 102 //Define Pins for I2C Interface
BlueShadow 2:1df4b48824b1 103 I2C i2c(I2C_SDA, I2C_SCL);
BlueShadow 2:1df4b48824b1 104 bool RepStart = true;
BlueShadow 2:1df4b48824b1 105 bool NoRepStart = false;
BlueShadow 2:1df4b48824b1 106
BlueShadow 2:1df4b48824b1 107 char* httpResToStr(HTTPResult res);
BlueShadow 2:1df4b48824b1 108
BlueShadow 5:dbedb2422089 109 namespace patch // this may be something to delete *********************
BlueShadow 2:1df4b48824b1 110 {
BlueShadow 2:1df4b48824b1 111 template < typename T > std::string to_string( const T& n )
BlueShadow 2:1df4b48824b1 112 {
BlueShadow 2:1df4b48824b1 113 std::ostringstream stm ;
BlueShadow 2:1df4b48824b1 114 stm << n ;
BlueShadow 2:1df4b48824b1 115 return stm.str() ;
BlueShadow 2:1df4b48824b1 116 }
BlueShadow 2:1df4b48824b1 117 }
BlueShadow 2:1df4b48824b1 118
BlueShadow 2:1df4b48824b1 119
BlueShadow 5:dbedb2422089 120 // Initialize Serial port
BlueShadow 5:dbedb2422089 121 Serial pc(USBTX, USBRX);
BlueShadow 5:dbedb2422089 122 int pc_baud = 115200;
BlueShadow 5:dbedb2422089 123
BlueShadow 5:dbedb2422089 124 // Initialize pins for I2C communication for sensors. Set jumpers J6,J7 in FRDM-STBC-AGM01 board accordingly.
BlueShadow 5:dbedb2422089 125 FXOS8700 accel(D14,D15);
BlueShadow 5:dbedb2422089 126 FXOS8700 mag(D14,D15);
BlueShadow 5:dbedb2422089 127 FXAS21002 gyro(D14,D15);
BlueShadow 5:dbedb2422089 128
BlueShadow 5:dbedb2422089 129 // Set Sensor Stream details
BlueShadow 5:dbedb2422089 130 char streamAcc[] = "acc_rms"; // Stream you want to push to
BlueShadow 5:dbedb2422089 131 char streamMag[] = "mag_rms"; // Stream you want to push to
BlueShadow 5:dbedb2422089 132 char streamGyr[] = "gyr_rms"; // Stream you want to push to
BlueShadow 5:dbedb2422089 133
BlueShadow 5:dbedb2422089 134
BlueShadow 2:1df4b48824b1 135 /****************************************************************************************************
BlueShadow 2:1df4b48824b1 136 // main
BlueShadow 2:1df4b48824b1 137 ****************************************************************************************************/
BlueShadow 2:1df4b48824b1 138
BlueShadow 2:1df4b48824b1 139 int main()
BlueShadow 2:1df4b48824b1 140 {
mfiore 1:26b8af61d0ac 141 // Disable the battery charger unless a battery is attached.
mfiore 1:26b8af61d0ac 142 bc_nce = 1;
BlueShadow 2:1df4b48824b1 143
BlueShadow 5:dbedb2422089 144 // Change the baud rate of the debug port from the default 9600 to 115200.
BlueShadow 5:dbedb2422089 145 // Serial debug(USBTX, USBRX);
BlueShadow 5:dbedb2422089 146 // debug.baud(115200);
BlueShadow 5:dbedb2422089 147 pc.baud(pc_baud);
BlueShadow 5:dbedb2422089 148
BlueShadow 5:dbedb2422089 149 // Configure Accelerometer FXOS8700, Magnetometer FXOS8700 & Gyroscope FXAS21002
BlueShadow 5:dbedb2422089 150 accel.accel_config();
BlueShadow 5:dbedb2422089 151 mag.mag_config();
BlueShadow 5:dbedb2422089 152 gyro.gyro_config();
BlueShadow 2:1df4b48824b1 153
BlueShadow 5:dbedb2422089 154 float accel_data[3];
BlueShadow 5:dbedb2422089 155 float accel_rms=0.0;
BlueShadow 5:dbedb2422089 156 float mag_data[3];
BlueShadow 5:dbedb2422089 157 float mag_rms=0.0;
BlueShadow 5:dbedb2422089 158 float gyro_data[3];
BlueShadow 5:dbedb2422089 159 float gyro_rms=0.0;
BlueShadow 2:1df4b48824b1 160
BlueShadow 5:dbedb2422089 161 logDebug("Begin Data Acquisition from FXOS8700 and FXAS21002....\r\n\r\n");
BlueShadow 5:dbedb2422089 162
BlueShadow 5:dbedb2422089 163 static int post_interval_ms = 10000; //************* it was 30000, I don't want to wait 30 seconds ************************/
BlueShadow 5:dbedb2422089 164
BlueShadow 5:dbedb2422089 165
BlueShadow 2:1df4b48824b1 166
mfiore 0:6ce1803b7a03 167 //Sets the log level to INFO, higher log levels produce more log output.
mfiore 0:6ce1803b7a03 168 //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
BlueShadow 2:1df4b48824b1 169 mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
BlueShadow 2:1df4b48824b1 170
BlueShadow 2:1df4b48824b1 171
BlueShadow 2:1df4b48824b1 172 //****************************************************************************************************/
BlueShadow 2:1df4b48824b1 173 // Initialization Radio Section **********************************************************
BlueShadow 2:1df4b48824b1 174 //****************************************************************************************************/
mfiore 0:6ce1803b7a03 175 logInfo("initializing cellular radio");
mfiore 0:6ce1803b7a03 176 radio_ok = init_mtsas();
mfiore 0:6ce1803b7a03 177 if (! radio_ok) {
mfiore 0:6ce1803b7a03 178 while (true) {
mfiore 0:6ce1803b7a03 179 logError("failed to initialize cellular radio");
mfiore 0:6ce1803b7a03 180 wait(1);
mfiore 0:6ce1803b7a03 181 }
mfiore 0:6ce1803b7a03 182 }
BlueShadow 2:1df4b48824b1 183
BlueShadow 4:d16e07588838 184 Timer post_timer;
BlueShadow 4:d16e07588838 185 post_timer.start();
BlueShadow 4:d16e07588838 186 int timeStamp;
BlueShadow 4:d16e07588838 187 int countingLoop = 0;
BlueShadow 4:d16e07588838 188 Timer loop_timer;
BlueShadow 4:d16e07588838 189 loop_timer.start();
BlueShadow 2:1df4b48824b1 190
mfiore 0:6ce1803b7a03 191 logInfo("setting APN");
mfiore 0:6ce1803b7a03 192 if (radio->setApn(apn) != MTS_SUCCESS)
mfiore 0:6ce1803b7a03 193 logError("failed to set APN to \"%s\"", apn);
BlueShadow 2:1df4b48824b1 194 logInfo("APN set successful");
BlueShadow 2:1df4b48824b1 195
BlueShadow 4:d16e07588838 196 logInfo("bringing up the link"); //added to the program to create a connection outside of the while(1) loop.
BlueShadow 4:d16e07588838 197 if (! radio->connect()) {
BlueShadow 4:d16e07588838 198 logError("failed to bring up the link");
BlueShadow 4:d16e07588838 199 //return 0;
BlueShadow 4:d16e07588838 200 } else {
BlueShadow 4:d16e07588838 201
BlueShadow 4:d16e07588838 202 logInfo("Entering loop");
BlueShadow 5:dbedb2422089 203 while (countingLoop < 5 ) {
BlueShadow 4:d16e07588838 204 if (post_timer.read_ms() > post_interval_ms ) { // can this be changed to seconds?
BlueShadow 4:d16e07588838 205 timeStamp = post_timer.read_ms();
BlueShadow 4:d16e07588838 206 logDebug("timer read %d", timeStamp);
BlueShadow 4:d16e07588838 207 logDebug("timer value %d", post_interval_ms );
BlueShadow 4:d16e07588838 208 logDebug("loop count value %d", countingLoop );
BlueShadow 2:1df4b48824b1 209
BlueShadow 5:dbedb2422089 210 accel.acquire_accel_data_g(accel_data);
BlueShadow 5:dbedb2422089 211 accel_rms = sqrt(((accel_data[0]*accel_data[0])+(accel_data[1]*accel_data[1])+(accel_data[2]*accel_data[2]))/3);
BlueShadow 5:dbedb2422089 212 logDebug("accel %4.2f,\t%4.2f,\t%4.2f,\t\n",accel_data[0],accel_data[1],accel_data[2]);
BlueShadow 5:dbedb2422089 213 wait(0.01);
BlueShadow 5:dbedb2422089 214
BlueShadow 5:dbedb2422089 215 mag.acquire_mag_data_uT(mag_data);
BlueShadow 5:dbedb2422089 216 logDebug("mag %4.2f,\t%4.2f,\t%4.2f,\t\n",mag_data[0],mag_data[1],mag_data[2]);
BlueShadow 5:dbedb2422089 217 mag_rms = sqrt(((mag_data[0]*mag_data[0])+(mag_data[1]*mag_data[1])+(mag_data[2]*mag_data[2]))/3);
BlueShadow 5:dbedb2422089 218 wait(0.01);
BlueShadow 4:d16e07588838 219
BlueShadow 5:dbedb2422089 220 gyro.acquire_gyro_data_dps(gyro_data);
BlueShadow 5:dbedb2422089 221 logDebug("gyro %4.2f,\t%4.2f,\t%4.2f\r\n",gyro_data[0],gyro_data[1],gyro_data[2]);
BlueShadow 5:dbedb2422089 222 gyro_rms = sqrt(((gyro_data[0]*gyro_data[0])+(gyro_data[1]*gyro_data[1])+(gyro_data[2]*gyro_data[2]))/3);
BlueShadow 5:dbedb2422089 223 wait(0.01);
BlueShadow 4:d16e07588838 224
BlueShadow 5:dbedb2422089 225 logDebug("\r\nAccelerometer shock %f\r\n", accel_rms);
BlueShadow 5:dbedb2422089 226 logDebug("Magnitometer max value vs 1.0 %f\r\n", mag_rms);
BlueShadow 5:dbedb2422089 227 logDebug("Gyro RMS %f\r\n\n", gyro_rms);
BlueShadow 5:dbedb2422089 228 wait(0.01);
BlueShadow 2:1df4b48824b1 229
BlueShadow 5:dbedb2422089 230 // logDebug("https://quickstart.internetofthings.ibmcloud.com");
BlueShadow 5:dbedb2422089 231 // logInfo("bringing up the link");
BlueShadow 2:1df4b48824b1 232
BlueShadow 2:1df4b48824b1 233 // HTTPClient object used for HTTP requests.
BlueShadow 5:dbedb2422089 234 // HTTPClient http;
BlueShadow 2:1df4b48824b1 235
BlueShadow 2:1df4b48824b1 236 // Enable strict certificate validation.
BlueShadow 5:dbedb2422089 237 // http.setPeerVerification(VERIFY_PEER);
BlueShadow 2:1df4b48824b1 238
BlueShadow 2:1df4b48824b1 239 // Load certificates defined in ssl_certificates.h.
BlueShadow 2:1df4b48824b1 240 // See comments in ssl_certificates.h for information on how to get and format root certificates.
BlueShadow 5:dbedb2422089 241 // if (http.addRootCACertificate(ssl_certificates) != HTTP_OK)
BlueShadow 5:dbedb2422089 242 // logError("loading SSL certificates failed");
BlueShadow 2:1df4b48824b1 243
BlueShadow 2:1df4b48824b1 244 // HTTP POST example - QUickstart
BlueShadow 2:1df4b48824b1 245
BlueShadow 5:dbedb2422089 246 // char http_rx_buf[1024];
BlueShadow 5:dbedb2422089 247 // char http_tx_buf[1024];
BlueShadow 2:1df4b48824b1 248
BlueShadow 5:dbedb2422089 249 // logDebug("\r\nPosting Readings\r\n");
BlueShadow 5:dbedb2422089 250 // memset(http_tx_buf, 0, sizeof(http_tx_buf));
BlueShadow 5:dbedb2422089 251 // memset(http_rx_buf, 0, sizeof(http_rx_buf));
BlueShadow 5:dbedb2422089 252 // snprintf(http_tx_buf, sizeof(http_tx_buf), "{ \"AccX\": \"%f\" , \"AccY\": \"%f\", \"Accz\": \"%f\" }", accel_data[0],accel_data[1],accel_data[2]);
BlueShadow 5:dbedb2422089 253 // logDebug("%s",http_tx_buf);
BlueShadow 5:dbedb2422089 254 // HTTPResult res;
BlueShadow 2:1df4b48824b1 255
BlueShadow 2:1df4b48824b1 256 // IHTTPDataIn object - will contain data received from server.
BlueShadow 5:dbedb2422089 257 // HTTPText http_rx(http_rx_buf, sizeof(http_rx_buf));
BlueShadow 2:1df4b48824b1 258
BlueShadow 2:1df4b48824b1 259 // IHTTPDataOut object - contains data to be posted to server.
BlueShadow 2:1df4b48824b1 260 // HTTPJson automatically adds the JSON content-type header to the request.
BlueShadow 5:dbedb2422089 261 // HTTPJson http_tx(http_tx_buf, strlen(http_tx_buf)+1);
BlueShadow 2:1df4b48824b1 262
BlueShadow 2:1df4b48824b1 263 // Make a HTTP POST request to http://httpbin.org/
BlueShadow 5:dbedb2422089 264 // res = http.post("http://quickstart.internetofthings.ibmcloud.com/api/v0002/device/types/dragonflytype/devices/dragonfly02/events/myEvent", http_tx, &http_rx);
BlueShadow 5:dbedb2422089 265 // res = http.post("http://quickstart.internetofthings.ibmcloud.com/api/v0002/device/types/ TYPE VARIABLE /devices/ NAME VARIABLE /events/myEvent", http_tx, &http_rx);
BlueShadow 5:dbedb2422089 266 // /*** there should be no spaces in the web site listed in above line ***/
BlueShadow 5:dbedb2422089 267
BlueShadow 5:dbedb2422089 268 // if (res != HTTP_OK)
BlueShadow 5:dbedb2422089 269 // logError("HTTPS POST to Bluemix failed [%d][%s]", res, httpResToStr(res));
BlueShadow 5:dbedb2422089 270 // else
BlueShadow 5:dbedb2422089 271 // logInfo("HTTPS POST to Bluemix succeeded [%d]\r\n%s", http.getHTTPResponseCode(), http_rx_buf);
BlueShadow 2:1df4b48824b1 272
BlueShadow 2:1df4b48824b1 273 //logInfo("finished - bringing down link");
BlueShadow 4:d16e07588838 274 // radio->disconnect();
BlueShadow 2:1df4b48824b1 275 post_timer.reset();
BlueShadow 3:ff2bf7a1ece8 276 countingLoop +=1;
BlueShadow 2:1df4b48824b1 277 }
mfiore 0:6ce1803b7a03 278 }
BlueShadow 2:1df4b48824b1 279
BlueShadow 2:1df4b48824b1 280 //return 0;
mfiore 0:6ce1803b7a03 281 }
BlueShadow 4:d16e07588838 282 radio->disconnect();
BlueShadow 4:d16e07588838 283 timeStamp = loop_timer.read_ms();
BlueShadow 4:d16e07588838 284 logInfo("loop timer = %d", timeStamp);
BlueShadow 4:d16e07588838 285 logInfo("\r\n\n\nEnd Of Line\r\n");
mfiore 0:6ce1803b7a03 286 }
mfiore 0:6ce1803b7a03 287
BlueShadow 4:d16e07588838 288
BlueShadow 4:d16e07588838 289 /***********************************************
BlueShadow 4:d16e07588838 290 * below are the call routines
BlueShadow 4:d16e07588838 291 /***********************************************/
BlueShadow 4:d16e07588838 292
BlueShadow 2:1df4b48824b1 293 bool init_mtsas()
BlueShadow 2:1df4b48824b1 294 {
mfiore 0:6ce1803b7a03 295 io = new mts::MTSSerialFlowControl(RADIO_TX, RADIO_RX, RADIO_RTS, RADIO_CTS);
mfiore 0:6ce1803b7a03 296 if (! io)
mfiore 0:6ce1803b7a03 297 return false;
BlueShadow 2:1df4b48824b1 298
mfiore 0:6ce1803b7a03 299 // radio default baud rate is 115200
mfiore 0:6ce1803b7a03 300 io->baud(115200);
mfiore 0:6ce1803b7a03 301 radio = mts::CellularFactory::create(io);
mfiore 0:6ce1803b7a03 302 if (! radio)
mfiore 0:6ce1803b7a03 303 return false;
BlueShadow 2:1df4b48824b1 304
mfiore 0:6ce1803b7a03 305 // Transport must be set properly before any TCPSocketConnection or UDPSocket objects are created
mfiore 0:6ce1803b7a03 306 Transport::setTransport(radio);
BlueShadow 2:1df4b48824b1 307
mfiore 0:6ce1803b7a03 308 return true;
mfiore 0:6ce1803b7a03 309 }
mfiore 0:6ce1803b7a03 310
BlueShadow 2:1df4b48824b1 311 char* httpResToStr(HTTPResult res)
BlueShadow 2:1df4b48824b1 312 {
mfiore 0:6ce1803b7a03 313 switch(res) {
mfiore 0:6ce1803b7a03 314 case HTTP_PROCESSING:
mfiore 0:6ce1803b7a03 315 return "HTTP_PROCESSING";
mfiore 0:6ce1803b7a03 316 case HTTP_PARSE:
mfiore 0:6ce1803b7a03 317 return "HTTP_PARSE";
mfiore 0:6ce1803b7a03 318 case HTTP_DNS:
mfiore 0:6ce1803b7a03 319 return "HTTP_DNS";
mfiore 0:6ce1803b7a03 320 case HTTP_PRTCL:
mfiore 0:6ce1803b7a03 321 return "HTTP_PRTCL";
mfiore 0:6ce1803b7a03 322 case HTTP_NOTFOUND:
mfiore 0:6ce1803b7a03 323 return "HTTP_NOTFOUND";
mfiore 0:6ce1803b7a03 324 case HTTP_REFUSED:
mfiore 0:6ce1803b7a03 325 return "HTTP_REFUSED";
mfiore 0:6ce1803b7a03 326 case HTTP_ERROR:
mfiore 0:6ce1803b7a03 327 return "HTTP_ERROR";
mfiore 0:6ce1803b7a03 328 case HTTP_TIMEOUT:
mfiore 0:6ce1803b7a03 329 return "HTTP_TIMEOUT";
mfiore 0:6ce1803b7a03 330 case HTTP_CONN:
mfiore 0:6ce1803b7a03 331 return "HTTP_CONN";
mfiore 0:6ce1803b7a03 332 case HTTP_CLOSED:
mfiore 0:6ce1803b7a03 333 return "HTTP_CLOSED";
mfiore 0:6ce1803b7a03 334 case HTTP_REDIRECT:
mfiore 0:6ce1803b7a03 335 return "HTTP_REDIRECT";
mfiore 0:6ce1803b7a03 336 case HTTP_OK:
mfiore 0:6ce1803b7a03 337 return "HTTP_OK";
mfiore 0:6ce1803b7a03 338 default:
mfiore 0:6ce1803b7a03 339 return "HTTP Result unknown";
mfiore 0:6ce1803b7a03 340 }
mfiore 0:6ce1803b7a03 341 }
BlueShadow 2:1df4b48824b1 342