Sample code for using Aeris AerCloud with MultiTech Socket Modem

Dependencies:   FXLS8471Q MPL3115A2 MQTT mbed

Dependents:   MultiTech_AerCloud_ST-sensor_Modem

Fork of 2lemetry_Sensor_Example by Multi-Hackers

Files at this revision

API Documentation at this revision

Comitter:
mchowla
Date:
Fri Dec 12 22:26:35 2014 +0000
Parent:
3:9736a8776102
Commit message:
Initial Version of MultiTech Socket Modem Example

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
mtsas.lib Show annotated file Show diff for this revision Revisions of this file
diff -r 9736a8776102 -r 81c6b9d73cb1 main.cpp
--- a/main.cpp	Tue Oct 28 19:09:28 2014 +0000
+++ b/main.cpp	Fri Dec 12 22:26:35 2014 +0000
@@ -1,6 +1,6 @@
 /* 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.
+ * a cellular connection to Aeris AerCloud using an MQTT client protocol.
  */
 
 #include "mbed.h"
@@ -9,34 +9,45 @@
 #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
- * You must have a hacker (or higher) account at http://app.thingfabric.com
- * After you register and login, follow the steps below to set up your client
- * Click on "Default ThingFabric Project"
- *      Set _2LEMETRY_DOMAIN to the string after "Project" at the top of the page
- * Click on "Credentials"
- * Click on "Default ThingFabric Credential"
- *      Set _2LEMETRY_USER_ID to the value in the "Key (Username)" field
- *      Set _2LEMETRY_TOKEN to the value in the "MD5 Secret" field
- * If you are running this code on multiple devices, you will want to make the _2LEMETRY_DEVICE_ID field unique for each device
- * Set the _APN field to the APN provided with your sim card
- * Build, flash, and run
- *      This code sends a random integer value approximately every 30 seconds
- * Click on "Default ThingFabric Project"
- * Click on "Analytics"
- * You should be able to see your test data (page needs to be refreshed periodically, it doesn't automatically refresh)
- */
+//
+// PLEASE READ THIS!
+//
+// Example was created for the following hardware:
+//   ST Nucleo F401RE   http://developer.mbed.org/platforms/ST-Nucleo-F401RE/
+//   Freescale Multi-Sensor Shield https://developer.mbed.org/components/Freescale-Multi-Sensor-Shield/
+//   MultiTech Socket Modem Shield: http://developer.mbed.org/components/Multi-Tech-SocketModem-Arduino-Shield-MT/
+//   MultiTech MTSMC-H5 GSM Socket Modem http://www.multitech.com/models/92503252LF#gsc.tab=0
+//
+// To get the sample running, you'll need to fill in the following parameters below
+//   Your cellular provider's APN: _APN
+//   AerCloud API Key: _AERCLOUD_API_APIKEY
+//   AerCloud Account ID: _AERCLOUD_ACCOUNT_ID
+//   AerCloud Container: _ACERCLOUD_CONTAINER
+//
+// The AerCloud container needa a Data Model with the following schema:
+//    accel_x  FLOAT
+//    accel_y  FLOAT 
+//    accel-Z  FLOAT
+//    pressure FLOAT
+//    temperature FLOAT
+//
+// To check if data has made it in the container, create a long polling subscription in AerPort and they use the following url in your browswer
+//
+// http://longpoll.aercloud.aeris.com/v1/1/containers/subscriptions/<subscrption_name>/notificationChannels/longPoll?apiKey=<api_key>
+//
+// You should see the something that looks like this in the browser:
+// {"sclContentInstances":[{"sclId":"nucleo-0001","containerId":"Nucleo_Test","contentInstance":{"id":"a40c8e60-8248-11e4-8b38-0677f0dfdf5e","contentSize":90,"creationTime":1418420922950,"content":{"contentType":"application/json","contentTypeBinary":"{\"x\":0.005615,\"y\":-0.041260,\"z\":1.015137,\"pressure\":101098.500000,\"temperature\":25.125000}"}}},
+//
+//
 
-char _2LEMETRY_USERID[] = "";
-char _2LEMETRY_TOKEN[] = "";
-char _2LEMETRY_DOMAIN[] = "";
-char _2LEMETRY_STUFF[] = "mbed";
-char _2LEMETRY_DEVICE_ID[] = "nucleo-0001";
+char _AERCLOUD_API_KEY[] = "SET_YOUR_API_KEY";
+char _AERCLOUD_ACCOUNT_ID[] = "SET_YOUR_ACCOUNT_NUMBER";
+char _AERCLOUD_CONTAINER[] = "Nucleo_Test";
+char _AERCLOUD_DEVICE_ID[] = "nucleo-0001";
 
-char _APN[] = "";
+char _APN[] = "SET_YOUR_CELLULAR_PROVIDERS_APN" ";
 
-char _host[] = "q.mq.tt";
+char _host[] = "mqtt.aercloud.aeris.com";
 int _port = 1883;
 
 #define MPL3115A2_I2C_ADDRESS (0x60<<1)
@@ -48,6 +59,7 @@
 }
 
 int main() {
+    printf("Hello World\r\n");
     MTSLog::setLogLevel(MTSLog::TRACE_LEVEL);
     
     // for Nucleo boards
@@ -73,11 +85,25 @@
         wait(2);
     }
     
+    printf("Signal Strength: %d\n\r", radio->getSignalStrength()); //Check the signal strength should be above 8
+    
+    // If you suspect a connectivity issue, uncomment the code below and if ping works.  If you are not getting a
+    //  valid ping, there's a connectivity problem.  First step is to verify you've got the right APN set
+    //
+    // Try pinging default server "8.8.8.8" (Google's DNS)
+    //int ping_valid = 0;
+    //while (ping_valid == 0) {
+    //    ping_valid = radio->ping();
+    //    printf("Ping Valid: %s\n\r", ping_valid ? "true" : "false");
+    //    
+    //    if (ping_valid == 0) {
+    //        wait(3);
+    //    }
+    //}
+    
     PubSubClient mqtt(_host, _port, callback);
     
-    char topicStr[128];
     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);
@@ -86,8 +112,9 @@
     float acc_data[3];
     
     while (true) {
-        if (! mqtt.connect(_2LEMETRY_DEVICE_ID, _2LEMETRY_USERID, _2LEMETRY_TOKEN)) {
-            logError("failed to connect to 2lemetry server");
+        if (! mqtt.connect(_AERCLOUD_DEVICE_ID, _AERCLOUD_ACCOUNT_ID, _AERCLOUD_API_KEY)) {
+            logError("failed to connect to AerCloud Server");
+            wait(5);
             continue;
         }
         
@@ -95,7 +122,7 @@
         
         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)) {
+        if (! mqtt.publish(_AERCLOUD_CONTAINER, buf)) {
             logError("failed to publish: [%s]", buf);
         }
         wait(1);
diff -r 9736a8776102 -r 81c6b9d73cb1 mbed.bld
--- a/mbed.bld	Tue Oct 28 19:09:28 2014 +0000
+++ b/mbed.bld	Fri Dec 12 22:26:35 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/cb3d968589d8
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file
diff -r 9736a8776102 -r 81c6b9d73cb1 mtsas.lib
--- a/mtsas.lib	Tue Oct 28 19:09:28 2014 +0000
+++ b/mtsas.lib	Fri Dec 12 22:26:35 2014 +0000
@@ -1,1 +1,1 @@
-http://developer.mbed.org/teams/Multi-Hackers/code/mtsas/#45f3c6dbd646
+http://developer.mbed.org/teams/Multi-Hackers/code/mtsas/