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:
Fri Aug 12 19:24:41 2016 +0000
Revision:
4:d16e07588838
Parent:
3:ff2bf7a1ece8
Child:
5:dbedb2422089
added a loop count of 25 before disconnecting the Cell Radio.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BlueShadow 2:1df4b48824b1 1 /** Combination of MultiTech HTTPS Example using json with ROHM Sennsor board and IBM Bluemix
BlueShadow 2:1df4b48824b1 2 *
BlueShadow 2:1df4b48824b1 3 * Configures the Sensor board for Ambient Light, cellular radio, brings up the cellular link,
BlueShadow 2:1df4b48824b1 4 * and does HTTPS POST requests.
mfiore 0:6ce1803b7a03 5 * 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 6 *
BlueShadow 2:1df4b48824b1 7 *
BlueShadow 2:1df4b48824b1 8 *
BlueShadow 2:1df4b48824b1 9 * The following hardware is required to successfully run this program:
BlueShadow 2:1df4b48824b1 10 * - MultiTech UDK2 (4" square white PCB with Arduino headers, antenna
BlueShadow 2:1df4b48824b1 11 * connector, micro USB ports, and 40-pin connector for Dragonfly)
BlueShadow 2:1df4b48824b1 12 * - MultiTech Dragonfly (1"x2" green PCB with Telit radio)
BlueShadow 2:1df4b48824b1 13 * - Rohm Electronics Sensor Board
BlueShadow 2:1df4b48824b1 14 * - Expansion board (LSM6DS0
BlueShadow 2:1df4b48824b1 15 * 3-axis accelerometer + 3-axis gyroscope, LIS3MDL 3-axis
BlueShadow 2:1df4b48824b1 16 * magnetometer, HTS221 humidity and temperature sensor and LPS25HB
BlueShadow 2:1df4b48824b1 17 * pressure sensor)
BlueShadow 2:1df4b48824b1 18 *
BlueShadow 2:1df4b48824b1 19 * What this program does:
BlueShadow 2:1df4b48824b1 20 * - reads data from all sensors on board
BlueShadow 2:1df4b48824b1 21 * - prints all sensor data to debug port on a periodic basis
BlueShadow 2:1df4b48824b1 22 * - optionally send data to BlueMix
BlueShadow 2:1df4b48824b1 23 * - All data is sent to a specific location determined by the student login.
BlueShadow 2:1df4b48824b1 24 * - BlueMix cloud platform (user must create own account and configure a device
BlueShadow 2:1df4b48824b1 25 * - you need to set the "VENDOR" and "MODEL"
BlueShadow 2:1df4b48824b1 26
BlueShadow 2:1df4b48824b1 27 * - you need to set the "do_cloud_post" flag to true for this to
BlueShadow 2:1df4b48824b1 28 * work
BlueShadow 2:1df4b48824b1 29 *
BlueShadow 2:1df4b48824b1 30 * Setup:
BlueShadow 2:1df4b48824b1 31 * - Correctly insert SIM card into Dragonfly
BlueShadow 2:1df4b48824b1 32 * - Seat the Dragonfly on the UDK2 board
BlueShadow 2:1df4b48824b1 33 * - Connect an antenna to the connector on the Dragonfly labled "M"
BlueShadow 2:1df4b48824b1 34 * - Stack the Base Shield on the UDK2 Arduino headers
BlueShadow 2:1df4b48824b1 35 * - Stack the MEMs board on top of the Base Shield
BlueShadow 2:1df4b48824b1 36 * - Plug in the power cable
BlueShadow 2:1df4b48824b1 37 * - Plug a micro USB cable into the port below and slightly to the
BlueShadow 2:1df4b48824b1 38 * left of the Dragonfly (NOT the port on the Dragonfly)
BlueShadow 2:1df4b48824b1 39 *
BlueShadow 2:1df4b48824b1 40 * Go have fun and make something cool!
BlueShadow 2:1df4b48824b1 41 *
BlueShadow 2:1df4b48824b1 42 ************************************************************************/
BlueShadow 2:1df4b48824b1 43 /*
BlueShadow 2:1df4b48824b1 44 Sample Program Description:
BlueShadow 2:1df4b48824b1 45 This Program will enable to Multi-Tech Dragonfly platform to utilize ROHM's Multi-sensor Shield Board.
BlueShadow 2:1df4b48824b1 46 This program will initialize all sensors on the shield and then read back the sensor data.
BlueShadow 2:1df4b48824b1 47 Data will then be output to the UART Debug Terminal every 1 second.
BlueShadow 2:1df4b48824b1 48
BlueShadow 2:1df4b48824b1 49 Sample Program Author:
BlueShadow 2:1df4b48824b1 50 ROHM USDC
BlueShadow 2:1df4b48824b1 51
BlueShadow 2:1df4b48824b1 52 Additional Resources:
BlueShadow 2:1df4b48824b1 53 ROHM Sensor Shield GitHub Repository: https://github.com/ROHMUSDC/ROHM_SensorPlatform_Multi-Sensor-Shield
mfiore 0:6ce1803b7a03 54 * NOTE: This example changes the baud rate of the debug port to 115200 baud!
mfiore 0:6ce1803b7a03 55 */
mfiore 0:6ce1803b7a03 56
mfiore 0:6ce1803b7a03 57 #include "mbed.h"
mfiore 0:6ce1803b7a03 58 #include "mtsas.h"
mfiore 0:6ce1803b7a03 59 #include "ssl_certificates.h"
BlueShadow 2:1df4b48824b1 60 #include <string> // added for string manipulation
BlueShadow 2:1df4b48824b1 61 #include <sstream>
BlueShadow 2:1df4b48824b1 62
BlueShadow 2:1df4b48824b1 63
BlueShadow 2:1df4b48824b1 64
BlueShadow 2:1df4b48824b1 65 //-------- Customise these values -----------
BlueShadow 2:1df4b48824b1 66
BlueShadow 2:1df4b48824b1 67 #define ORG "quickstart" // your organization or "quickstart"
BlueShadow 2:1df4b48824b1 68 #define DEVICE_TYPE "dragonflytype" // use this default for quickstart or customize to your registered device type
BlueShadow 2:1df4b48824b1 69 #define DEVICE_ID "dragonfly01" // use this default for quickstart or customize to your registered device id
BlueShadow 2:1df4b48824b1 70 #define TOKEN "pauljaeger" // not used with "quickstart"
BlueShadow 2:1df4b48824b1 71 #define EVENT "myEvent" // use this default or customize to your event type
BlueShadow 2:1df4b48824b1 72 //-------- Customise the above values --------
BlueShadow 2:1df4b48824b1 73
BlueShadow 2:1df4b48824b1 74
BlueShadow 2:1df4b48824b1 75 //char BlueMix_HEADER[] = "Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n";
BlueShadow 4:d16e07588838 76 //char BlueMix_HEADER[] = "Content-Type: application/json";
BlueShadow 2:1df4b48824b1 77
BlueShadow 4:d16e07588838 78 //const char BlueMix_URL[] = "http://" ORG ".internetofthings.ibmcloud.com/api/v0002/device/types/" DEVICE_TYPE "/devices/" DEVICE_ID "/events/" EVENT;
BlueShadow 2:1df4b48824b1 79 // replace typeID and deviceId with "" and delete ()
BlueShadow 2:1df4b48824b1 80 // replace $eventId = IBM will define in class.
BlueShadow 2:1df4b48824b1 81
BlueShadow 2:1df4b48824b1 82
BlueShadow 2:1df4b48824b1 83 //*****************************************************************************************************************************************************
BlueShadow 2:1df4b48824b1 84 DigitalOut Led1Out(LED1);
BlueShadow 2:1df4b48824b1 85
mfiore 0:6ce1803b7a03 86
mfiore 1:26b8af61d0ac 87 // This line controls the regulator's battery charger.
mfiore 1:26b8af61d0ac 88 // BC_NCE = 0 enables the battery charger
mfiore 1:26b8af61d0ac 89 // BC_NCE = 1 disables the battery charger
mfiore 1:26b8af61d0ac 90 DigitalOut bc_nce(PB_2);
mfiore 1:26b8af61d0ac 91
mfiore 0:6ce1803b7a03 92 bool init_mtsas();
mfiore 0:6ce1803b7a03 93 char* httpResToStr(HTTPResult res);
mfiore 0:6ce1803b7a03 94
mfiore 0:6ce1803b7a03 95 // The MTSSerialFlowControl object represents the physical serial link between the processor and the cellular radio.
mfiore 0:6ce1803b7a03 96 mts::MTSSerialFlowControl* io;
mfiore 0:6ce1803b7a03 97 // The Cellular object represents the cellular radio.
mfiore 0:6ce1803b7a03 98 mts::Cellular* radio;
mfiore 0:6ce1803b7a03 99
mfiore 0:6ce1803b7a03 100 // An APN is required for GSM radios.
BlueShadow 2:1df4b48824b1 101 static const char apn[] = "iot.aer.net";
mfiore 0:6ce1803b7a03 102
mfiore 0:6ce1803b7a03 103 bool radio_ok = false;
mfiore 0:6ce1803b7a03 104
BlueShadow 2:1df4b48824b1 105
BlueShadow 2:1df4b48824b1 106 #define RPR0521 //RPR0521 Ambient Light Sensor.
BlueShadow 2:1df4b48824b1 107 //Define Pins for I2C Interface
BlueShadow 2:1df4b48824b1 108 I2C i2c(I2C_SDA, I2C_SCL);
BlueShadow 2:1df4b48824b1 109 bool RepStart = true;
BlueShadow 2:1df4b48824b1 110 bool NoRepStart = false;
BlueShadow 2:1df4b48824b1 111
BlueShadow 2:1df4b48824b1 112 #ifdef RPR0521
BlueShadow 2:1df4b48824b1 113 int RPR0521_addr_w = 0x70; //7bit addr = 0x38, with write bit 0
BlueShadow 2:1df4b48824b1 114 int RPR0521_addr_r = 0x71; //7bit addr = 0x38, with read bit 1
BlueShadow 2:1df4b48824b1 115 char RPR0521_ModeControl[2] = {0x41, 0xE6};
BlueShadow 2:1df4b48824b1 116 char RPR0521_ALSPSControl[2] = {0x42, 0x03};
BlueShadow 2:1df4b48824b1 117 char RPR0521_Persist[2] = {0x43, 0x20};
BlueShadow 2:1df4b48824b1 118 char RPR0521_Addr_ReadData = 0x44;
BlueShadow 2:1df4b48824b1 119 char RPR0521_Content_ReadData[6];
BlueShadow 2:1df4b48824b1 120 int RPR0521_PS_RAWOUT = 0; //this is an output
BlueShadow 2:1df4b48824b1 121 float RPR0521_PS_OUT = 0;
BlueShadow 2:1df4b48824b1 122 int RPR0521_ALS_D0_RAWOUT = 0;
BlueShadow 2:1df4b48824b1 123 int RPR0521_ALS_D1_RAWOUT = 0;
BlueShadow 2:1df4b48824b1 124 float RPR0521_ALS_DataRatio = 0;
BlueShadow 2:1df4b48824b1 125 float RPR0521_ALS_OUT = 0; //this is an output
BlueShadow 2:1df4b48824b1 126 float RPR0521_ALS[2]; // is this ok taking an int to the [0] value and float to [1]???????????
BlueShadow 2:1df4b48824b1 127 #endif
BlueShadow 2:1df4b48824b1 128
BlueShadow 2:1df4b48824b1 129 bool init_mtsas();
BlueShadow 2:1df4b48824b1 130 void ReadRPR0521_ALS ();
BlueShadow 2:1df4b48824b1 131 char* httpResToStr(HTTPResult res);
BlueShadow 2:1df4b48824b1 132
BlueShadow 2:1df4b48824b1 133
BlueShadow 2:1df4b48824b1 134 namespace patch // I have no idea why this is in the code *********************
BlueShadow 2:1df4b48824b1 135 {
BlueShadow 2:1df4b48824b1 136 template < typename T > std::string to_string( const T& n )
BlueShadow 2:1df4b48824b1 137 {
BlueShadow 2:1df4b48824b1 138 std::ostringstream stm ;
BlueShadow 2:1df4b48824b1 139 stm << n ;
BlueShadow 2:1df4b48824b1 140 return stm.str() ;
BlueShadow 2:1df4b48824b1 141 }
BlueShadow 2:1df4b48824b1 142 }
BlueShadow 2:1df4b48824b1 143
BlueShadow 2:1df4b48824b1 144
BlueShadow 2:1df4b48824b1 145 /****************************************************************************************************
BlueShadow 2:1df4b48824b1 146 // main
BlueShadow 2:1df4b48824b1 147 ****************************************************************************************************/
BlueShadow 2:1df4b48824b1 148
BlueShadow 2:1df4b48824b1 149 int main()
BlueShadow 2:1df4b48824b1 150 {
mfiore 1:26b8af61d0ac 151 // Disable the battery charger unless a battery is attached.
mfiore 1:26b8af61d0ac 152 bc_nce = 1;
BlueShadow 2:1df4b48824b1 153
BlueShadow 3:ff2bf7a1ece8 154 static int post_interval_ms = 500; //************* I don't want to wait 30 seconds ************************/
BlueShadow 2:1df4b48824b1 155
mfiore 0:6ce1803b7a03 156 // Change the baud rate of the debug port from the default 9600 to 115200.
mfiore 0:6ce1803b7a03 157 Serial debug(USBTX, USBRX);
BlueShadow 2:1df4b48824b1 158
mfiore 0:6ce1803b7a03 159 debug.baud(115200);
BlueShadow 2:1df4b48824b1 160
mfiore 0:6ce1803b7a03 161 //Sets the log level to INFO, higher log levels produce more log output.
mfiore 0:6ce1803b7a03 162 //Possible levels: NONE, FATAL, ERROR, WARNING, INFO, DEBUG, TRACE
BlueShadow 2:1df4b48824b1 163 mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL);
BlueShadow 2:1df4b48824b1 164
BlueShadow 2:1df4b48824b1 165
BlueShadow 2:1df4b48824b1 166
BlueShadow 2:1df4b48824b1 167 //****************************************************************************************************
BlueShadow 2:1df4b48824b1 168 // Initialize I2C Devices ************
BlueShadow 2:1df4b48824b1 169 //****************************************************************************************************/
BlueShadow 2:1df4b48824b1 170
BlueShadow 2:1df4b48824b1 171 #ifdef RPR0521
BlueShadow 2:1df4b48824b1 172 i2c.write(RPR0521_addr_w, &RPR0521_ModeControl[0], 2, false);
BlueShadow 2:1df4b48824b1 173 i2c.write(RPR0521_addr_w, &RPR0521_ALSPSControl[0], 2, false);
BlueShadow 2:1df4b48824b1 174 i2c.write(RPR0521_addr_w, &RPR0521_Persist[0], 2, false);
BlueShadow 2:1df4b48824b1 175 #endif
BlueShadow 2:1df4b48824b1 176
BlueShadow 2:1df4b48824b1 177 //****************************************************************************************************/
BlueShadow 2:1df4b48824b1 178 // Initialization Radio Section **********************************************************
BlueShadow 2:1df4b48824b1 179 //****************************************************************************************************/
mfiore 0:6ce1803b7a03 180 logInfo("initializing cellular radio");
mfiore 0:6ce1803b7a03 181 radio_ok = init_mtsas();
mfiore 0:6ce1803b7a03 182 if (! radio_ok) {
mfiore 0:6ce1803b7a03 183 while (true) {
mfiore 0:6ce1803b7a03 184 logError("failed to initialize cellular radio");
mfiore 0:6ce1803b7a03 185 wait(1);
mfiore 0:6ce1803b7a03 186 }
mfiore 0:6ce1803b7a03 187 }
BlueShadow 2:1df4b48824b1 188
BlueShadow 4:d16e07588838 189 Timer post_timer;
BlueShadow 4:d16e07588838 190 post_timer.start();
BlueShadow 4:d16e07588838 191 int timeStamp;
BlueShadow 4:d16e07588838 192 int countingLoop = 0;
BlueShadow 4:d16e07588838 193 Timer loop_timer;
BlueShadow 4:d16e07588838 194 loop_timer.start();
BlueShadow 2:1df4b48824b1 195
mfiore 0:6ce1803b7a03 196 logInfo("setting APN");
mfiore 0:6ce1803b7a03 197 if (radio->setApn(apn) != MTS_SUCCESS)
mfiore 0:6ce1803b7a03 198 logError("failed to set APN to \"%s\"", apn);
BlueShadow 2:1df4b48824b1 199 logInfo("APN set successful");
BlueShadow 2:1df4b48824b1 200
BlueShadow 4:d16e07588838 201 logInfo("bringing up the link"); //added to the program to create a connection outside of the while(1) loop.
BlueShadow 4:d16e07588838 202 if (! radio->connect()) {
BlueShadow 4:d16e07588838 203 logError("failed to bring up the link");
BlueShadow 4:d16e07588838 204 //return 0;
BlueShadow 4:d16e07588838 205 } else {
BlueShadow 4:d16e07588838 206
BlueShadow 4:d16e07588838 207 logInfo("Entering loop");
BlueShadow 4:d16e07588838 208 while (countingLoop < 25 ) {
BlueShadow 4:d16e07588838 209 if (post_timer.read_ms() > post_interval_ms ) { // can this be changed to seconds?
BlueShadow 4:d16e07588838 210 timeStamp = post_timer.read_ms();
BlueShadow 4:d16e07588838 211 logDebug("timer read %d", timeStamp);
BlueShadow 4:d16e07588838 212 logDebug("timer value %d", post_interval_ms );
BlueShadow 4:d16e07588838 213 logDebug("loop count value %d", countingLoop );
BlueShadow 2:1df4b48824b1 214
BlueShadow 2:1df4b48824b1 215 #ifdef RPR0521 //als digital
BlueShadow 4:d16e07588838 216 ReadRPR0521_ALS ();
BlueShadow 4:d16e07588838 217 int sensor_data = RPR0521_ALS[0];
BlueShadow 4:d16e07588838 218 int proximity_data = RPR0521_ALS[1];
BlueShadow 2:1df4b48824b1 219 #else
BlueShadow 4:d16e07588838 220 int sensor_data = -1;
BlueShadow 4:d16e07588838 221 int proximity_data = -1;
BlueShadow 2:1df4b48824b1 222 #endif
BlueShadow 4:d16e07588838 223 logDebug("\r\nPosting Light Reading: %d Proximity Reading: %d",sensor_data,proximity_data);
BlueShadow 4:d16e07588838 224
BlueShadow 4:d16e07588838 225 logDebug("https://quickstart.internetofthings.ibmcloud.com");
BlueShadow 4:d16e07588838 226
BlueShadow 2:1df4b48824b1 227 // http_tx.clear();
BlueShadow 2:1df4b48824b1 228
BlueShadow 4:d16e07588838 229 logInfo("bringing up the link");
BlueShadow 2:1df4b48824b1 230
BlueShadow 2:1df4b48824b1 231 // HTTPClient object used for HTTP requests.
BlueShadow 2:1df4b48824b1 232 HTTPClient http;
BlueShadow 2:1df4b48824b1 233
BlueShadow 2:1df4b48824b1 234 // Enable strict certificate validation.
BlueShadow 2:1df4b48824b1 235 http.setPeerVerification(VERIFY_PEER);
BlueShadow 2:1df4b48824b1 236
BlueShadow 2:1df4b48824b1 237 // Load certificates defined in ssl_certificates.h.
BlueShadow 2:1df4b48824b1 238 // See comments in ssl_certificates.h for information on how to get and format root certificates.
BlueShadow 2:1df4b48824b1 239 if (http.addRootCACertificate(ssl_certificates) != HTTP_OK)
BlueShadow 2:1df4b48824b1 240 logError("loading SSL certificates failed");
BlueShadow 2:1df4b48824b1 241
BlueShadow 2:1df4b48824b1 242 // HTTP POST example - QUickstart
BlueShadow 2:1df4b48824b1 243
BlueShadow 2:1df4b48824b1 244 char http_rx_buf[1024];
BlueShadow 2:1df4b48824b1 245 char http_tx_buf[1024];
BlueShadow 2:1df4b48824b1 246
BlueShadow 2:1df4b48824b1 247 memset(http_tx_buf, 0, sizeof(http_tx_buf));
BlueShadow 2:1df4b48824b1 248 memset(http_rx_buf, 0, sizeof(http_rx_buf));
BlueShadow 3:ff2bf7a1ece8 249 snprintf(http_tx_buf, sizeof(http_tx_buf), "{ \"Light\": \"%d\" , \"Proximity\": \"%d\" }", sensor_data,proximity_data);
BlueShadow 2:1df4b48824b1 250 logDebug("%s",http_tx_buf);
BlueShadow 2:1df4b48824b1 251 HTTPResult res;
BlueShadow 2:1df4b48824b1 252
BlueShadow 2:1df4b48824b1 253 // IHTTPDataIn object - will contain data received from server.
BlueShadow 2:1df4b48824b1 254 HTTPText http_rx(http_rx_buf, sizeof(http_rx_buf));
BlueShadow 2:1df4b48824b1 255
BlueShadow 2:1df4b48824b1 256 // IHTTPDataOut object - contains data to be posted to server.
BlueShadow 2:1df4b48824b1 257 // HTTPJson automatically adds the JSON content-type header to the request.
BlueShadow 2:1df4b48824b1 258 HTTPJson http_tx(http_tx_buf, strlen(http_tx_buf)+1);
BlueShadow 2:1df4b48824b1 259
BlueShadow 2:1df4b48824b1 260 // Make a HTTP POST request to http://httpbin.org/
BlueShadow 3:ff2bf7a1ece8 261 res = http.post("http://quickstart.internetofthings.ibmcloud.com/api/v0002/device/types/dragonflytype/devices/dragonfly02/events/myEvent", http_tx, &http_rx);
BlueShadow 2:1df4b48824b1 262 if (res != HTTP_OK)
BlueShadow 2:1df4b48824b1 263 logError("HTTPS POST to Bluemix failed [%d][%s]", res, httpResToStr(res));
BlueShadow 2:1df4b48824b1 264 else
BlueShadow 2:1df4b48824b1 265 logInfo("HTTPS POST to Bluemix succeeded [%d]\r\n%s", http.getHTTPResponseCode(), http_rx_buf);
BlueShadow 2:1df4b48824b1 266
BlueShadow 2:1df4b48824b1 267 //logInfo("finished - bringing down link");
BlueShadow 4:d16e07588838 268 // radio->disconnect();
BlueShadow 2:1df4b48824b1 269 post_timer.reset();
BlueShadow 3:ff2bf7a1ece8 270 countingLoop +=1;
BlueShadow 2:1df4b48824b1 271 }
mfiore 0:6ce1803b7a03 272 }
BlueShadow 2:1df4b48824b1 273
BlueShadow 2:1df4b48824b1 274 //return 0;
mfiore 0:6ce1803b7a03 275 }
BlueShadow 4:d16e07588838 276 radio->disconnect();
BlueShadow 4:d16e07588838 277 timeStamp = loop_timer.read_ms();
BlueShadow 4:d16e07588838 278 logInfo("loop timer = %d", timeStamp);
BlueShadow 4:d16e07588838 279
BlueShadow 4:d16e07588838 280 logInfo("\r\n\n\nEnd Of Line\r\n");
mfiore 0:6ce1803b7a03 281 }
mfiore 0:6ce1803b7a03 282
BlueShadow 4:d16e07588838 283
BlueShadow 4:d16e07588838 284 /***********************************************
BlueShadow 4:d16e07588838 285 * below are the call routines
BlueShadow 4:d16e07588838 286 /***********************************************/
BlueShadow 4:d16e07588838 287
BlueShadow 2:1df4b48824b1 288 bool init_mtsas()
BlueShadow 2:1df4b48824b1 289 {
mfiore 0:6ce1803b7a03 290 io = new mts::MTSSerialFlowControl(RADIO_TX, RADIO_RX, RADIO_RTS, RADIO_CTS);
mfiore 0:6ce1803b7a03 291 if (! io)
mfiore 0:6ce1803b7a03 292 return false;
BlueShadow 2:1df4b48824b1 293
mfiore 0:6ce1803b7a03 294 // radio default baud rate is 115200
mfiore 0:6ce1803b7a03 295 io->baud(115200);
mfiore 0:6ce1803b7a03 296 radio = mts::CellularFactory::create(io);
mfiore 0:6ce1803b7a03 297 if (! radio)
mfiore 0:6ce1803b7a03 298 return false;
BlueShadow 2:1df4b48824b1 299
mfiore 0:6ce1803b7a03 300 // Transport must be set properly before any TCPSocketConnection or UDPSocket objects are created
mfiore 0:6ce1803b7a03 301 Transport::setTransport(radio);
BlueShadow 2:1df4b48824b1 302
mfiore 0:6ce1803b7a03 303 return true;
mfiore 0:6ce1803b7a03 304 }
mfiore 0:6ce1803b7a03 305
BlueShadow 2:1df4b48824b1 306 char* httpResToStr(HTTPResult res)
BlueShadow 2:1df4b48824b1 307 {
mfiore 0:6ce1803b7a03 308 switch(res) {
mfiore 0:6ce1803b7a03 309 case HTTP_PROCESSING:
mfiore 0:6ce1803b7a03 310 return "HTTP_PROCESSING";
mfiore 0:6ce1803b7a03 311 case HTTP_PARSE:
mfiore 0:6ce1803b7a03 312 return "HTTP_PARSE";
mfiore 0:6ce1803b7a03 313 case HTTP_DNS:
mfiore 0:6ce1803b7a03 314 return "HTTP_DNS";
mfiore 0:6ce1803b7a03 315 case HTTP_PRTCL:
mfiore 0:6ce1803b7a03 316 return "HTTP_PRTCL";
mfiore 0:6ce1803b7a03 317 case HTTP_NOTFOUND:
mfiore 0:6ce1803b7a03 318 return "HTTP_NOTFOUND";
mfiore 0:6ce1803b7a03 319 case HTTP_REFUSED:
mfiore 0:6ce1803b7a03 320 return "HTTP_REFUSED";
mfiore 0:6ce1803b7a03 321 case HTTP_ERROR:
mfiore 0:6ce1803b7a03 322 return "HTTP_ERROR";
mfiore 0:6ce1803b7a03 323 case HTTP_TIMEOUT:
mfiore 0:6ce1803b7a03 324 return "HTTP_TIMEOUT";
mfiore 0:6ce1803b7a03 325 case HTTP_CONN:
mfiore 0:6ce1803b7a03 326 return "HTTP_CONN";
mfiore 0:6ce1803b7a03 327 case HTTP_CLOSED:
mfiore 0:6ce1803b7a03 328 return "HTTP_CLOSED";
mfiore 0:6ce1803b7a03 329 case HTTP_REDIRECT:
mfiore 0:6ce1803b7a03 330 return "HTTP_REDIRECT";
mfiore 0:6ce1803b7a03 331 case HTTP_OK:
mfiore 0:6ce1803b7a03 332 return "HTTP_OK";
mfiore 0:6ce1803b7a03 333 default:
mfiore 0:6ce1803b7a03 334 return "HTTP Result unknown";
mfiore 0:6ce1803b7a03 335 }
mfiore 0:6ce1803b7a03 336 }
BlueShadow 2:1df4b48824b1 337
BlueShadow 2:1df4b48824b1 338
BlueShadow 2:1df4b48824b1 339 #ifdef RPR0521 //als digital
BlueShadow 2:1df4b48824b1 340 void ReadRPR0521_ALS ()
BlueShadow 2:1df4b48824b1 341 {
BlueShadow 2:1df4b48824b1 342 i2c.write(RPR0521_addr_w, &RPR0521_Addr_ReadData, 1, RepStart);
BlueShadow 2:1df4b48824b1 343 i2c.read(RPR0521_addr_r, &RPR0521_Content_ReadData[0], 6, NoRepStart);
BlueShadow 2:1df4b48824b1 344
BlueShadow 2:1df4b48824b1 345 RPR0521_ALS[1] = (RPR0521_Content_ReadData[1]<<8) | (RPR0521_Content_ReadData[0]);
BlueShadow 2:1df4b48824b1 346 RPR0521_ALS_D0_RAWOUT = (RPR0521_Content_ReadData[3]<<8) | (RPR0521_Content_ReadData[2]);
BlueShadow 2:1df4b48824b1 347 RPR0521_ALS_D1_RAWOUT = (RPR0521_Content_ReadData[5]<<8) | (RPR0521_Content_ReadData[4]);
BlueShadow 2:1df4b48824b1 348 RPR0521_ALS_DataRatio = (float)RPR0521_ALS_D1_RAWOUT / (float)RPR0521_ALS_D0_RAWOUT;
BlueShadow 2:1df4b48824b1 349
BlueShadow 2:1df4b48824b1 350 if(RPR0521_ALS_DataRatio < (float)0.595) {
BlueShadow 2:1df4b48824b1 351 RPR0521_ALS[0] = ((float)1.682*(float)RPR0521_ALS_D0_RAWOUT - (float)1.877*(float)RPR0521_ALS_D1_RAWOUT);
BlueShadow 2:1df4b48824b1 352 } else if(RPR0521_ALS_DataRatio < (float)1.015) {
BlueShadow 2:1df4b48824b1 353 RPR0521_ALS[0] = ((float)0.644*(float)RPR0521_ALS_D0_RAWOUT - (float)0.132*(float)RPR0521_ALS_D1_RAWOUT);
BlueShadow 2:1df4b48824b1 354 } else if(RPR0521_ALS_DataRatio < (float)1.352) {
BlueShadow 2:1df4b48824b1 355 RPR0521_ALS[0] = ((float)0.756*(float)RPR0521_ALS_D0_RAWOUT - (float)0.243*(float)RPR0521_ALS_D1_RAWOUT);
BlueShadow 2:1df4b48824b1 356 } else if(RPR0521_ALS_DataRatio < (float)3.053) {
BlueShadow 2:1df4b48824b1 357 RPR0521_ALS[0] = ((float)0.766*(float)RPR0521_ALS_D0_RAWOUT - (float)0.25*(float)RPR0521_ALS_D1_RAWOUT);
BlueShadow 2:1df4b48824b1 358 } else {
BlueShadow 2:1df4b48824b1 359 RPR0521_ALS[0] = 0;
BlueShadow 2:1df4b48824b1 360 }
BlueShadow 2:1df4b48824b1 361 logDebug("RPR-0521 ALS/PROX Sensor Data:\r\n");
BlueShadow 2:1df4b48824b1 362 logDebug(" ALS = %0.2f lx\r\n", RPR0521_ALS[0]);
BlueShadow 2:1df4b48824b1 363 logDebug(" PROX= %0.2f ADC Counts\r\n", RPR0521_ALS[1]); //defined as a float but is an unsigned.
BlueShadow 2:1df4b48824b1 364
BlueShadow 2:1df4b48824b1 365 }
BlueShadow 2:1df4b48824b1 366 #endif