![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Dragonfly Class in Dallas 12/11/2015. Rohm Sensor board AT&T SIM
Dependencies: MbedJSONValue mbed mtsas FXAS21002 FXOS8700
Fork of VVV_MultiTech_Dragonfly_ATT_Dallas by
main.cpp@9:3dcbe04adfd0, 2016-08-23 (annotated)
- Committer:
- BlueShadow
- Date:
- Tue Aug 23 08:08:39 2016 +0000
- Revision:
- 9:3dcbe04adfd0
- Parent:
- 8:a09dd040bb4b
MultiTech Dragonfly sending SMS sensor data from Freescale (NXP) MEMs board to cell phone
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 0:a44e71488e1f | 1 | /************************************************************************* |
BlueShadow | 8:a09dd040bb4b | 2 | * Dragonfly Example program of SMS on Freescale sensor board |
BlueShadow | 8:a09dd040bb4b | 3 | */ |
BlueShadow | 6:7946b5c2376a | 4 | |
mfiore | 0:a44e71488e1f | 5 | #include "mbed.h" |
mfiore | 0:a44e71488e1f | 6 | #include "mtsas.h" |
mfiore | 0:a44e71488e1f | 7 | #include "MbedJSONValue.h" |
mfiore | 5:a946ef74a8c4 | 8 | #include "HTTPJson.h" |
mfiore | 0:a44e71488e1f | 9 | #include <string> |
BlueShadow | 8:a09dd040bb4b | 10 | #include "FXAS21002.h" |
BlueShadow | 8:a09dd040bb4b | 11 | #include "FXOS8700.h" |
mfiore | 0:a44e71488e1f | 12 | |
mfiore | 0:a44e71488e1f | 13 | // Debug serial port |
mfiore | 0:a44e71488e1f | 14 | static Serial debug(USBTX, USBRX); |
mfiore | 0:a44e71488e1f | 15 | |
mfiore | 0:a44e71488e1f | 16 | // MTSSerialFlowControl - serial link between processor and radio |
mfiore | 1:a049d113e250 | 17 | static MTSSerialFlowControl* io; |
mfiore | 0:a44e71488e1f | 18 | |
mfiore | 0:a44e71488e1f | 19 | // Cellular - radio object for cellular operations (SMS, TCP, etc) |
mfiore | 0:a44e71488e1f | 20 | Cellular* radio; |
mfiore | 0:a44e71488e1f | 21 | |
mfiore | 0:a44e71488e1f | 22 | // APN associated with SIM card |
mfiore | 4:730b61258422 | 23 | // this APN should work for the AT&T SIM that came with your Dragonfly |
BlueShadow | 9:3dcbe04adfd0 | 24 | static const std::string apn = ""; |
mfiore | 0:a44e71488e1f | 25 | |
mfiore | 0:a44e71488e1f | 26 | // Phone number to send SMS messages to |
mfiore | 5:a946ef74a8c4 | 27 | // just change the x digits - the 1 needs to stay! |
BlueShadow | 9:3dcbe04adfd0 | 28 | static const std::string phone_number = " NEED A NUMBER with a 1"; |
mfiore | 5:a946ef74a8c4 | 29 | |
BlueShadow | 8:a09dd040bb4b | 30 | FXOS8700 accel(D14,D15); |
BlueShadow | 8:a09dd040bb4b | 31 | FXOS8700 mag(D14,D15); |
BlueShadow | 8:a09dd040bb4b | 32 | FXAS21002 gyro(D14,D15); |
mfiore | 0:a44e71488e1f | 33 | |
mfiore | 0:a44e71488e1f | 34 | // variables for sensor data |
BlueShadow | 8:a09dd040bb4b | 35 | char streamAcc[] = "acc_rms"; |
BlueShadow | 8:a09dd040bb4b | 36 | char streamMag[] = "mag_rms"; |
BlueShadow | 8:a09dd040bb4b | 37 | char streamGyr[] = "gyr_rms"; |
mfiore | 0:a44e71488e1f | 38 | |
mfiore | 0:a44e71488e1f | 39 | // misc variables |
BlueShadow | 6:7946b5c2376a | 40 | static int sms_interval_ms = 60000; |
BlueShadow | 8:a09dd040bb4b | 41 | static int read_interval_ms = 5000; |
BlueShadow | 8:a09dd040bb4b | 42 | static int print_interval_ms = 1500; |
mfiore | 0:a44e71488e1f | 43 | int debug_baud = 115200; |
mfiore | 0:a44e71488e1f | 44 | |
BlueShadow | 8:a09dd040bb4b | 45 | bool radio_ok = false; |
BlueShadow | 6:7946b5c2376a | 46 | |
BlueShadow | 6:7946b5c2376a | 47 | /**************************************************************************************************** |
mfiore | 0:a44e71488e1f | 48 | // function prototypes |
BlueShadow | 6:7946b5c2376a | 49 | ****************************************************************************************************/ |
mfiore | 0:a44e71488e1f | 50 | bool init_mtsas(); |
mfiore | 0:a44e71488e1f | 51 | |
BlueShadow | 6:7946b5c2376a | 52 | /**************************************************************************************************** |
mfiore | 0:a44e71488e1f | 53 | // main |
BlueShadow | 6:7946b5c2376a | 54 | ****************************************************************************************************/ |
BlueShadow | 6:7946b5c2376a | 55 | int main() |
BlueShadow | 6:7946b5c2376a | 56 | { |
mfiore | 0:a44e71488e1f | 57 | mts::MTSLog::setLogLevel(mts::MTSLog::TRACE_LEVEL); |
mfiore | 0:a44e71488e1f | 58 | debug.baud(debug_baud); |
mfiore | 0:a44e71488e1f | 59 | logInfo("starting..."); |
BlueShadow | 6:7946b5c2376a | 60 | |
BlueShadow | 6:7946b5c2376a | 61 | /**************************************************************************************************** |
BlueShadow | 6:7946b5c2376a | 62 | Initialize I2C Devices ************ |
BlueShadow | 6:7946b5c2376a | 63 | ****************************************************************************************************/ |
BlueShadow | 8:a09dd040bb4b | 64 | accel.accel_config(); |
BlueShadow | 8:a09dd040bb4b | 65 | mag.mag_config(); |
BlueShadow | 8:a09dd040bb4b | 66 | gyro.gyro_config(); |
BlueShadow | 6:7946b5c2376a | 67 | |
BlueShadow | 8:a09dd040bb4b | 68 | float accel_data[3]; |
BlueShadow | 8:a09dd040bb4b | 69 | //float mag_data[3]; |
BlueShadow | 8:a09dd040bb4b | 70 | //float gyro_data[3]; |
BlueShadow | 6:7946b5c2376a | 71 | |
BlueShadow | 6:7946b5c2376a | 72 | // Initialization Radio Section ********************************************************** |
BlueShadow | 6:7946b5c2376a | 73 | |
mfiore | 0:a44e71488e1f | 74 | radio_ok = init_mtsas(); |
mfiore | 0:a44e71488e1f | 75 | if (! radio_ok) |
mfiore | 0:a44e71488e1f | 76 | logError("MTSAS init failed"); |
mfiore | 0:a44e71488e1f | 77 | else |
mfiore | 0:a44e71488e1f | 78 | logInfo("MTSAS is ok"); |
BlueShadow | 6:7946b5c2376a | 79 | |
BlueShadow | 6:7946b5c2376a | 80 | //End Radio Initialization Section ********************************************************** |
BlueShadow | 8:a09dd040bb4b | 81 | float dataX = 0; |
BlueShadow | 8:a09dd040bb4b | 82 | float dataY = 0; |
BlueShadow | 8:a09dd040bb4b | 83 | float dataZ = 1; |
BlueShadow | 8:a09dd040bb4b | 84 | Timer sms_timer; |
BlueShadow | 8:a09dd040bb4b | 85 | sms_timer.start(); |
BlueShadow | 8:a09dd040bb4b | 86 | Timer read_timer; |
BlueShadow | 8:a09dd040bb4b | 87 | read_timer.start(); // Timer data is set in the Variable seciton see misc variables Timer motion_timer; |
mfiore | 1:a049d113e250 | 88 | Timer print_timer; |
BlueShadow | 6:7946b5c2376a | 89 | print_timer.start(); |
BlueShadow | 6:7946b5c2376a | 90 | Timer motion_timer; |
BlueShadow | 6:7946b5c2376a | 91 | motion_timer.start(); |
BlueShadow | 6:7946b5c2376a | 92 | |
mfiore | 0:a44e71488e1f | 93 | while (true) { |
BlueShadow | 8:a09dd040bb4b | 94 | if (read_timer.read_ms() > read_interval_ms) { |
BlueShadow | 6:7946b5c2376a | 95 | |
BlueShadow | 8:a09dd040bb4b | 96 | accel.acquire_accel_data_g(accel_data); |
BlueShadow | 8:a09dd040bb4b | 97 | dataX = accel_data[0]; |
BlueShadow | 8:a09dd040bb4b | 98 | dataY = accel_data[1]; |
BlueShadow | 8:a09dd040bb4b | 99 | dataZ = accel_data[2]; |
BlueShadow | 6:7946b5c2376a | 100 | |
BlueShadow | 8:a09dd040bb4b | 101 | read_timer.reset(); |
mfiore | 0:a44e71488e1f | 102 | } |
BlueShadow | 6:7946b5c2376a | 103 | |
mfiore | 0:a44e71488e1f | 104 | if (print_timer.read_ms() > print_interval_ms) { |
BlueShadow | 8:a09dd040bb4b | 105 | |
mfiore | 0:a44e71488e1f | 106 | logDebug("SENSOR DATA"); |
BlueShadow | 8:a09dd040bb4b | 107 | logDebug("DataZ %0.3f", dataZ); |
BlueShadow | 8:a09dd040bb4b | 108 | logDebug("DataY %0.3f", dataY); |
mfiore | 0:a44e71488e1f | 109 | print_timer.reset(); |
mfiore | 0:a44e71488e1f | 110 | } |
BlueShadow | 6:7946b5c2376a | 111 | |
BlueShadow | 8:a09dd040bb4b | 112 | // SMS |
BlueShadow | 6:7946b5c2376a | 113 | if (sms_timer.read_ms() > sms_interval_ms) { |
BlueShadow | 6:7946b5c2376a | 114 | sms_timer.reset(); |
BlueShadow | 6:7946b5c2376a | 115 | logInfo("SMS Send Routine"); |
BlueShadow | 8:a09dd040bb4b | 116 | printf(" In sms routine \r\n"); |
mfiore | 0:a44e71488e1f | 117 | if (radio_ok) { |
mfiore | 0:a44e71488e1f | 118 | MbedJSONValue sms_json; |
mfiore | 0:a44e71488e1f | 119 | string sms_str; |
BlueShadow | 6:7946b5c2376a | 120 | |
BlueShadow | 9:3dcbe04adfd0 | 121 | sms_json[" edge Gravity: "] = dataY; |
BlueShadow | 9:3dcbe04adfd0 | 122 | sms_json[" level Gravity: "] = dataZ; |
BlueShadow | 6:7946b5c2376a | 123 | |
mfiore | 2:955a63247721 | 124 | sms_str = "SENSOR DATA:\n"; |
mfiore | 0:a44e71488e1f | 125 | sms_str += sms_json.serialize(); |
BlueShadow | 6:7946b5c2376a | 126 | |
mfiore | 0:a44e71488e1f | 127 | logDebug("sending SMS to %s:\r\n%s", phone_number.c_str(), sms_str.c_str()); |
BlueShadow | 9:3dcbe04adfd0 | 128 | if (dataZ<0.6f) { //added |
mfiore | 0:a44e71488e1f | 129 | Code ret = radio->sendSMS(phone_number, sms_str); |
mfiore | 0:a44e71488e1f | 130 | if (ret != MTS_SUCCESS) |
mfiore | 0:a44e71488e1f | 131 | logError("sending SMS failed"); |
BlueShadow | 9:3dcbe04adfd0 | 132 | } //added |
mfiore | 0:a44e71488e1f | 133 | } |
mfiore | 0:a44e71488e1f | 134 | } |
mfiore | 0:a44e71488e1f | 135 | } |
mfiore | 0:a44e71488e1f | 136 | } |
mfiore | 0:a44e71488e1f | 137 | |
mfiore | 1:a049d113e250 | 138 | // init functions |
BlueShadow | 6:7946b5c2376a | 139 | bool init_mtsas() |
BlueShadow | 6:7946b5c2376a | 140 | { |
mfiore | 1:a049d113e250 | 141 | io = new MTSSerialFlowControl(RADIO_TX, RADIO_RX, RADIO_RTS, RADIO_CTS); |
mfiore | 1:a049d113e250 | 142 | if (! io) |
mfiore | 1:a049d113e250 | 143 | return false; |
BlueShadow | 6:7946b5c2376a | 144 | |
mfiore | 1:a049d113e250 | 145 | io->baud(115200); |
mfiore | 1:a049d113e250 | 146 | radio = CellularFactory::create(io); |
mfiore | 1:a049d113e250 | 147 | if (! radio) |
mfiore | 1:a049d113e250 | 148 | return false; |
BlueShadow | 6:7946b5c2376a | 149 | |
mfiore | 1:a049d113e250 | 150 | Code ret = radio->setApn(apn); |
mfiore | 1:a049d113e250 | 151 | if (ret != MTS_SUCCESS) |
mfiore | 1:a049d113e250 | 152 | return false; |
BlueShadow | 6:7946b5c2376a | 153 | |
mfiore | 5:a946ef74a8c4 | 154 | Transport::setTransport(radio); |
BlueShadow | 6:7946b5c2376a | 155 | |
mfiore | 1:a049d113e250 | 156 | return true; |
mfiore | 1:a049d113e250 | 157 | } |