Rev 1.0 4/26/2016 Paul Jaeger - Multitech, Brian Huey - Sprint Changed post interval to 2000ms added temp, analoguv and pressure to http post added alias: TEMP ANALOG-UV PRESSURE concatenated http post, to post all within the same routine and check for error after the post confirmed that data is published to Exosite
Dependencies: MbedJSONValue mbed mtsas
Fork of UUU_MultiTech_Dragonfly_Sprint by
main.cpp@12:9942995476ef, 2016-04-26 (annotated)
- Committer:
- brianhuey
- Date:
- Tue Apr 26 16:21:12 2016 +0000
- Revision:
- 12:9942995476ef
- Parent:
- 11:d2ac3fa6f2d3
- Child:
- 13:cc2f24b260ab
Rev 1.0 4/26/2016 Paul Jaeger - Multitech, Brian Huey - Sprint; Changed post interval to 2000ms ; added temp, analoguv and pressure to http post; added alias: ; TEMP; ANALOG-UV; PRESSURE; concatenated http post, to po
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 0:a44e71488e1f | 1 | /************************************************************************* |
BlueShadow | 8:e78dcfad254b | 2 | * Dragonfly Example program for 2016 Sprint Exosite Training |
BlueShadow | 6:7946b5c2376a | 3 | * |
mfiore | 0:a44e71488e1f | 4 | * The following hardware is required to successfully run this program: |
mfiore | 0:a44e71488e1f | 5 | * - MultiTech UDK2 (4" square white PCB with Arduino headers, antenna |
mfiore | 0:a44e71488e1f | 6 | * connector, micro USB ports, and 40-pin connector for Dragonfly) |
mfiore | 0:a44e71488e1f | 7 | * - MultiTech Dragonfly (1"x2" green PCB with Telit radio) |
BlueShadow | 8:e78dcfad254b | 8 | * - Rohm Electronics Sensor Board |
BlueShadow | 8:e78dcfad254b | 9 | |
BlueShadow | 8:e78dcfad254b | 10 | * - Expansion board (LSM6DS0 |
mfiore | 0:a44e71488e1f | 11 | * 3-axis accelerometer + 3-axis gyroscope, LIS3MDL 3-axis |
mfiore | 0:a44e71488e1f | 12 | * magnetometer, HTS221 humidity and temperature sensor and LPS25HB |
mfiore | 0:a44e71488e1f | 13 | * pressure sensor) |
mfiore | 0:a44e71488e1f | 14 | * |
mfiore | 0:a44e71488e1f | 15 | * What this program does: |
BlueShadow | 8:e78dcfad254b | 16 | * - reads data from all sensors on board |
mfiore | 0:a44e71488e1f | 17 | * - prints all sensor data to debug port on a periodic basis |
BlueShadow | 8:e78dcfad254b | 18 | * - optionally send data to Exosite |
BlueShadow | 8:e78dcfad254b | 19 | * - All data is sent to a specific location determined by the student login. |
BlueShadow | 8:e78dcfad254b | 20 | * - Exosite cloud platform (user must create own account and configure a device |
BlueShadow | 8:e78dcfad254b | 21 | * - you need to set the "VENDOR" and "MODEL" |
BlueShadow | 8:e78dcfad254b | 22 | |
mfiore | 5:a946ef74a8c4 | 23 | * - you need to set the "do_cloud_post" flag to true for this to |
mfiore | 5:a946ef74a8c4 | 24 | * work |
mfiore | 0:a44e71488e1f | 25 | * |
mfiore | 0:a44e71488e1f | 26 | * Setup: |
mfiore | 0:a44e71488e1f | 27 | * - Correctly insert SIM card into Dragonfly |
mfiore | 0:a44e71488e1f | 28 | * - Seat the Dragonfly on the UDK2 board |
mfiore | 0:a44e71488e1f | 29 | * - Connect an antenna to the connector on the Dragonfly labled "M" |
mfiore | 0:a44e71488e1f | 30 | * - Stack the Base Shield on the UDK2 Arduino headers |
mfiore | 0:a44e71488e1f | 31 | * - Stack the MEMs board on top of the Base Shield |
mfiore | 0:a44e71488e1f | 32 | * - Plug in the power cable |
mfiore | 0:a44e71488e1f | 33 | * - Plug a micro USB cable into the port below and slightly to the |
mfiore | 0:a44e71488e1f | 34 | * left of the Dragonfly (NOT the port on the Dragonfly) |
mfiore | 0:a44e71488e1f | 35 | * |
mfiore | 0:a44e71488e1f | 36 | * Go have fun and make something cool! |
mfiore | 0:a44e71488e1f | 37 | * |
mfiore | 0:a44e71488e1f | 38 | ************************************************************************/ |
BlueShadow | 6:7946b5c2376a | 39 | /* |
BlueShadow | 6:7946b5c2376a | 40 | Sample Program Description: |
BlueShadow | 6:7946b5c2376a | 41 | This Program will enable to Multi-Tech Dragonfly platform to utilize ROHM's Multi-sensor Shield Board. |
BlueShadow | 6:7946b5c2376a | 42 | This program will initialize all sensors on the shield and then read back the sensor data. |
BlueShadow | 6:7946b5c2376a | 43 | Data will then be output to the UART Debug Terminal every 1 second. |
BlueShadow | 6:7946b5c2376a | 44 | |
BlueShadow | 6:7946b5c2376a | 45 | Sample Program Author: |
BlueShadow | 6:7946b5c2376a | 46 | ROHM USDC |
BlueShadow | 6:7946b5c2376a | 47 | |
BlueShadow | 6:7946b5c2376a | 48 | Additional Resources: |
BlueShadow | 6:7946b5c2376a | 49 | ROHM Sensor Shield GitHub Repository: https://github.com/ROHMUSDC/ROHM_SensorPlatform_Multi-Sensor-Shield |
brianhuey | 12:9942995476ef | 50 | |
brianhuey | 12:9942995476ef | 51 | Rev 1.0 4/26/2016 Paul Jaeger - Multitech, Brian Huey - Sprint |
brianhuey | 12:9942995476ef | 52 | Changed post interval to 2000ms |
brianhuey | 12:9942995476ef | 53 | added temp, analoguv and pressure to http post |
brianhuey | 12:9942995476ef | 54 | added alias: |
brianhuey | 12:9942995476ef | 55 | TEMP |
brianhuey | 12:9942995476ef | 56 | ANALOG-UV |
brianhuey | 12:9942995476ef | 57 | PRESSURE |
brianhuey | 12:9942995476ef | 58 | concatenated http post, to post all within the same routine and check for error after the post |
brianhuey | 12:9942995476ef | 59 | confirmed that data is published to Exosite |
BlueShadow | 6:7946b5c2376a | 60 | */ |
BlueShadow | 6:7946b5c2376a | 61 | |
BlueShadow | 6:7946b5c2376a | 62 | |
mfiore | 0:a44e71488e1f | 63 | #include "mbed.h" |
mfiore | 0:a44e71488e1f | 64 | #include "mtsas.h" |
mfiore | 0:a44e71488e1f | 65 | #include <string> |
BlueShadow | 8:e78dcfad254b | 66 | #include <sstream> |
BlueShadow | 8:e78dcfad254b | 67 | |
brianhuey | 12:9942995476ef | 68 | #define EXOSITE_CIK "41de7cf671184e2838c8f185e8aa60ed1c07639e" |
BlueShadow | 8:e78dcfad254b | 69 | |
BlueShadow | 8:e78dcfad254b | 70 | char EXOSITE_HEADER[] = "X-Exosite-CIK: " EXOSITE_CIK "\r\nAccept: application/x-www-form-urlencoded; charset=utf-8\r\n"; |
BlueShadow | 8:e78dcfad254b | 71 | const char EXOSITE_URL[] = "https://m2.exosite.com:443/onep:v1/stack/alias"; |
BlueShadow | 8:e78dcfad254b | 72 | |
BlueShadow | 8:e78dcfad254b | 73 | DigitalOut Led1Out(LED1); |
mfiore | 0:a44e71488e1f | 74 | |
mfiore | 0:a44e71488e1f | 75 | // Debug serial port |
mfiore | 0:a44e71488e1f | 76 | static Serial debug(USBTX, USBRX); |
mfiore | 0:a44e71488e1f | 77 | |
mfiore | 0:a44e71488e1f | 78 | // MTSSerialFlowControl - serial link between processor and radio |
mfiore | 1:a049d113e250 | 79 | static MTSSerialFlowControl* io; |
mfiore | 0:a44e71488e1f | 80 | |
mfiore | 0:a44e71488e1f | 81 | // Cellular - radio object for cellular operations (SMS, TCP, etc) |
mfiore | 0:a44e71488e1f | 82 | Cellular* radio; |
mfiore | 0:a44e71488e1f | 83 | |
mfiore | 0:a44e71488e1f | 84 | // APN associated with SIM card |
mfiore | 4:730b61258422 | 85 | // this APN should work for the AT&T SIM that came with your Dragonfly |
mfiore | 4:730b61258422 | 86 | //static const std::string apn = ""; |
BlueShadow | 8:e78dcfad254b | 87 | static const std::string apn = "b2b.tmobile.com"; |
mfiore | 5:a946ef74a8c4 | 88 | |
mfiore | 5:a946ef74a8c4 | 89 | // set to true if you want to post to the cloud |
mfiore | 5:a946ef74a8c4 | 90 | //bool do_cloud_post = false; |
mfiore | 5:a946ef74a8c4 | 91 | bool do_cloud_post = true; |
mfiore | 5:a946ef74a8c4 | 92 | |
mfiore | 0:a44e71488e1f | 93 | // variables for sensor data |
mfiore | 0:a44e71488e1f | 94 | float temp_celsius; |
mfiore | 0:a44e71488e1f | 95 | float humidity_percent; |
mfiore | 0:a44e71488e1f | 96 | float pressure_mbar; |
mfiore | 0:a44e71488e1f | 97 | float moisture_percent; |
mfiore | 0:a44e71488e1f | 98 | int32_t mag_mgauss[3]; |
mfiore | 0:a44e71488e1f | 99 | int32_t acc_mg[3]; |
mfiore | 0:a44e71488e1f | 100 | int32_t gyro_mdps[3]; |
mfiore | 0:a44e71488e1f | 101 | |
mfiore | 0:a44e71488e1f | 102 | // misc variables |
BlueShadow | 9:6475e1b83491 | 103 | static char wall_of_dash[] = "--------------------------------------------------"; |
brianhuey | 12:9942995476ef | 104 | static int post_interval_ms = 2000; /* was set to 30000, but huey changed to 2000 */ |
mfiore | 0:a44e71488e1f | 105 | int debug_baud = 115200; |
mfiore | 0:a44e71488e1f | 106 | |
BlueShadow | 6:7946b5c2376a | 107 | |
BlueShadow | 6:7946b5c2376a | 108 | |
BlueShadow | 6:7946b5c2376a | 109 | /**************************************************************************************************** |
BlueShadow | 6:7946b5c2376a | 110 | |
BlueShadow | 6:7946b5c2376a | 111 | ****************************************************************************************************/ |
BlueShadow | 6:7946b5c2376a | 112 | |
BlueShadow | 6:7946b5c2376a | 113 | //Macros for checking each of the different Sensor Devices |
BlueShadow | 6:7946b5c2376a | 114 | #define AnalogTemp //BDE0600 |
BlueShadow | 6:7946b5c2376a | 115 | #define AnalogUV //ML8511 |
BlueShadow | 6:7946b5c2376a | 116 | #define HallSensor //BU52011 |
BlueShadow | 6:7946b5c2376a | 117 | #define RPR0521 //RPR0521 |
BlueShadow | 6:7946b5c2376a | 118 | #define KMX62 //KMX61, Accel/Mag |
BlueShadow | 6:7946b5c2376a | 119 | #define COLOR //BH1745 |
BlueShadow | 6:7946b5c2376a | 120 | #define KX022 //KX022, Accel Only |
BlueShadow | 6:7946b5c2376a | 121 | #define Pressure //BM1383 |
BlueShadow | 6:7946b5c2376a | 122 | |
BlueShadow | 6:7946b5c2376a | 123 | |
BlueShadow | 6:7946b5c2376a | 124 | //Define Pins for I2C Interface |
BlueShadow | 6:7946b5c2376a | 125 | I2C i2c(I2C_SDA, I2C_SCL); |
BlueShadow | 6:7946b5c2376a | 126 | bool RepStart = true; |
BlueShadow | 6:7946b5c2376a | 127 | bool NoRepStart = false; |
BlueShadow | 6:7946b5c2376a | 128 | |
BlueShadow | 6:7946b5c2376a | 129 | //Define Sensor Variables |
BlueShadow | 6:7946b5c2376a | 130 | #ifdef AnalogTemp |
BlueShadow | 6:7946b5c2376a | 131 | AnalogIn BDE0600_Temp(PC_4); //Mapped to A2 |
BlueShadow | 6:7946b5c2376a | 132 | uint16_t BDE0600_Temp_value; |
BlueShadow | 6:7946b5c2376a | 133 | float BDE0600_output; |
BlueShadow | 6:7946b5c2376a | 134 | #endif |
BlueShadow | 6:7946b5c2376a | 135 | |
BlueShadow | 6:7946b5c2376a | 136 | #ifdef AnalogUV |
BlueShadow | 6:7946b5c2376a | 137 | AnalogIn ML8511_UV(PC_1); //Mapped to A4 |
BlueShadow | 6:7946b5c2376a | 138 | uint16_t ML8511_UV_value; |
BlueShadow | 6:7946b5c2376a | 139 | float ML8511_output; |
BlueShadow | 6:7946b5c2376a | 140 | #endif |
BlueShadow | 6:7946b5c2376a | 141 | |
BlueShadow | 6:7946b5c2376a | 142 | #ifdef HallSensor |
BlueShadow | 6:7946b5c2376a | 143 | DigitalIn Hall_GPIO0(PC_8); |
BlueShadow | 6:7946b5c2376a | 144 | DigitalIn Hall_GPIO1(PB_5); |
BlueShadow | 6:7946b5c2376a | 145 | int Hall_Return1; |
BlueShadow | 6:7946b5c2376a | 146 | int Hall_Return0; |
BlueShadow | 6:7946b5c2376a | 147 | int32_t Hall_Return[2]; |
BlueShadow | 6:7946b5c2376a | 148 | #endif |
BlueShadow | 6:7946b5c2376a | 149 | |
BlueShadow | 6:7946b5c2376a | 150 | #ifdef RPR0521 |
BlueShadow | 6:7946b5c2376a | 151 | int RPR0521_addr_w = 0x70; //7bit addr = 0x38, with write bit 0 |
BlueShadow | 6:7946b5c2376a | 152 | int RPR0521_addr_r = 0x71; //7bit addr = 0x38, with read bit 1 |
BlueShadow | 6:7946b5c2376a | 153 | char RPR0521_ModeControl[2] = {0x41, 0xE6}; |
BlueShadow | 6:7946b5c2376a | 154 | char RPR0521_ALSPSControl[2] = {0x42, 0x03}; |
BlueShadow | 6:7946b5c2376a | 155 | char RPR0521_Persist[2] = {0x43, 0x20}; |
BlueShadow | 6:7946b5c2376a | 156 | char RPR0521_Addr_ReadData = 0x44; |
BlueShadow | 6:7946b5c2376a | 157 | char RPR0521_Content_ReadData[6]; |
BlueShadow | 6:7946b5c2376a | 158 | int RPR0521_PS_RAWOUT = 0; //this is an output |
BlueShadow | 6:7946b5c2376a | 159 | float RPR0521_PS_OUT = 0; |
BlueShadow | 6:7946b5c2376a | 160 | int RPR0521_ALS_D0_RAWOUT = 0; |
BlueShadow | 6:7946b5c2376a | 161 | int RPR0521_ALS_D1_RAWOUT = 0; |
BlueShadow | 6:7946b5c2376a | 162 | float RPR0521_ALS_DataRatio = 0; |
BlueShadow | 6:7946b5c2376a | 163 | float RPR0521_ALS_OUT = 0; //this is an output |
BlueShadow | 6:7946b5c2376a | 164 | float RPR0521_ALS[2]; // is this ok taking an int to the [0] value and float to [1]??????????? |
BlueShadow | 6:7946b5c2376a | 165 | #endif |
BlueShadow | 6:7946b5c2376a | 166 | |
BlueShadow | 6:7946b5c2376a | 167 | #ifdef KMX62 |
BlueShadow | 6:7946b5c2376a | 168 | int KMX62_addr_w = 0x1C; //7bit addr = 0x38, with write bit 0 |
BlueShadow | 6:7946b5c2376a | 169 | int KMX62_addr_r = 0x1D; //7bit addr = 0x38, with read bit 1 |
BlueShadow | 6:7946b5c2376a | 170 | char KMX62_CNTL2[2] = {0x3A, 0x5F}; |
BlueShadow | 6:7946b5c2376a | 171 | char KMX62_Addr_Accel_ReadData = 0x0A; |
BlueShadow | 6:7946b5c2376a | 172 | char KMX62_Content_Accel_ReadData[6]; |
BlueShadow | 6:7946b5c2376a | 173 | char KMX62_Addr_Mag_ReadData = 0x10; |
BlueShadow | 6:7946b5c2376a | 174 | char KMX62_Content_Mag_ReadData[6]; |
BlueShadow | 6:7946b5c2376a | 175 | short int MEMS_Accel_Xout = 0; |
BlueShadow | 6:7946b5c2376a | 176 | short int MEMS_Accel_Yout = 0; |
BlueShadow | 6:7946b5c2376a | 177 | short int MEMS_Accel_Zout = 0; |
BlueShadow | 6:7946b5c2376a | 178 | double MEMS_Accel_Conv_Xout = 0; |
BlueShadow | 6:7946b5c2376a | 179 | double MEMS_Accel_Conv_Yout = 0; |
BlueShadow | 6:7946b5c2376a | 180 | double MEMS_Accel_Conv_Zout = 0; |
BlueShadow | 6:7946b5c2376a | 181 | |
BlueShadow | 6:7946b5c2376a | 182 | short int MEMS_Mag_Xout = 0; |
BlueShadow | 6:7946b5c2376a | 183 | short int MEMS_Mag_Yout = 0; |
BlueShadow | 6:7946b5c2376a | 184 | short int MEMS_Mag_Zout = 0; |
BlueShadow | 6:7946b5c2376a | 185 | float MEMS_Mag_Conv_Xout = 0; |
BlueShadow | 6:7946b5c2376a | 186 | float MEMS_Mag_Conv_Yout = 0; |
BlueShadow | 6:7946b5c2376a | 187 | float MEMS_Mag_Conv_Zout = 0; |
BlueShadow | 6:7946b5c2376a | 188 | |
BlueShadow | 6:7946b5c2376a | 189 | double MEMS_Accel[3]; |
BlueShadow | 6:7946b5c2376a | 190 | float MEMS_Mag[3]; |
BlueShadow | 6:7946b5c2376a | 191 | #endif |
BlueShadow | 6:7946b5c2376a | 192 | |
BlueShadow | 6:7946b5c2376a | 193 | #ifdef COLOR |
BlueShadow | 6:7946b5c2376a | 194 | int BH1745_addr_w = 0x72; //write |
BlueShadow | 6:7946b5c2376a | 195 | int BH1745_addr_r = 0x73; //read |
BlueShadow | 6:7946b5c2376a | 196 | char BH1745_persistence[2] = {0x61, 0x03}; |
BlueShadow | 6:7946b5c2376a | 197 | char BH1745_mode1[2] = {0x41, 0x00}; |
BlueShadow | 6:7946b5c2376a | 198 | char BH1745_mode2[2] = {0x42, 0x92}; |
BlueShadow | 6:7946b5c2376a | 199 | char BH1745_mode3[2] = {0x43, 0x02}; |
BlueShadow | 6:7946b5c2376a | 200 | char BH1745_Content_ReadData[6]; |
BlueShadow | 6:7946b5c2376a | 201 | char BH1745_Addr_color_ReadData = 0x50; |
BlueShadow | 6:7946b5c2376a | 202 | int BH1745_Red; |
BlueShadow | 6:7946b5c2376a | 203 | int BH1745_Blue; |
BlueShadow | 6:7946b5c2376a | 204 | int BH1745_Green; |
BlueShadow | 6:7946b5c2376a | 205 | int32_t BH1745[3]; //Red, Blue Green matrix |
BlueShadow | 6:7946b5c2376a | 206 | #endif |
BlueShadow | 6:7946b5c2376a | 207 | |
BlueShadow | 6:7946b5c2376a | 208 | #ifdef KX022 |
BlueShadow | 6:7946b5c2376a | 209 | int KX022_addr_w = 0x3C; //write |
BlueShadow | 6:7946b5c2376a | 210 | int KX022_addr_r = 0x3D; //read |
BlueShadow | 6:7946b5c2376a | 211 | char KX022_Accel_CNTL1[2] = {0x18, 0x41}; |
BlueShadow | 6:7946b5c2376a | 212 | char KX022_Accel_ODCNTL[2] = {0x1B, 0x02}; |
BlueShadow | 6:7946b5c2376a | 213 | char KX022_Accel_CNTL3[2] = {0x1A, 0xD8}; |
BlueShadow | 6:7946b5c2376a | 214 | char KX022_Accel_TILT_TIMER[2] = {0x22, 0x01}; |
BlueShadow | 6:7946b5c2376a | 215 | char KX022_Accel_CNTL2[2] = {0x18, 0xC1}; |
BlueShadow | 6:7946b5c2376a | 216 | char KX022_Content_ReadData[6]; |
BlueShadow | 6:7946b5c2376a | 217 | char KX022_Addr_Accel_ReadData = 0x06; |
BlueShadow | 6:7946b5c2376a | 218 | float KX022_Accel_X; |
BlueShadow | 6:7946b5c2376a | 219 | float KX022_Accel_Y; |
BlueShadow | 6:7946b5c2376a | 220 | float KX022_Accel_Z; |
BlueShadow | 6:7946b5c2376a | 221 | short int KX022_Accel_X_RawOUT = 0; |
BlueShadow | 6:7946b5c2376a | 222 | short int KX022_Accel_Y_RawOUT = 0; |
BlueShadow | 6:7946b5c2376a | 223 | short int KX022_Accel_Z_RawOUT = 0; |
BlueShadow | 6:7946b5c2376a | 224 | int KX022_Accel_X_LB = 0; |
BlueShadow | 6:7946b5c2376a | 225 | int KX022_Accel_X_HB = 0; |
BlueShadow | 6:7946b5c2376a | 226 | int KX022_Accel_Y_LB = 0; |
BlueShadow | 6:7946b5c2376a | 227 | int KX022_Accel_Y_HB = 0; |
BlueShadow | 6:7946b5c2376a | 228 | int KX022_Accel_Z_LB = 0; |
BlueShadow | 6:7946b5c2376a | 229 | int KX022_Accel_Z_HB = 0; |
BlueShadow | 6:7946b5c2376a | 230 | float KX022_Accel[3]; |
BlueShadow | 6:7946b5c2376a | 231 | #endif |
BlueShadow | 6:7946b5c2376a | 232 | |
BlueShadow | 6:7946b5c2376a | 233 | #ifdef Pressure |
BlueShadow | 6:7946b5c2376a | 234 | int Press_addr_w = 0xBA; //write |
BlueShadow | 6:7946b5c2376a | 235 | int Press_addr_r = 0xBB; //read |
BlueShadow | 6:7946b5c2376a | 236 | char PWR_DOWN[2] = {0x12, 0x01}; |
BlueShadow | 6:7946b5c2376a | 237 | char SLEEP[2] = {0x13, 0x01}; |
BlueShadow | 6:7946b5c2376a | 238 | char Mode_Control[2] = {0x14, 0xC4}; |
BlueShadow | 6:7946b5c2376a | 239 | char Press_Content_ReadData[6]; |
BlueShadow | 6:7946b5c2376a | 240 | char Press_Addr_ReadData =0x1A; |
BlueShadow | 6:7946b5c2376a | 241 | int BM1383_Temp_highByte; |
BlueShadow | 6:7946b5c2376a | 242 | int BM1383_Temp_lowByte; |
BlueShadow | 6:7946b5c2376a | 243 | int BM1383_Pres_highByte; |
BlueShadow | 6:7946b5c2376a | 244 | int BM1383_Pres_lowByte; |
BlueShadow | 6:7946b5c2376a | 245 | int BM1383_Pres_leastByte; |
BlueShadow | 6:7946b5c2376a | 246 | short int BM1383_Temp_Out; |
BlueShadow | 6:7946b5c2376a | 247 | float BM1383_Temp_Conv_Out; |
BlueShadow | 6:7946b5c2376a | 248 | float BM1383_Pres_Conv_Out; |
BlueShadow | 6:7946b5c2376a | 249 | float_t BM1383[2]; // Temp is 0 and Pressure is 1 |
BlueShadow | 6:7946b5c2376a | 250 | float BM1383_Var; |
BlueShadow | 6:7946b5c2376a | 251 | float BM1383_Deci; |
BlueShadow | 6:7946b5c2376a | 252 | #endif |
BlueShadow | 6:7946b5c2376a | 253 | |
BlueShadow | 6:7946b5c2376a | 254 | /**************************************************************************************************** |
mfiore | 0:a44e71488e1f | 255 | // function prototypes |
BlueShadow | 6:7946b5c2376a | 256 | ****************************************************************************************************/ |
mfiore | 0:a44e71488e1f | 257 | bool init_mtsas(); |
BlueShadow | 6:7946b5c2376a | 258 | void ReadAnalogTemp(); |
BlueShadow | 6:7946b5c2376a | 259 | void ReadAnalogUV (); |
BlueShadow | 6:7946b5c2376a | 260 | void ReadHallSensor (); |
BlueShadow | 6:7946b5c2376a | 261 | void ReadCOLOR (); |
BlueShadow | 6:7946b5c2376a | 262 | void ReadRPR0521_ALS (); |
BlueShadow | 6:7946b5c2376a | 263 | void ReadKMX62_Accel (); |
BlueShadow | 6:7946b5c2376a | 264 | void ReadKMX62_Mag (); |
BlueShadow | 6:7946b5c2376a | 265 | void ReadPressure (); |
BlueShadow | 6:7946b5c2376a | 266 | void ReadKX022(); |
BlueShadow | 8:e78dcfad254b | 267 | char* httpResToStr(HTTPResult res); |
BlueShadow | 8:e78dcfad254b | 268 | |
BlueShadow | 8:e78dcfad254b | 269 | namespace patch |
BlueShadow | 8:e78dcfad254b | 270 | { |
BlueShadow | 9:6475e1b83491 | 271 | template < typename T > std::string to_string( const T& n ) |
BlueShadow | 9:6475e1b83491 | 272 | { |
BlueShadow | 9:6475e1b83491 | 273 | std::ostringstream stm ; |
BlueShadow | 9:6475e1b83491 | 274 | stm << n ; |
BlueShadow | 9:6475e1b83491 | 275 | return stm.str() ; |
BlueShadow | 9:6475e1b83491 | 276 | } |
BlueShadow | 8:e78dcfad254b | 277 | } |
mfiore | 0:a44e71488e1f | 278 | |
BlueShadow | 6:7946b5c2376a | 279 | /**************************************************************************************************** |
mfiore | 0:a44e71488e1f | 280 | // main |
BlueShadow | 6:7946b5c2376a | 281 | ****************************************************************************************************/ |
BlueShadow | 6:7946b5c2376a | 282 | int main() |
BlueShadow | 6:7946b5c2376a | 283 | { |
mfiore | 0:a44e71488e1f | 284 | mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); |
mfiore | 0:a44e71488e1f | 285 | debug.baud(debug_baud); |
BlueShadow | 6:7946b5c2376a | 286 | |
BlueShadow | 6:7946b5c2376a | 287 | // Initialization Radio Section ********************************************************** |
BlueShadow | 8:e78dcfad254b | 288 | logInfo("initializing cellular radio"); |
BlueShadow | 8:e78dcfad254b | 289 | if (!init_mtsas()) { |
BlueShadow | 8:e78dcfad254b | 290 | while (true) { |
BlueShadow | 8:e78dcfad254b | 291 | logError("failed to initialize cellular radio"); |
BlueShadow | 8:e78dcfad254b | 292 | wait(1); |
BlueShadow | 8:e78dcfad254b | 293 | } |
BlueShadow | 8:e78dcfad254b | 294 | } |
BlueShadow | 9:6475e1b83491 | 295 | |
BlueShadow | 8:e78dcfad254b | 296 | logInfo("Configuring http...\r\n"); |
BlueShadow | 8:e78dcfad254b | 297 | HTTPClient http; |
BlueShadow | 8:e78dcfad254b | 298 | HTTPResult result; |
BlueShadow | 8:e78dcfad254b | 299 | http.setHeader(EXOSITE_HEADER); |
BlueShadow | 9:6475e1b83491 | 300 | |
BlueShadow | 8:e78dcfad254b | 301 | char http_rx_buf[1024]; |
BlueShadow | 8:e78dcfad254b | 302 | // IHTTPDataIn object - will contain data received from server. |
BlueShadow | 8:e78dcfad254b | 303 | HTTPText http_rx(http_rx_buf, sizeof(http_rx_buf)); |
BlueShadow | 9:6475e1b83491 | 304 | |
BlueShadow | 8:e78dcfad254b | 305 | // IHTTPDataOut object - contains data to be posted to server. |
BlueShadow | 8:e78dcfad254b | 306 | HTTPMap http_tx; |
BlueShadow | 9:6475e1b83491 | 307 | |
BlueShadow | 9:6475e1b83491 | 308 | |
BlueShadow | 8:e78dcfad254b | 309 | //**************************************************************************************************** |
BlueShadow | 8:e78dcfad254b | 310 | // Initialize I2C Devices ************ |
BlueShadow | 8:e78dcfad254b | 311 | //****************************************************************************************************/ |
BlueShadow | 6:7946b5c2376a | 312 | |
BlueShadow | 9:6475e1b83491 | 313 | #ifdef RPR0521 |
BlueShadow | 9:6475e1b83491 | 314 | i2c.write(RPR0521_addr_w, &RPR0521_ModeControl[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 315 | i2c.write(RPR0521_addr_w, &RPR0521_ALSPSControl[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 316 | i2c.write(RPR0521_addr_w, &RPR0521_Persist[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 317 | #endif |
BlueShadow | 9:6475e1b83491 | 318 | |
BlueShadow | 9:6475e1b83491 | 319 | #ifdef KMX62 |
BlueShadow | 9:6475e1b83491 | 320 | i2c.write(KMX62_addr_w, &KMX62_CNTL2[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 321 | #endif |
BlueShadow | 9:6475e1b83491 | 322 | |
BlueShadow | 9:6475e1b83491 | 323 | #ifdef COLOR |
BlueShadow | 9:6475e1b83491 | 324 | i2c.write(BH1745_addr_w, &BH1745_persistence[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 325 | i2c.write(BH1745_addr_w, &BH1745_mode1[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 326 | i2c.write(BH1745_addr_w, &BH1745_mode2[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 327 | i2c.write(BH1745_addr_w, &BH1745_mode3[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 328 | #endif |
BlueShadow | 9:6475e1b83491 | 329 | |
BlueShadow | 9:6475e1b83491 | 330 | #ifdef KX022 |
BlueShadow | 9:6475e1b83491 | 331 | i2c.write(KX022_addr_w, &KX022_Accel_CNTL1[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 332 | i2c.write(KX022_addr_w, &KX022_Accel_ODCNTL[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 333 | i2c.write(KX022_addr_w, &KX022_Accel_CNTL3[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 334 | i2c.write(KX022_addr_w, &KX022_Accel_TILT_TIMER[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 335 | i2c.write(KX022_addr_w, &KX022_Accel_CNTL2[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 336 | #endif |
BlueShadow | 9:6475e1b83491 | 337 | |
BlueShadow | 9:6475e1b83491 | 338 | #ifdef Pressure |
BlueShadow | 9:6475e1b83491 | 339 | i2c.write(Press_addr_w, &PWR_DOWN[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 340 | i2c.write(Press_addr_w, &SLEEP[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 341 | i2c.write(Press_addr_w, &Mode_Control[0], 2, false); |
BlueShadow | 9:6475e1b83491 | 342 | #endif |
BlueShadow | 9:6475e1b83491 | 343 | |
BlueShadow | 6:7946b5c2376a | 344 | |
BlueShadow | 8:e78dcfad254b | 345 | //****************************************************************************************************/ |
BlueShadow | 8:e78dcfad254b | 346 | //End I2C Initialization Section ********************************************************** |
BlueShadow | 8:e78dcfad254b | 347 | //****************************************************************************************************/ |
BlueShadow | 9:6475e1b83491 | 348 | |
BlueShadow | 8:e78dcfad254b | 349 | Timer post_timer; |
BlueShadow | 9:6475e1b83491 | 350 | post_timer.start(); |
BlueShadow | 8:e78dcfad254b | 351 | logInfo("Setup complete."); |
BlueShadow | 8:e78dcfad254b | 352 | logInfo("Waiting for %d ms to trigger connect...", post_interval_ms); |
BlueShadow | 6:7946b5c2376a | 353 | |
BlueShadow | 9:6475e1b83491 | 354 | //*******************************************************************************************************/ |
BlueShadow | 9:6475e1b83491 | 355 | //Beging loop for Main |
BlueShadow | 9:6475e1b83491 | 356 | //*******************************************************************************************************/ |
BlueShadow | 9:6475e1b83491 | 357 | |
BlueShadow | 8:e78dcfad254b | 358 | while (true) { |
BlueShadow | 8:e78dcfad254b | 359 | if (post_timer.read_ms() > post_interval_ms && do_cloud_post) { |
BlueShadow | 8:e78dcfad254b | 360 | logInfo("bringing up the link"); |
BlueShadow | 9:6475e1b83491 | 361 | |
BlueShadow | 9:6475e1b83491 | 362 | #ifdef AnalogTemp |
BlueShadow | 9:6475e1b83491 | 363 | ReadAnalogTemp (); |
BlueShadow | 9:6475e1b83491 | 364 | #endif |
BlueShadow | 9:6475e1b83491 | 365 | |
BlueShadow | 9:6475e1b83491 | 366 | #ifdef AnalogUV |
BlueShadow | 9:6475e1b83491 | 367 | ReadAnalogUV (); |
BlueShadow | 9:6475e1b83491 | 368 | #endif |
BlueShadow | 9:6475e1b83491 | 369 | |
BlueShadow | 9:6475e1b83491 | 370 | #ifdef HallSensor |
BlueShadow | 9:6475e1b83491 | 371 | ReadHallSensor (); |
BlueShadow | 9:6475e1b83491 | 372 | #endif |
BlueShadow | 9:6475e1b83491 | 373 | |
BlueShadow | 9:6475e1b83491 | 374 | #ifdef COLOR |
BlueShadow | 9:6475e1b83491 | 375 | ReadCOLOR (); |
BlueShadow | 9:6475e1b83491 | 376 | #endif |
BlueShadow | 9:6475e1b83491 | 377 | |
BlueShadow | 9:6475e1b83491 | 378 | #ifdef RPR0521 //als digital |
BlueShadow | 9:6475e1b83491 | 379 | ReadRPR0521_ALS (); |
BlueShadow | 9:6475e1b83491 | 380 | #endif |
BlueShadow | 9:6475e1b83491 | 381 | |
BlueShadow | 9:6475e1b83491 | 382 | #ifdef Pressure |
BlueShadow | 9:6475e1b83491 | 383 | ReadPressure(); |
BlueShadow | 9:6475e1b83491 | 384 | #endif |
BlueShadow | 9:6475e1b83491 | 385 | |
BlueShadow | 9:6475e1b83491 | 386 | #ifdef KMX62 |
BlueShadow | 9:6475e1b83491 | 387 | ReadKMX62_Accel (); |
BlueShadow | 9:6475e1b83491 | 388 | ReadKMX62_Mag (); |
BlueShadow | 9:6475e1b83491 | 389 | #endif |
BlueShadow | 9:6475e1b83491 | 390 | |
BlueShadow | 9:6475e1b83491 | 391 | #ifdef KX022 |
BlueShadow | 9:6475e1b83491 | 392 | ReadKX022 (); |
BlueShadow | 9:6475e1b83491 | 393 | #endif |
BlueShadow | 9:6475e1b83491 | 394 | |
BlueShadow | 9:6475e1b83491 | 395 | logDebug("%s", wall_of_dash); |
BlueShadow | 9:6475e1b83491 | 396 | logDebug("SENSOR DATA"); |
BlueShadow | 9:6475e1b83491 | 397 | logDebug("temperature: %0.2f C", BM1383[0]); |
BlueShadow | 9:6475e1b83491 | 398 | logDebug("analog uv: %.1f mW/cm2", ML8511_output); |
BlueShadow | 9:6475e1b83491 | 399 | logDebug("ambient Light %0.3f", RPR0521_ALS[0]); |
BlueShadow | 9:6475e1b83491 | 400 | logDebug("proximity count %0.3f", RPR0521_ALS[1]); |
BlueShadow | 9:6475e1b83491 | 401 | logDebug("hall effect: South %d\t North %d", Hall_Return[0],Hall_Return[1]); |
BlueShadow | 9:6475e1b83491 | 402 | logDebug("pressure: %0.2f hPa", BM1383[1]); |
BlueShadow | 9:6475e1b83491 | 403 | logDebug("magnetometer:\r\n\tx: %0.3f\ty: %0.3f\tz: %0.3f\tuT", MEMS_Mag[0], MEMS_Mag[1], MEMS_Mag[2]); |
BlueShadow | 9:6475e1b83491 | 404 | logDebug("accelerometer:\r\n\tx: %0.3f\ty: %0.3f\tz: %0.3f\tg", MEMS_Accel[0], MEMS_Accel[1], MEMS_Accel[2]); |
BlueShadow | 9:6475e1b83491 | 405 | logDebug("color:\r\n\tred: %ld\tgrn: %ld\tblu: %ld\t", BH1745[0], BH1745[1], BH1745[2]); |
BlueShadow | 9:6475e1b83491 | 406 | logDebug("%s", wall_of_dash); |
BlueShadow | 9:6475e1b83491 | 407 | |
BlueShadow | 9:6475e1b83491 | 408 | |
BlueShadow | 9:6475e1b83491 | 409 | //*******************************************************************************************************/ |
BlueShadow | 9:6475e1b83491 | 410 | //Connect to the radio to send data |
BlueShadow | 9:6475e1b83491 | 411 | //*******************************************************************************************************/ |
BlueShadow | 9:6475e1b83491 | 412 | |
BlueShadow | 8:e78dcfad254b | 413 | if (radio->connect()) { |
brianhuey | 12:9942995476ef | 414 | int sensor_data_light = RPR0521_ALS[0]; |
brianhuey | 12:9942995476ef | 415 | int sensor_data_temp = BM1383[0] ; |
brianhuey | 12:9942995476ef | 416 | int sensor_data_analoguv = ML8511_output; |
brianhuey | 12:9942995476ef | 417 | int sensor_data_pressure = BM1383[1]; |
brianhuey | 12:9942995476ef | 418 | |
BlueShadow | 8:e78dcfad254b | 419 | logDebug("posting sensor data"); |
brianhuey | 12:9942995476ef | 420 | logDebug("%d",sensor_data_light); |
brianhuey | 12:9942995476ef | 421 | logDebug("%d",sensor_data_temp); |
brianhuey | 12:9942995476ef | 422 | logDebug("%d",sensor_data_analoguv); |
brianhuey | 12:9942995476ef | 423 | logDebug("%d",sensor_data_pressure); |
brianhuey | 12:9942995476ef | 424 | |
brianhuey | 12:9942995476ef | 425 | std::string sensor_data_light_str = patch::to_string(sensor_data_light); |
brianhuey | 12:9942995476ef | 426 | logDebug("Sensor data string: %s",sensor_data_light_str.c_str()); |
brianhuey | 12:9942995476ef | 427 | std::string sensor_data_temp_str = patch::to_string(sensor_data_temp); |
brianhuey | 12:9942995476ef | 428 | logDebug("Sensor temp data string: %s",sensor_data_temp_str.c_str()); |
brianhuey | 12:9942995476ef | 429 | std::string sensor_data_analoguv_str = patch::to_string(sensor_data_analoguv); |
brianhuey | 12:9942995476ef | 430 | logDebug("Sensor analoguv data string: %s",sensor_data_analoguv_str.c_str()); |
brianhuey | 12:9942995476ef | 431 | std::string sensor_data_pressure_str = patch::to_string(sensor_data_pressure); |
brianhuey | 12:9942995476ef | 432 | logDebug("Sensor pressure data string: %s",sensor_data_pressure_str.c_str()); |
BlueShadow | 9:6475e1b83491 | 433 | |
BlueShadow | 8:e78dcfad254b | 434 | // Make HTTP POST request |
brianhuey | 12:9942995476ef | 435 | http_tx.clear(); |
brianhuey | 12:9942995476ef | 436 | http_tx.put("ALS", sensor_data_light_str.c_str()); |
brianhuey | 12:9942995476ef | 437 | http_tx.put("TEMP", sensor_data_temp_str.c_str()); |
brianhuey | 12:9942995476ef | 438 | http_tx.put("ANALOG-UV", sensor_data_analoguv_str.c_str()); |
brianhuey | 12:9942995476ef | 439 | http_tx.put("PRESSURE", sensor_data_pressure_str.c_str()); |
brianhuey | 12:9942995476ef | 440 | |
brianhuey | 12:9942995476ef | 441 | // Check HTTP Post Result |
BlueShadow | 8:e78dcfad254b | 442 | result = http.post(EXOSITE_URL, http_tx, &http_rx); |
BlueShadow | 8:e78dcfad254b | 443 | if (result != HTTP_OK) { |
BlueShadow | 8:e78dcfad254b | 444 | logError("HTTP POST failed [%d][%s]", result, httpResToStr(result)); |
BlueShadow | 8:e78dcfad254b | 445 | } else { |
BlueShadow | 8:e78dcfad254b | 446 | logInfo("HTTP POST succeeded [%d]\r\n%s", http.getHTTPResponseCode(), http_rx_buf); |
BlueShadow | 8:e78dcfad254b | 447 | } |
brianhuey | 12:9942995476ef | 448 | |
brianhuey | 12:9942995476ef | 449 | |
BlueShadow | 6:7946b5c2376a | 450 | |
mfiore | 4:730b61258422 | 451 | radio->disconnect(); |
mfiore | 4:730b61258422 | 452 | } else { |
mfiore | 4:730b61258422 | 453 | logError("establishing PPP link failed"); |
mfiore | 4:730b61258422 | 454 | } |
BlueShadow | 6:7946b5c2376a | 455 | |
mfiore | 4:730b61258422 | 456 | post_timer.reset(); |
BlueShadow | 9:6475e1b83491 | 457 | |
BlueShadow | 8:e78dcfad254b | 458 | logInfo("Waiting for %d ms to trigger connect...", post_interval_ms); |
mfiore | 4:730b61258422 | 459 | } |
mfiore | 0:a44e71488e1f | 460 | } |
mfiore | 0:a44e71488e1f | 461 | } |
mfiore | 0:a44e71488e1f | 462 | |
BlueShadow | 8:e78dcfad254b | 463 | |
mfiore | 1:a049d113e250 | 464 | // init functions |
BlueShadow | 6:7946b5c2376a | 465 | bool init_mtsas() |
BlueShadow | 6:7946b5c2376a | 466 | { |
mfiore | 1:a049d113e250 | 467 | io = new MTSSerialFlowControl(RADIO_TX, RADIO_RX, RADIO_RTS, RADIO_CTS); |
mfiore | 1:a049d113e250 | 468 | if (! io) |
mfiore | 1:a049d113e250 | 469 | return false; |
BlueShadow | 6:7946b5c2376a | 470 | |
mfiore | 1:a049d113e250 | 471 | io->baud(115200); |
mfiore | 1:a049d113e250 | 472 | radio = CellularFactory::create(io); |
mfiore | 1:a049d113e250 | 473 | if (! radio) |
mfiore | 1:a049d113e250 | 474 | return false; |
BlueShadow | 6:7946b5c2376a | 475 | |
mfiore | 1:a049d113e250 | 476 | Code ret = radio->setApn(apn); |
mfiore | 1:a049d113e250 | 477 | if (ret != MTS_SUCCESS) |
mfiore | 1:a049d113e250 | 478 | return false; |
BlueShadow | 6:7946b5c2376a | 479 | |
mfiore | 5:a946ef74a8c4 | 480 | Transport::setTransport(radio); |
BlueShadow | 6:7946b5c2376a | 481 | |
mfiore | 1:a049d113e250 | 482 | return true; |
mfiore | 1:a049d113e250 | 483 | } |
mfiore | 1:a049d113e250 | 484 | |
BlueShadow | 9:6475e1b83491 | 485 | char* httpResToStr(HTTPResult result) |
BlueShadow | 9:6475e1b83491 | 486 | { |
BlueShadow | 8:e78dcfad254b | 487 | switch(result) { |
BlueShadow | 8:e78dcfad254b | 488 | case HTTP_PROCESSING: |
BlueShadow | 8:e78dcfad254b | 489 | return "HTTP_PROCESSING"; |
BlueShadow | 8:e78dcfad254b | 490 | case HTTP_PARSE: |
BlueShadow | 8:e78dcfad254b | 491 | return "HTTP_PARSE"; |
BlueShadow | 8:e78dcfad254b | 492 | case HTTP_DNS: |
BlueShadow | 8:e78dcfad254b | 493 | return "HTTP_DNS"; |
BlueShadow | 8:e78dcfad254b | 494 | case HTTP_PRTCL: |
BlueShadow | 8:e78dcfad254b | 495 | return "HTTP_PRTCL"; |
BlueShadow | 8:e78dcfad254b | 496 | case HTTP_NOTFOUND: |
BlueShadow | 8:e78dcfad254b | 497 | return "HTTP_NOTFOUND"; |
BlueShadow | 8:e78dcfad254b | 498 | case HTTP_REFUSED: |
BlueShadow | 8:e78dcfad254b | 499 | return "HTTP_REFUSED"; |
BlueShadow | 8:e78dcfad254b | 500 | case HTTP_ERROR: |
BlueShadow | 8:e78dcfad254b | 501 | return "HTTP_ERROR"; |
BlueShadow | 8:e78dcfad254b | 502 | case HTTP_TIMEOUT: |
BlueShadow | 8:e78dcfad254b | 503 | return "HTTP_TIMEOUT"; |
BlueShadow | 8:e78dcfad254b | 504 | case HTTP_CONN: |
BlueShadow | 8:e78dcfad254b | 505 | return "HTTP_CONN"; |
BlueShadow | 8:e78dcfad254b | 506 | case HTTP_CLOSED: |
BlueShadow | 8:e78dcfad254b | 507 | return "HTTP_CLOSED"; |
BlueShadow | 8:e78dcfad254b | 508 | case HTTP_REDIRECT: |
BlueShadow | 8:e78dcfad254b | 509 | return "HTTP_REDIRECT"; |
BlueShadow | 8:e78dcfad254b | 510 | case HTTP_OK: |
BlueShadow | 8:e78dcfad254b | 511 | return "HTTP_OK"; |
BlueShadow | 8:e78dcfad254b | 512 | default: |
BlueShadow | 8:e78dcfad254b | 513 | return "HTTP Result unknown"; |
BlueShadow | 6:7946b5c2376a | 514 | } |
mfiore | 0:a44e71488e1f | 515 | } |
mfiore | 0:a44e71488e1f | 516 | |
BlueShadow | 9:6475e1b83491 | 517 | |
BlueShadow | 9:6475e1b83491 | 518 | //************************************************************************************************/ |
BlueShadow | 9:6475e1b83491 | 519 | // Sensor data acquisition functions |
BlueShadow | 9:6475e1b83491 | 520 | //************************************************************************************************/ |
BlueShadow | 9:6475e1b83491 | 521 | #ifdef AnalogTemp |
BlueShadow | 9:6475e1b83491 | 522 | void ReadAnalogTemp () |
BlueShadow | 9:6475e1b83491 | 523 | { |
BlueShadow | 9:6475e1b83491 | 524 | BDE0600_Temp_value = BDE0600_Temp.read_u16(); |
BlueShadow | 9:6475e1b83491 | 525 | |
BlueShadow | 9:6475e1b83491 | 526 | BDE0600_output = (float)BDE0600_Temp_value * (float)0.000050354; //(value * (3.3V/65535)) |
BlueShadow | 9:6475e1b83491 | 527 | BDE0600_output = (BDE0600_output-(float)1.753)/((float)-0.01068) + (float)30; |
BlueShadow | 9:6475e1b83491 | 528 | |
BlueShadow | 9:6475e1b83491 | 529 | // printf("BDE0600 Analog Temp Sensor Data:\r\n"); |
BlueShadow | 9:6475e1b83491 | 530 | // printf(" Temp = %.2f C\r\n", BDE0600_output); |
BlueShadow | 9:6475e1b83491 | 531 | } |
BlueShadow | 9:6475e1b83491 | 532 | #endif |
BlueShadow | 9:6475e1b83491 | 533 | |
BlueShadow | 9:6475e1b83491 | 534 | #ifdef AnalogUV |
BlueShadow | 9:6475e1b83491 | 535 | void ReadAnalogUV () |
BlueShadow | 9:6475e1b83491 | 536 | { |
BlueShadow | 9:6475e1b83491 | 537 | ML8511_UV_value = ML8511_UV.read_u16(); |
BlueShadow | 9:6475e1b83491 | 538 | ML8511_output = (float)ML8511_UV_value * (float)0.000050354; //(value * (3.3V/65535)) //Note to self: when playing with this, a negative value is seen... Honestly, I think this has to do with my ADC converstion... |
BlueShadow | 9:6475e1b83491 | 539 | ML8511_output = (ML8511_output-(float)2.2)/((float)0.129) + 10; // Added +5 to the offset so when inside (aka, no UV, readings show 0)... this is the wrong approach... and the readings don't make sense... Fix this. |
BlueShadow | 9:6475e1b83491 | 540 | |
BlueShadow | 9:6475e1b83491 | 541 | // printf("ML8511 Analog UV Sensor Data:\r\n"); |
BlueShadow | 9:6475e1b83491 | 542 | // printf(" UV = %.1f mW/cm2\r\n", ML8511_output); |
BlueShadow | 9:6475e1b83491 | 543 | |
BlueShadow | 9:6475e1b83491 | 544 | } |
BlueShadow | 9:6475e1b83491 | 545 | #endif |
BlueShadow | 9:6475e1b83491 | 546 | |
BlueShadow | 9:6475e1b83491 | 547 | |
BlueShadow | 9:6475e1b83491 | 548 | #ifdef HallSensor |
BlueShadow | 9:6475e1b83491 | 549 | void ReadHallSensor () |
BlueShadow | 9:6475e1b83491 | 550 | { |
BlueShadow | 9:6475e1b83491 | 551 | |
BlueShadow | 9:6475e1b83491 | 552 | Hall_Return[0] = Hall_GPIO0; |
BlueShadow | 9:6475e1b83491 | 553 | Hall_Return[1] = Hall_GPIO1; |
BlueShadow | 9:6475e1b83491 | 554 | |
BlueShadow | 9:6475e1b83491 | 555 | // printf("BU52011 Hall Switch Sensor Data:\r\n"); |
BlueShadow | 9:6475e1b83491 | 556 | // printf(" South Detect = %d\r\n", Hall_Return[0]); |
BlueShadow | 9:6475e1b83491 | 557 | // printf(" North Detect = %d\r\n", Hall_Return[1]); |
BlueShadow | 9:6475e1b83491 | 558 | |
BlueShadow | 9:6475e1b83491 | 559 | |
BlueShadow | 9:6475e1b83491 | 560 | } |
BlueShadow | 9:6475e1b83491 | 561 | #endif |
BlueShadow | 9:6475e1b83491 | 562 | |
BlueShadow | 9:6475e1b83491 | 563 | #ifdef COLOR |
BlueShadow | 9:6475e1b83491 | 564 | void ReadCOLOR () |
BlueShadow | 9:6475e1b83491 | 565 | { |
BlueShadow | 9:6475e1b83491 | 566 | |
BlueShadow | 9:6475e1b83491 | 567 | //Read color data from the IC |
BlueShadow | 9:6475e1b83491 | 568 | i2c.write(BH1745_addr_w, &BH1745_Addr_color_ReadData, 1, RepStart); |
BlueShadow | 9:6475e1b83491 | 569 | i2c.read(BH1745_addr_r, &BH1745_Content_ReadData[0], 6, NoRepStart); |
BlueShadow | 9:6475e1b83491 | 570 | |
BlueShadow | 9:6475e1b83491 | 571 | //separate all data read into colors |
BlueShadow | 9:6475e1b83491 | 572 | BH1745[0] = (BH1745_Content_ReadData[1]<<8) | (BH1745_Content_ReadData[0]); |
BlueShadow | 9:6475e1b83491 | 573 | BH1745[1] = (BH1745_Content_ReadData[3]<<8) | (BH1745_Content_ReadData[2]); |
BlueShadow | 9:6475e1b83491 | 574 | BH1745[2] = (BH1745_Content_ReadData[5]<<8) | (BH1745_Content_ReadData[4]); |
BlueShadow | 9:6475e1b83491 | 575 | |
BlueShadow | 9:6475e1b83491 | 576 | //Output Data into UART |
BlueShadow | 9:6475e1b83491 | 577 | // printf("BH1745 COLOR Sensor Data:\r\n"); |
BlueShadow | 9:6475e1b83491 | 578 | // printf(" Red = %d ADC Counts\r\n",BH1745[0]); |
BlueShadow | 9:6475e1b83491 | 579 | // printf(" Green = %d ADC Counts\r\n",BH1745[1]); |
BlueShadow | 9:6475e1b83491 | 580 | // printf(" Blue = %d ADC Counts\r\n",BH1745[2]); |
BlueShadow | 9:6475e1b83491 | 581 | |
BlueShadow | 9:6475e1b83491 | 582 | } |
BlueShadow | 9:6475e1b83491 | 583 | #endif |
BlueShadow | 9:6475e1b83491 | 584 | |
BlueShadow | 9:6475e1b83491 | 585 | #ifdef RPR0521 //als digital |
BlueShadow | 9:6475e1b83491 | 586 | void ReadRPR0521_ALS () |
BlueShadow | 9:6475e1b83491 | 587 | { |
BlueShadow | 9:6475e1b83491 | 588 | i2c.write(RPR0521_addr_w, &RPR0521_Addr_ReadData, 1, RepStart); |
BlueShadow | 9:6475e1b83491 | 589 | i2c.read(RPR0521_addr_r, &RPR0521_Content_ReadData[0], 6, NoRepStart); |
BlueShadow | 9:6475e1b83491 | 590 | |
BlueShadow | 9:6475e1b83491 | 591 | RPR0521_ALS[1] = (RPR0521_Content_ReadData[1]<<8) | (RPR0521_Content_ReadData[0]); |
BlueShadow | 9:6475e1b83491 | 592 | RPR0521_ALS_D0_RAWOUT = (RPR0521_Content_ReadData[3]<<8) | (RPR0521_Content_ReadData[2]); |
BlueShadow | 9:6475e1b83491 | 593 | RPR0521_ALS_D1_RAWOUT = (RPR0521_Content_ReadData[5]<<8) | (RPR0521_Content_ReadData[4]); |
BlueShadow | 9:6475e1b83491 | 594 | RPR0521_ALS_DataRatio = (float)RPR0521_ALS_D1_RAWOUT / (float)RPR0521_ALS_D0_RAWOUT; |
BlueShadow | 9:6475e1b83491 | 595 | |
BlueShadow | 9:6475e1b83491 | 596 | if(RPR0521_ALS_DataRatio < (float)0.595) { |
BlueShadow | 9:6475e1b83491 | 597 | RPR0521_ALS[0] = ((float)1.682*(float)RPR0521_ALS_D0_RAWOUT - (float)1.877*(float)RPR0521_ALS_D1_RAWOUT); |
BlueShadow | 9:6475e1b83491 | 598 | } else if(RPR0521_ALS_DataRatio < (float)1.015) { |
BlueShadow | 9:6475e1b83491 | 599 | RPR0521_ALS[0] = ((float)0.644*(float)RPR0521_ALS_D0_RAWOUT - (float)0.132*(float)RPR0521_ALS_D1_RAWOUT); |
BlueShadow | 9:6475e1b83491 | 600 | } else if(RPR0521_ALS_DataRatio < (float)1.352) { |
BlueShadow | 9:6475e1b83491 | 601 | RPR0521_ALS[0] = ((float)0.756*(float)RPR0521_ALS_D0_RAWOUT - (float)0.243*(float)RPR0521_ALS_D1_RAWOUT); |
BlueShadow | 9:6475e1b83491 | 602 | } else if(RPR0521_ALS_DataRatio < (float)3.053) { |
BlueShadow | 9:6475e1b83491 | 603 | RPR0521_ALS[0] = ((float)0.766*(float)RPR0521_ALS_D0_RAWOUT - (float)0.25*(float)RPR0521_ALS_D1_RAWOUT); |
BlueShadow | 9:6475e1b83491 | 604 | } else { |
BlueShadow | 9:6475e1b83491 | 605 | RPR0521_ALS[0] = 0; |
BlueShadow | 9:6475e1b83491 | 606 | } |
BlueShadow | 9:6475e1b83491 | 607 | // printf("RPR-0521 ALS/PROX Sensor Data:\r\n"); |
BlueShadow | 9:6475e1b83491 | 608 | // printf(" ALS = %0.2f lx\r\n", RPR0521_ALS[0]); |
BlueShadow | 9:6475e1b83491 | 609 | // printf(" PROX= %0.2f ADC Counts\r\n", RPR0521_ALS[1]); //defined as a float but is an unsigned. |
BlueShadow | 9:6475e1b83491 | 610 | |
BlueShadow | 9:6475e1b83491 | 611 | } |
BlueShadow | 9:6475e1b83491 | 612 | #endif |
BlueShadow | 9:6475e1b83491 | 613 | |
BlueShadow | 9:6475e1b83491 | 614 | #ifdef KMX62 |
BlueShadow | 9:6475e1b83491 | 615 | void ReadKMX62_Accel () |
BlueShadow | 9:6475e1b83491 | 616 | { |
BlueShadow | 9:6475e1b83491 | 617 | //Read Accel Portion from the IC |
BlueShadow | 9:6475e1b83491 | 618 | i2c.write(KMX62_addr_w, &KMX62_Addr_Accel_ReadData, 1, RepStart); |
BlueShadow | 9:6475e1b83491 | 619 | i2c.read(KMX62_addr_r, &KMX62_Content_Accel_ReadData[0], 6, NoRepStart); |
BlueShadow | 9:6475e1b83491 | 620 | |
BlueShadow | 9:6475e1b83491 | 621 | //Note: The highbyte and low byte return a 14bit value, dropping the two LSB in the Low byte. |
BlueShadow | 9:6475e1b83491 | 622 | // However, because we need the signed value, we will adjust the value when converting to "g" |
BlueShadow | 9:6475e1b83491 | 623 | MEMS_Accel_Xout = (KMX62_Content_Accel_ReadData[1]<<8) | (KMX62_Content_Accel_ReadData[0]); |
BlueShadow | 9:6475e1b83491 | 624 | MEMS_Accel_Yout = (KMX62_Content_Accel_ReadData[3]<<8) | (KMX62_Content_Accel_ReadData[2]); |
BlueShadow | 9:6475e1b83491 | 625 | MEMS_Accel_Zout = (KMX62_Content_Accel_ReadData[5]<<8) | (KMX62_Content_Accel_ReadData[4]); |
BlueShadow | 9:6475e1b83491 | 626 | |
BlueShadow | 9:6475e1b83491 | 627 | //Note: Conversion to G is as follows: |
BlueShadow | 9:6475e1b83491 | 628 | // Axis_ValueInG = MEMS_Accel_axis / 1024 |
BlueShadow | 9:6475e1b83491 | 629 | // However, since we did not remove the LSB previously, we need to divide by 4 again |
BlueShadow | 9:6475e1b83491 | 630 | // Thus, we will divide the output by 4096 (1024*4) to convert and cancel out the LSB |
BlueShadow | 9:6475e1b83491 | 631 | MEMS_Accel[0] = ((float)MEMS_Accel_Xout/4096/2); |
BlueShadow | 9:6475e1b83491 | 632 | MEMS_Accel[1] = ((float)MEMS_Accel_Yout/4096/2); |
BlueShadow | 9:6475e1b83491 | 633 | MEMS_Accel[2] = ((float)MEMS_Accel_Zout/4096/2); |
BlueShadow | 9:6475e1b83491 | 634 | |
BlueShadow | 9:6475e1b83491 | 635 | // Return Data to UART |
BlueShadow | 9:6475e1b83491 | 636 | // printf("KMX62 Accel+Mag Sensor Data:\r\n"); |
BlueShadow | 9:6475e1b83491 | 637 | // printf(" AccX= %0.2f g\r\n", MEMS_Accel[0]); |
BlueShadow | 9:6475e1b83491 | 638 | // printf(" AccY= %0.2f g\r\n", MEMS_Accel[1]); |
BlueShadow | 9:6475e1b83491 | 639 | // printf(" AccZ= %0.2f g\r\n", MEMS_Accel[2]); |
BlueShadow | 9:6475e1b83491 | 640 | |
BlueShadow | 9:6475e1b83491 | 641 | } |
BlueShadow | 9:6475e1b83491 | 642 | |
BlueShadow | 9:6475e1b83491 | 643 | void ReadKMX62_Mag () |
BlueShadow | 9:6475e1b83491 | 644 | { |
BlueShadow | 9:6475e1b83491 | 645 | |
BlueShadow | 9:6475e1b83491 | 646 | //Read Mag portion from the IC |
BlueShadow | 9:6475e1b83491 | 647 | i2c.write(KMX62_addr_w, &KMX62_Addr_Mag_ReadData, 1, RepStart); |
BlueShadow | 9:6475e1b83491 | 648 | i2c.read(KMX62_addr_r, &KMX62_Content_Mag_ReadData[0], 6, NoRepStart); |
BlueShadow | 9:6475e1b83491 | 649 | |
BlueShadow | 9:6475e1b83491 | 650 | //Note: The highbyte and low byte return a 14bit value, dropping the two LSB in the Low byte. |
BlueShadow | 9:6475e1b83491 | 651 | // However, because we need the signed value, we will adjust the value when converting to "g" |
BlueShadow | 9:6475e1b83491 | 652 | MEMS_Mag_Xout = (KMX62_Content_Mag_ReadData[1]<<8) | (KMX62_Content_Mag_ReadData[0]); |
BlueShadow | 9:6475e1b83491 | 653 | MEMS_Mag_Yout = (KMX62_Content_Mag_ReadData[3]<<8) | (KMX62_Content_Mag_ReadData[2]); |
BlueShadow | 9:6475e1b83491 | 654 | MEMS_Mag_Zout = (KMX62_Content_Mag_ReadData[5]<<8) | (KMX62_Content_Mag_ReadData[4]); |
BlueShadow | 9:6475e1b83491 | 655 | |
BlueShadow | 9:6475e1b83491 | 656 | //Note: Conversion to G is as follows: |
BlueShadow | 9:6475e1b83491 | 657 | // Axis_ValueInG = MEMS_Accel_axis / 1024 |
BlueShadow | 9:6475e1b83491 | 658 | // However, since we did not remove the LSB previously, we need to divide by 4 again |
BlueShadow | 9:6475e1b83491 | 659 | // Thus, we will divide the output by 4095 (1024*4) to convert and cancel out the LSB |
BlueShadow | 9:6475e1b83491 | 660 | MEMS_Mag[0] = (float)MEMS_Mag_Xout/4096*(float)0.146; |
BlueShadow | 9:6475e1b83491 | 661 | MEMS_Mag[1] = (float)MEMS_Mag_Yout/4096*(float)0.146; |
BlueShadow | 9:6475e1b83491 | 662 | MEMS_Mag[2] = (float)MEMS_Mag_Zout/4096*(float)0.146; |
BlueShadow | 9:6475e1b83491 | 663 | |
BlueShadow | 9:6475e1b83491 | 664 | // Return Data to UART |
BlueShadow | 9:6475e1b83491 | 665 | // printf(" MagX= %0.2f uT\r\n", MEMS_Mag[0]); |
BlueShadow | 9:6475e1b83491 | 666 | // printf(" MagY= %0.2f uT\r\n", MEMS_Mag[1]); |
BlueShadow | 9:6475e1b83491 | 667 | // printf(" MagZ= %0.2f uT\r\n", MEMS_Mag[2]); |
BlueShadow | 9:6475e1b83491 | 668 | |
BlueShadow | 9:6475e1b83491 | 669 | } |
BlueShadow | 9:6475e1b83491 | 670 | #endif |
BlueShadow | 9:6475e1b83491 | 671 | |
BlueShadow | 9:6475e1b83491 | 672 | #ifdef KX022 |
BlueShadow | 9:6475e1b83491 | 673 | void ReadKX022 () |
BlueShadow | 9:6475e1b83491 | 674 | { |
BlueShadow | 9:6475e1b83491 | 675 | |
BlueShadow | 9:6475e1b83491 | 676 | //Read KX022 Portion from the IC |
BlueShadow | 9:6475e1b83491 | 677 | i2c.write(KX022_addr_w, &KX022_Addr_Accel_ReadData, 1, RepStart); |
BlueShadow | 9:6475e1b83491 | 678 | i2c.read(KX022_addr_r, &KX022_Content_ReadData[0], 6, NoRepStart); |
BlueShadow | 9:6475e1b83491 | 679 | |
BlueShadow | 9:6475e1b83491 | 680 | //Format Data |
BlueShadow | 9:6475e1b83491 | 681 | KX022_Accel_X_RawOUT = (KX022_Content_ReadData[1]<<8) | (KX022_Content_ReadData[0]); |
BlueShadow | 9:6475e1b83491 | 682 | KX022_Accel_Y_RawOUT = (KX022_Content_ReadData[3]<<8) | (KX022_Content_ReadData[2]); |
BlueShadow | 9:6475e1b83491 | 683 | KX022_Accel_Z_RawOUT = (KX022_Content_ReadData[5]<<8) | (KX022_Content_ReadData[4]); |
BlueShadow | 9:6475e1b83491 | 684 | |
BlueShadow | 9:6475e1b83491 | 685 | //Scale Data |
BlueShadow | 9:6475e1b83491 | 686 | KX022_Accel[0] = (float)KX022_Accel_X_RawOUT / 16384; |
BlueShadow | 9:6475e1b83491 | 687 | KX022_Accel[1] = (float)KX022_Accel_Y_RawOUT / 16384; |
BlueShadow | 9:6475e1b83491 | 688 | KX022_Accel[2] = (float)KX022_Accel_Z_RawOUT / 16384; |
BlueShadow | 9:6475e1b83491 | 689 | |
BlueShadow | 9:6475e1b83491 | 690 | //Return Data through UART |
BlueShadow | 9:6475e1b83491 | 691 | // printf("KX022 Accelerometer Sensor Data: \r\n"); |
BlueShadow | 9:6475e1b83491 | 692 | // printf(" AccX= %0.2f g\r\n", KX022_Accel[0]); |
BlueShadow | 9:6475e1b83491 | 693 | // printf(" AccY= %0.2f g\r\n", KX022_Accel[1]); |
BlueShadow | 9:6475e1b83491 | 694 | // printf(" AccZ= %0.2f g\r\n", KX022_Accel[2]); |
BlueShadow | 9:6475e1b83491 | 695 | |
BlueShadow | 9:6475e1b83491 | 696 | } |
BlueShadow | 9:6475e1b83491 | 697 | #endif |
BlueShadow | 9:6475e1b83491 | 698 | |
BlueShadow | 9:6475e1b83491 | 699 | |
BlueShadow | 9:6475e1b83491 | 700 | #ifdef Pressure |
BlueShadow | 9:6475e1b83491 | 701 | void ReadPressure () |
BlueShadow | 9:6475e1b83491 | 702 | { |
BlueShadow | 9:6475e1b83491 | 703 | |
BlueShadow | 9:6475e1b83491 | 704 | i2c.write(Press_addr_w, &Press_Addr_ReadData, 1, RepStart); |
BlueShadow | 9:6475e1b83491 | 705 | i2c.read(Press_addr_r, &Press_Content_ReadData[0], 6, NoRepStart); |
BlueShadow | 9:6475e1b83491 | 706 | |
BlueShadow | 9:6475e1b83491 | 707 | BM1383_Temp_Out = (Press_Content_ReadData[0]<<8) | (Press_Content_ReadData[1]); |
BlueShadow | 9:6475e1b83491 | 708 | BM1383[0] = (float)BM1383_Temp_Out/32; |
BlueShadow | 9:6475e1b83491 | 709 | |
BlueShadow | 9:6475e1b83491 | 710 | BM1383_Var = (Press_Content_ReadData[2]<<3) | (Press_Content_ReadData[3] >> 5); |
BlueShadow | 9:6475e1b83491 | 711 | BM1383_Deci = ((Press_Content_ReadData[3] & 0x1f) << 6 | ((Press_Content_ReadData[4] >> 2))); |
BlueShadow | 9:6475e1b83491 | 712 | BM1383_Deci = (float)BM1383_Deci* (float)0.00048828125; //0.00048828125 = 2^-11 |
BlueShadow | 9:6475e1b83491 | 713 | BM1383[1] = (BM1383_Var + BM1383_Deci); //question pending here... |
BlueShadow | 9:6475e1b83491 | 714 | |
BlueShadow | 9:6475e1b83491 | 715 | // printf("BM1383 Pressure Sensor Data:\r\n"); |
BlueShadow | 9:6475e1b83491 | 716 | // printf(" Temperature= %0.2f C\r\n", BM1383[0]); |
BlueShadow | 9:6475e1b83491 | 717 | // printf(" Pressure = %0.2f hPa\r\n", BM1383[1]); |
BlueShadow | 9:6475e1b83491 | 718 | |
BlueShadow | 9:6475e1b83491 | 719 | } |
BlueShadow | 9:6475e1b83491 | 720 | #endif |