Example program for MultiTech Dragonfly using Grove moisture sensor and Grove button.
Dependencies: MbedJSONValue mbed mtsas
Fork of MultiTech_Dragonfly_2015_ATT_Gov_Solutions_Hackathon_Example by
Revision 6:d6cf1bf4130e, committed 2015-09-27
- Comitter:
- mfiore
- Date:
- Sun Sep 27 02:05:19 2015 +0000
- Parent:
- 5:a946ef74a8c4
- Commit message:
- remove all code for ST MEMs board
Changed in this revision
X_NUCLEO_IKS01A1.lib | Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r a946ef74a8c4 -r d6cf1bf4130e X_NUCLEO_IKS01A1.lib --- a/X_NUCLEO_IKS01A1.lib Sat Sep 26 22:07:27 2015 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://developer.mbed.org/teams/ST/code/X_NUCLEO_IKS01A1/#a91987e8cf51
diff -r a946ef74a8c4 -r d6cf1bf4130e main.cpp --- a/main.cpp Sat Sep 26 22:07:27 2015 +0000 +++ b/main.cpp Sun Sep 27 02:05:19 2015 +0000 @@ -8,14 +8,9 @@ * - Seeed Studio Base Shield * - Grove moisture sensor (to connect to Base Shield) * - Grove button (to connect to Base Shield) - * - MEMs Inertial and Environmental Nucleo Expansion board (LSM6DS0 - * 3-axis accelerometer + 3-axis gyroscope, LIS3MDL 3-axis - * magnetometer, HTS221 humidity and temperature sensor and LPS25HB - * pressure sensor) * * What this program does: - * - reads data from all sensors on MEMs board and moisture sensor on a - * periodic basis + * - reads data from the moisture sensor on a periodic basis * - prints all sensor data to debug port on a periodic basis * - optionally send a SMS containing sensor data when the Grove Button * is pushed @@ -37,7 +32,6 @@ * Shield * - Make sure the reference voltage selector switch (next to the A0 * socket) is switched to 5V so you get accurate analog readings - * - Stack the MEMs board on top of the Base Shield * - Plug in the power cable * - Plug a micro USB cable into the port below and slightly to the * left of the Dragonfly (NOT the port on the Dragonfly) @@ -48,7 +42,6 @@ #include "mbed.h" #include "mtsas.h" -#include "x_nucleo_iks01a1.h" #include "MbedJSONValue.h" #include "HTTPJson.h" #include <string> @@ -85,9 +78,6 @@ std::string url = "http://api-m2x.att.com/v2/devices/" + m2x_device_id + "/update"; -// handle to MEMs board object -static X_NUCLEO_IKS01A1* mems = X_NUCLEO_IKS01A1::Instance(); - // Moisture sensor AnalogIn moisture_sensor(A0); @@ -96,33 +86,19 @@ bool button_pressed = false; // variables for sensor data -float temp_celsius; -float temp_fahrenheit; -float humidity_percent; -float pressure_mbar; float moisture_percent; -int32_t mag_mgauss[3]; -int32_t acc_mg[3]; -int32_t gyro_mdps[3]; // misc variables static char wall_of_dash[] = "--------------------------------------------------"; bool radio_ok = false; static int thpm_interval_ms = 2000; -static int motion_interval_ms = 250; static int print_interval_ms = 10000; static int post_interval_ms = 30000; int debug_baud = 115200; // function prototypes bool init_mtsas(); -void read_temperature(); -void read_humidity(); -void read_pressure(); void read_moisture(); -void read_magnetometer(); -void read_accelerometer(); -void read_gyroscope(); void button_irq(); // main @@ -140,27 +116,16 @@ button.fall(&button_irq); Timer thpm_timer; - Timer motion_timer; Timer print_timer; Timer post_timer; thpm_timer.start(); - motion_timer.start(); print_timer.start(); post_timer.start(); while (true) { - if (motion_timer.read_ms() > motion_interval_ms) { - read_magnetometer(); - read_accelerometer(); - read_gyroscope(); - motion_timer.reset(); - } if (thpm_timer.read_ms() > thpm_interval_ms) { - read_temperature(); - read_humidity(); - read_pressure(); read_moisture(); thpm_timer.reset(); } @@ -168,13 +133,7 @@ if (print_timer.read_ms() > print_interval_ms) { logDebug("%s", wall_of_dash); logDebug("SENSOR DATA"); - logDebug("temperature: %f C\t%f F", temp_celsius, temp_fahrenheit); - logDebug("humidity: %f%%", humidity_percent); - logDebug("pressure: %f mbar", pressure_mbar); logDebug("moisture: %f%%", moisture_percent); - logDebug("magnetometer:\r\n\tx: %ld\ty: %ld\tz: %ld\tmgauss", mag_mgauss[0], mag_mgauss[1], mag_mgauss[2]); - logDebug("accelerometer:\r\n\tx: %ld\ty: %ld\tz: %ld\tmg", acc_mg[0], acc_mg[1], acc_mg[2]); - logDebug("gyroscope:\r\n\tx: %ld\ty: %ld\tz: %ld\tmdps", gyro_mdps[0], gyro_mdps[1], gyro_mdps[2]); logDebug("%s", wall_of_dash); print_timer.reset(); } @@ -186,20 +145,7 @@ MbedJSONValue sms_json; string sms_str; - sms_json["temp_C"] = temp_celsius; - sms_json["temp_F"] = temp_fahrenheit; - sms_json["humidity_percent"] = humidity_percent; - sms_json["pressure_mbar"] = pressure_mbar; sms_json["moisture_percent"] = moisture_percent; - sms_json["mag_mgauss"]["x"] = mag_mgauss[0]; - sms_json["mag_mgauss"]["y"] = mag_mgauss[1]; - sms_json["mag_mgauss"]["z"] = mag_mgauss[2]; - sms_json["acc_mg"]["x"] = acc_mg[0]; - sms_json["acc_mg"]["y"] = acc_mg[1]; - sms_json["acc_mg"]["z"] = acc_mg[2]; - sms_json["gyro_mdps"]["x"] = gyro_mdps[0]; - sms_json["gyro_mdps"]["y"] = gyro_mdps[1]; - sms_json["gyro_mdps"]["z"] = gyro_mdps[2]; sms_str = "SENSOR DATA:\n"; sms_str += sms_json.serialize(); @@ -223,12 +169,8 @@ char http_response_buf[256]; HTTPText http_response(http_response_buf, sizeof(http_response_buf)); - // temp_c, temp_f, humidity, pressure, and moisture are all stream IDs for my device in M2X - // modify these to match your streams or give your streams the same name - http_json_data["values"]["temp_c"] = temp_celsius; - http_json_data["values"]["temp_f"] = temp_fahrenheit; - http_json_data["values"]["humidity"] = humidity_percent; - http_json_data["values"]["pressure"] = pressure_mbar; + // moisture is a stream ID for my device in M2X + // modify this to match your streams or give your stream the same name http_json_data["values"]["moisture"] = moisture_percent; http_json_str = http_json_data.serialize(); @@ -275,62 +217,11 @@ } // Sensor data acquisition functions -void read_temperature() { - int ret; - - ret = mems->ht_sensor->GetTemperature(&temp_celsius); - if (ret) - logError("reading temp (C) failed"); - - ret = mems->ht_sensor->GetFahrenheit(&temp_fahrenheit); - if (ret) - logError("reading temp (F) failed"); -} - -void read_humidity() { - int ret; - - ret = mems->ht_sensor->GetHumidity(&humidity_percent); - if (ret) - logError("reading humidity failed"); -} - -void read_pressure() { - int ret; - - ret = mems->pt_sensor->GetPressure(&pressure_mbar); - if (ret) - logError("reading pressure failed"); -} void read_moisture() { moisture_percent = moisture_sensor * 100.0; } -void read_magnetometer() { - int ret; - - ret = mems->magnetometer->Get_M_Axes(mag_mgauss); - if (ret) - logError("reading magnetometer failed"); -} - -void read_accelerometer() { - int ret; - - ret = mems->GetAccelerometer()->Get_X_Axes(acc_mg); - if (ret) - logError("reading accelerometer failed"); -} - -void read_gyroscope() { - int ret; - - ret = mems->GetGyroscope()->Get_G_Axes(gyro_mdps); - if (ret) - logError("reading gyroscope failed"); -} - void button_irq() { button_pressed = true; }