Example program that reads in sensor data and sends it to the 2lemetry cloud.
Dependencies: FXLS8471Q MPL3115A2 MQTT mbed
Fork of 2lemetry_Sensor_Example by
Revision 1:76498fdfbecf, committed 2014-10-28
- Comitter:
- Vanger
- Date:
- Tue Oct 28 19:03:29 2014 +0000
- Parent:
- 0:b8d93d878bcb
- Child:
- 2:643e3707d043
- Commit message:
- Example program that utilizes the FRDM-FXS_MULTI board to measure data, and sends it through cellular to the 2lemetry cloud.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/FXLS8471Q.lib Tue Oct 28 19:03:29 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/JimCarver/code/FXLS8471Q/#b1fd3a2572e2
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MPL3115A2.lib Tue Oct 28 19:03:29 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/teams/components/code/MPL3115A2/#8c90a97b1036
--- a/main.cpp Tue Oct 28 17:14:45 2014 +0000 +++ b/main.cpp Tue Oct 28 19:03:29 2014 +0000 @@ -1,6 +1,13 @@ +/* This is an example program which reads in the 3-axis acceleration, pressure, and temperature data from + * a FRDM-FXS-MULTI sensor board. It then uses an MTSAS SocketModem Shield board to send the read data over + * a cellular connection to the 2lemetry cloud using an MQTT client protocol. + */ + #include "mbed.h" #include "mtsas.h" #include "PubSubClient.h" +#include "FXLS8471Q.h" +#include "MPL3115A2.h" /* PLEASE READ THIS! * The following fields must be populated in order to properly send data to the "Default ThingFabric Project" in your 2lemetry account using the MQTT client @@ -21,17 +28,21 @@ * You should be able to see your test data (page needs to be refreshed periodically, it doesn't automatically refresh) */ -char _2LEMETRY_USERID[] = ""; -char _2LEMETRY_TOKEN[] = ""; -char _2LEMETRY_DOMAIN[] = ""; -char _2LEMETRY_STUFF[] = "things"; +char _2LEMETRY_USERID[] = "086f47ee-9a3f-4f3f-8ae5-c0a13e059f74"; +char _2LEMETRY_TOKEN[] = "64bc612e5e632b3687a93c6326bfaaff"; +char _2LEMETRY_DOMAIN[] = "n49bxegoz2urcfy"; +char _2LEMETRY_STUFF[] = "mbed"; char _2LEMETRY_DEVICE_ID[] = "nucleo-0001"; -char _APN[] = ""; +char _APN[] = "dynamic.dcnm2m.com"; char _host[] = "q.mq.tt"; int _port = 1883; +#define MPL3115A2_I2C_ADDRESS (0x60<<1) + +#define DATA_INTERVAL 30 + void callback(char* topic, char* payload, unsigned int len) { logInfo("topic: [%s]\r\npayload: [%s]", topic, payload); } @@ -65,15 +76,25 @@ PubSubClient mqtt(_host, _port, callback); char topicStr[128]; - char buf[64]; + char buf[128]; snprintf(topicStr, sizeof(topicStr), "%s/%s/%s", _2LEMETRY_DOMAIN, _2LEMETRY_STUFF, _2LEMETRY_DEVICE_ID); + FXLS8471Q acc(D11, D12, D13, D10); + MPL3115A2 alt(D14, D15, MPL3115A2_I2C_ADDRESS, D4, D3); + alt.Barometric_Mode(); + + float acc_data[3]; + float temperature, pressure; + while (true) { if (! mqtt.connect(_2LEMETRY_DEVICE_ID, _2LEMETRY_USERID, _2LEMETRY_TOKEN)) { logError("failed to connect to 2lemetry server"); continue; } - snprintf(buf, sizeof(buf), "{\"test\":%d}", rand()); + + acc.ReadXYZ(acc_data); + + snprintf(buf, sizeof(buf), "{\"x\":%f,\"y\":%f,\"z\":%f,\"pressure\":%f,\"temperature\":%f}", acc_data[0],acc_data[1],acc_data[2], alt.getPressure(), alt.getTemperature()); logInfo("publishing: [%s]", buf); if (! mqtt.publish(topicStr, buf)) { logError("failed to publish: [%s]", buf); @@ -81,8 +102,7 @@ wait(1); mqtt.loop(); mqtt.disconnect(); - wait(30); + wait(DATA_INTERVAL); } - return 0; } \ No newline at end of file
--- a/mbed.bld Tue Oct 28 17:14:45 2014 +0000 +++ b/mbed.bld Tue Oct 28 19:03:29 2014 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/552587b429a1 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/cb3d968589d8 \ No newline at end of file