Pubnub demo for AT&T IoT Starter Kit. Functionally similar to the Flow demo.

Dependencies:   FXOS8700CQ MODSERIAL mbed

http://pubnub.github.io/slides/workshop/pictures/broadcast.png

Pubnub demo for AT&T IoT Starter Kit

This demo is functionally similar to the Flow demo, so you can find general information here: https://developer.mbed.org/users/JMF/code/Avnet_ATT_Cellular_IOT/.

The only difference is that we use Pubnub to publish the measurements and subscribe to receiving the instructions to set the LED.

Settings

Pubnub related settings are:

Pubnub settings in `config_me.h`

PUBNUB_SUBSCRIBE_KEY
PUBNUB_PUBLISH_KEY
PUBNUB_CHANNEL

All are documented in their respective comments.

Pubnub context class

Similar to Pubnub SDKs, we provide a Pubnub context class. It is defined in pubnub.h header file and implemented in pubnub.cpp.

It provides only the fundamental "publish" and "subscribe" methods. They are documented in the header file.

This class is reusable in other code (it is not specific to this demo), it has a very narrow interface to the AT&T IoT cellular modem code. For example of use, you can look at the main() (in main.c).

Sample of published data

Published message w/measurement data

{"serial":"vstarterkit001","temp":89.61,"humidity":35,"accelX":0.97,"accelY":0.013,"accelZ":-0.038}

Don't worry, nobody got burnt, the temperature is in degrees Fahrenheit. :)

Publish a message (from, say, the Pubnub console http://pubnub.com/console) of the form {"LED":<name-of-the-color>} on the channel that this demo listens to (default is hello_world) to turn the LED to that color on the Starter Kit:

Turn LED to red

{"LED":"Red"}

Turn LED to green

{"LED":"Green"}

Turn LED to blue

{"LED":"Blue"}
Revision:
64:09004cd610df
Parent:
63:90d7c69993cd
Child:
68:6e311c747045
diff -r 90d7c69993cd -r 09004cd610df cell_modem.cpp
--- a/cell_modem.cpp	Mon Aug 01 20:19:58 2016 +0000
+++ b/cell_modem.cpp	Mon Aug 01 23:32:55 2016 +0000
@@ -66,7 +66,7 @@
 
     if (cmd && strlen(cmd) > 0) {
         if (mdm_dbgmask & MDM_DBG_AT_CMDS) {
-            printf(MAG "ATCMD: " DEF "--> " GRN "%s" DEF "\n", cmd);
+            PRINTF(MAG "ATCMD: " DEF "--> " GRN "%s" DEF "\n", cmd);
         }
         mdm.puts(cmd);
         mdm.puts("\r\n");
@@ -88,7 +88,7 @@
                 continue;
                 
             if (mdm_dbgmask & MDM_DBG_AT_CMDS) {
-                printf(MAG "ATRSP: " DEF "<-- " CYN "%s" DEF "\n", rsp);
+                PRINTF(MAG "ATRSP: " DEF "<-- " CYN "%s" DEF "\n", rsp);
             }
         
             if (rsp_list) {
@@ -149,7 +149,7 @@
         if (rc == 0)
             return true; //timer.read();
         wait_ms(1000 - (timer.read_ms() % 1000));
-        pc.printf("\r%d",timer.read_ms()/1000);
+        PRINTF("\r%d",timer.read_ms()/1000);
     }
     return false;       
 }
@@ -163,7 +163,7 @@
 
     if (cmd && n > 0) {
         if (mdm_dbgmask & MDM_DBG_AT_CMDS) {
-            printf(MAG "ATCMD: " DEF "--> " GRN "%s" DEF "\n", cmd);
+            PRINTF(MAG "ATCMD: " DEF "--> " GRN "%s" DEF "\n", cmd);
         }
 //        mdm.puts(cmd);
 //        mdm.puts("\r\n");
@@ -196,7 +196,7 @@
             }
 
             if (mdm_dbgmask & MDM_DBG_AT_CMDS) {
-                printf(MAG "ATRSP: " DEF "<-- " CYN "%s" DEF "\n", cmd_buf);
+                PRINTF(MAG "ATRSP: " DEF "<-- " CYN "%s" DEF "\n", cmd_buf);
             }
 
             int rsp_idx = 0;
@@ -216,11 +216,11 @@
 void reinitialize_mdm(void)
 {
     // Initialize the modem
-    printf(GRN "Modem RE-initializing..." DEF "\r\n");
+    PRINTF(GRN "Modem RE-initializing..." DEF "\r\n");
     if (!mdm_init()) {
-        printf(RED "\n\rModem RE-initialization failed!" DEF "\n");
+        PRINTF(RED "\n\rModem RE-initialization failed!" DEF "\n");
     }
-    printf("\r\n");
+    PRINTF("\r\n");
 }
 // These are built on the fly
 string MyServerIpAddress;
@@ -266,11 +266,11 @@
 
     pc.baud(115200);
      // Initialize the modem
-    printf(GRN "Modem initializing... will take up to 60 seconds" DEF "\r\n");
+    PRINTF(GRN "Modem initializing... will take up to 60 seconds" DEF "\r\n");
     do {
         i=mdm_init();
         if (!i) {
-            pc.printf(RED "Modem initialization failed!" DEF "\n");
+            PRINTF(RED "Modem initialization failed!" DEF "\n");
         }
     } while (!i);
     
@@ -287,31 +287,31 @@
 int cell_modem_Sendreceive(char* tx_string, char* rx_string) 
 {
     int iStatus = 0; //error by default
-    printf(DEF "\r\n");
-    printf(BLU "Sending to modem : %s" DEF "\r\n", &tx_string[0]); 
+    PRINTF(DEF "\r\n");
+    PRINTF(BLU "Sending to modem : %s" DEF "\r\n", &tx_string[0]); 
     sockwrite_mdm(&tx_string[0]);
     if (sockread_mdm(&MySocketData, 1024, 20))
     {
-        printf(DEF "\r\n");
-        printf(YEL "Read back : %s" DEF "\r\n", &MySocketData[0]);
+        PRINTF(DEF "\r\n");
+        PRINTF(YEL "Read back : %s" DEF "\r\n", &MySocketData[0]);
         char stringToCharBuf[BUF_SIZE_FOR_N_MAX_SOCKREAD*MAX_WNC_SOCKREAD_PAYLOAD+1]; // WNC can return max of 1500 (per sockread)
         if ((MySocketData.length() + 1) < sizeof(stringToCharBuf))
         {
             strcpy(stringToCharBuf, MySocketData.c_str());
             if (extract_JSON(stringToCharBuf, &rx_string[0]))
             {
-                printf(GRN "JSON : %s" DEF "\n", &rx_string[0]);
+                PRINTF(GRN "JSON : %s" DEF "\n", &rx_string[0]);
                 iStatus = 1; //all good
             }
         }
         else
         {
-            printf(RED "BUFFER not big enough for sock data!" DEF "\r\n");
+            PRINTF(RED "BUFFER not big enough for sock data!" DEF "\r\n");
         }
     }
     else
     {
-        printf(RED "No response..." DEF "\r\n");
+        PRINTF(RED "No response..." DEF "\r\n");
     }
     return iStatus;
 }