mDot processor with ROHM sensor board on UDK2.
Dependencies: MbedJSONValue libmDot mbed-rtos mbed
Fork of VVV_MultiTech_Dragonfly_ATT_Dallas by
Revision 9:10082fc85d18, committed 2016-02-28
- Comitter:
- BlueShadow
- Date:
- Sun Feb 28 23:17:46 2016 +0000
- Parent:
- 8:720595aa7bfd
- Commit message:
- Cleaned up ROHM board for Training classes. Removed some extra remarks and unused variables.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
| mbed-rtos.lib | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Feb 26 02:42:23 2016 +0000
+++ b/main.cpp Sun Feb 28 23:17:46 2016 +0000
@@ -1,5 +1,5 @@
/*************************************************************************
- * Originally this was a
+ * Originally this was a
* Dragonfly Example program for 2015 AT&T Government Solutions Hackathon
*
* This is in process of being convertered to a mDot processor. mDot has a
@@ -17,11 +17,11 @@
* pressure sensor)
*
* What this program does:
- * - reads data from all sensors on MEMs board and moisture sensor on a
- * periodic basis
+ * - reads data from all sensors on MEMs board on a periodic basis
* - prints all sensor data to debug port on a periodic basis
* - optionally sends LoRa sensor data when the timer expires
- * THis needs to be written yet.
+ *
+ * This needs to be written yet.
* - optionally sends sensor data to AT&T M2X cloud platform (user must
* create own M2X account and configure a device)
* - you need to set the "m2x_api_key" field and the "m2x_device_id"
@@ -56,10 +56,8 @@
*/
-
#include "mbed.h"
#include "MbedJSONValue.h"
-// #include "HTTPJson.h"
#include <string>
// added the following help files for a mDot not required for Dragonfly.
@@ -73,21 +71,6 @@
// Debug serial port
static Serial debug(USBTX, USBRX);
-// see https://m2x.att.com/developer/documentation/v2/overview for M2X API documentation
-// M2X device ID
-static const std::string m2x_device_id = "";
-
-// M2X primary API key
-static const std::string m2x_api_key = "";
-
-// set to true if you want to post to the cloud
-// you need to have you M2X account set up properly for this to work?
-bool do_cloud_post = false;
-//bool do_cloud_post = true;
-
-std::string url = "http://api-m2x.att.com/v2/devices/" + m2x_device_id + "/update";
-
-
// variables for sensor data
float temp_celsius;
float humidity_percent;
@@ -99,12 +82,10 @@
// misc variables
static char wall_of_dash[] = "--------------------------------------------------";
-bool radio_ok = false;
static int thpm_interval_ms = 5000;
static int motion_interval_ms = 5000;
static int print_interval_ms = 5000;
static int sms_interval_ms = 60000;
-static int post_interval_ms = 30000;
int debug_baud = 115200;
@@ -121,7 +102,8 @@
#define COLOR //BH1745
#define KX022 //KX022, Accel Only
#define Pressure //BM1383
-//#define SMS //allow SMS messaging
+
+#define SMS //allow SMS messaging now sending LORA!!!!
//#define Web //allow M2X communication
@@ -326,10 +308,10 @@
mDot* dot;
std::vector<uint8_t> data;
std::string data_str = "hello! Jeff";
-
+
// get a mDot handle
dot = mDot::getInstance();
-
+
// print library version information
logInfo("version: %s", dot->getId().c_str());
@@ -338,12 +320,12 @@
//*******************************************
// reset to default config so we know what state we're in
dot->resetConfig();
-
+
dot->setLogLevel(mts::MTSLog::TRACE_LEVEL); //INFO_LEVEL
// set up the mDot with our network information: frequency sub band, network name, and network password
// these can all be saved in NVM so they don't need to be set every time - see mDot::saveConfig()
-
+
// frequency sub band is only applicable in the 915 (US) frequency band
// if using a MultiTech Conduit gateway, use the same sub band as your Conduit (1-8) - the mDot will use the 8 channels in that sub band
// if using a gateway that supports all 64 channels, use sub band 0 - the mDot will use all 64 channels
@@ -351,31 +333,31 @@
if ((ret = dot->setFrequencySubBand(config_frequency_sub_band)) != mDot::MDOT_OK) {
logError("failed to set frequency sub band %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
-
+
logInfo("setting network name");
if ((ret = dot->setNetworkName(config_network_name)) != mDot::MDOT_OK) {
logError("failed to set network name %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
-
+
logInfo("setting network password");
if ((ret = dot->setNetworkPassphrase(config_network_pass)) != mDot::MDOT_OK) {
logError("failed to set network password %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
-
+
// a higher spreading factor allows for longer range but lower throughput
// in the 915 (US) frequency band, spreading factors 7 - 10 are available
// in the 868 (EU) frequency band, spreading factors 7 - 12 are available
logInfo("setting TX spreading factor");
- if ((ret = dot->setTxDataRate(mDot::SF_10)) != mDot::MDOT_OK) {
+ if ((ret = dot->setTxDataRate(mDot::SF_7)) != mDot::MDOT_OK) {
logError("failed to set TX datarate %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
-
+
// request receive confirmation of packets from the gateway
logInfo("enabling ACKs");
if ((ret = dot->setAck(1)) != mDot::MDOT_OK) {
logError("failed to enable ACKs %d:%s", ret, mDot::getReturnCodeString(ret).c_str());
}
-
+
// save this configuration to the mDot's NVM
logInfo("saving config");
if (! dot->saveConfig()) {
@@ -411,11 +393,6 @@
sms_timer.start();
#endif
-#ifdef Web
- Timer post_timer;
- post_timer.start();
-#endif
-
while (true) {
if (thpm_timer.read_ms() > thpm_interval_ms) {
#ifdef AnalogTemp
@@ -478,84 +455,18 @@
if (sms_timer.read_ms() > sms_interval_ms) {
sms_timer.reset();
logInfo("SMS Send Routine");
-printf(" In sms routine \r\n");
-// if (radio_ok) {
-// MbedJSONValue sms_json;
-// string sms_str;
-//
-// sms_json["temp_C"] = BDE0600_output;
-// sms_json["UV"] = ML8511_output;
-// sms_json["Ambient Light"] = RPR0521_ALS[0];
-// sms_json["Prox"] = RPR0521_ALS[1];
-// sms_json["pressure_hPa"] = BM1383[1];
-// sms_json["mag_mgauss"]["x"] = MEMS_Mag[0];
-// sms_json["mag_mgauss"]["y"] = MEMS_Mag[1];
-// sms_json["mag_mgauss"]["z"] = MEMS_Mag[2];
-// sms_json["acc_mg"]["x"] = MEMS_Accel[0];
-// sms_json["acc_mg"]["y"] = MEMS_Accel[1];
-// sms_json["acc_mg"]["z"] = MEMS_Accel[2];
-// sms_json["Red"] = BH1745[0];
-// sms_json["Green"] = BH1745[1];
-// sms_json["Blue"] = BH1745[2];
-//
-// sms_str = "SENSOR DATA:\n";
-// sms_str += sms_json.serialize();
-//
-// logDebug("sending SMS to %s:\r\n%s", phone_number.c_str(), sms_str.c_str());
-// Code ret = radio->sendSMS(phone_number, sms_str);
-// if (ret != MTS_SUCCESS)
-// logError("sending SMS failed");
-// }
+ printf(" In sms routine \r\n");
+
}
#endif
-#ifdef Web
- if (post_timer.read_ms() > post_interval_ms && do_cloud_post) {
- printf("in web\n\r");
-// if (radio->connect()) {
-// logDebug("posting sensor data");
-//
-// HTTPClient http;
-// MbedJSONValue http_json_data;
-// std::string http_json_str;
-// std::string m2x_header = "X-M2X-KEY: " + m2x_api_key + "\r\n";
-// int ret;
-// 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"] = BDE0600_output;
-// http_json_data["values"]["UV"] = ML8511_output;
-// http_json_data["values"]["Ambient Light"] = RPR0521_ALS[0];
-// http_json_data["values"]["Prox"] = RPR0521_ALS[1];
-// http_json_str = http_json_data.serialize();
-//
-// // add extra header with M2X API key
-// http.setHeader(m2x_header.c_str());
-//
-// HTTPJson http_json((char*) http_json_str.c_str());
-// ret = http.post(url.c_str(), http_json, &http_response);
-// if (ret != HTTP_OK)
-// logError("posting data to cloud failed: [%d][%s]", ret, http_response_buf);
-// else
-// logDebug("post result [%d][%s]", http.getHTTPResponseCode(), http_response_buf);
-//
-// radio->disconnect();
-// } else {
-// logError("establishing PPP link failed");
-// }
-
- post_timer.reset();
- }
-#endif
wait_ms(10);
}
}
-
+/************************************************************************************************/
// Sensor data acquisition functions
/************************************************************************************************/
#ifdef AnalogTemp
@@ -596,7 +507,7 @@
// printf(" South Detect = %d\r\n", Hall_Return[0]);
// printf(" North Detect = %d\r\n", Hall_Return[1]);
-
+
}
#endif
@@ -712,7 +623,7 @@
#ifdef KX022
void ReadKX022 ()
{
-
+
//Read KX022 Portion from the IC
i2c.write(KX022_addr_w, &KX022_Addr_Accel_ReadData, 1, RepStart);
i2c.read(KX022_addr_r, &KX022_Content_ReadData[0], 6, NoRepStart);
@@ -758,38 +669,3 @@
}
#endif
-
-
-/************************************************************************************
-// reference only to remember what the names and fuctions are without finding them above.
- ************************************************************************************
- (" Temp = %.2f C\r\n", BDE0600_output);
- printf(" UV = %.1f mW/cm2\r\n", ML8511_output);
-
- printf("BH1745 COLOR Sensor Data:\r\n");
- printf(" Red = %d ADC Counts\r\n",BH1745[0]);
- printf(" Green = %d ADC Counts\r\n",BH1745[1]);
- printf(" Blue = %d ADC Counts\r\n",BH1745[2]);
-
- printf(" ALS = %0.2f lx\r\n", RPR0521_ALS[0]);
- printf(" PROX= %u ADC Counts\r\n", RPR0521_ALS[1]); //defined as a float but is an unsigned, bad coding on my part.
-
- printf("KMX62 Accel+Mag Sensor Data:\r\n");
- printf(" AccX= %0.2f g\r\n", MEMS_Accel[0]);
- printf(" AccY= %0.2f g\r\n", MEMS_Accel[1]);
- printf(" AccZ= %0.2f g\r\n", MEMS_Accel[2]);
-
- printf(" MagX= %0.2f uT\r\n", MEMS_Mag[0]);
- printf(" MagY= %0.2f uT\r\n", MEMS_Mag[1]);
- printf(" MagZ= %0.2f uT\r\n", MEMS_Mag[2]);
-
- printf("KX022 Accelerometer Sensor Data: \r\n");
- printf(" AccX= %0.2f g\r\n", KX022_Accel[0]);
- printf(" AccY= %0.2f g\r\n", KX022_Accel[1]);
- printf(" AccZ= %0.2f g\r\n", KX022_Accel[2]);
-
- printf("BM1383 Pressure Sensor Data:\r\n");
- printf(" Temperature= %0.2f C\r\n", BM1383[0]);
- printf(" Pressure = %0.2f hPa\r\n", BM1383[1]);
-
- **********************************************************************************/
--- a/mbed-rtos.lib Fri Feb 26 02:42:23 2016 +0000 +++ b/mbed-rtos.lib Sun Feb 28 23:17:46 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed-rtos/#07314541bd12 +http://mbed.org/users/mbed_official/code/mbed-rtos/#b4c5542476ba
