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:
61:f6b93129f954
Parent:
57:d184175b6b03
Child:
64:09004cd610df
--- a/sensors.cpp	Sat Jul 30 16:26:22 2016 +0000
+++ b/sensors.cpp	Mon Aug 01 18:29:04 2016 +0000
@@ -2,6 +2,8 @@
 #include "sensors.h"
 #include "hardware.h"
 #include "FXOS8700CQ.h"
+#include "HTS221.h"
+#include <string>
 
 //I2C for pmod sensors:
 #define Si1145_PMOD_I2C_ADDR   0xC0 //this is for 7-bit addr 0x60 for the Si7020
@@ -312,7 +314,7 @@
 //* Read the FXOS8700CQ - 6-axis combo Sensor Accelerometer and Magnetometer
 //********************************************************************************************************************************************
 bool bMotionSensor_present = false;
-void init_motion_sensor()
+void Init_motion_sensor()
 {
     // Note: this class is instantiated here because if it is statically declared, the cellular shield init kills the I2C bus...
     // Class instantiation with pin names for the motion sensor on the FRDM-K64F board:
@@ -333,9 +335,9 @@
         bMotionSensor_present = true;
         fxos.enable();
     }
-} //init_motion_sensor
+} //Init_motion_sensor()
 
-void read_motion_sensor()
+void Read_motion_sensor()
 {
     // Note: this class is instantiated here because if it is statically declared, the cellular shield init kills the I2C bus...
     // Class instantiation with pin names for the motion sensor on the FRDM-K64F board:
@@ -359,8 +361,46 @@
         sprintf(SENSOR_DATA.AccelY, "%2.3f", fAccelScaled_y);
         sprintf(SENSOR_DATA.AccelZ, "%2.3f", fAccelScaled_z);
     } //bMotionSensor_present
-} //read_motion_sensor
+} //Read_motion_sensor()
+
+
+//********************************************************************************************************************************************
+//* Read the HTS221 temperature & humidity sensor on the Cellular Shield
+//********************************************************************************************************************************************
+// These are to be built on the fly
+string my_temp;
+string my_humidity;
+HTS221 hts221;
 
+#define CTOF(x)  ((x)*1.8+32)
+bool bHTS221_present = false;
+void Init_HTS221()
+{
+    int i;
+    void hts221_init(void);
+    i = hts221.begin();
+    if (i)
+    {
+        bHTS221_present = true;
+        pc.printf(BLU "HTS221 Detected (0x%02X)\n\r",i);
+        printf("  Temp  is: %0.2f F \n\r",CTOF(hts221.readTemperature()));
+        printf("  Humid is: %02d %%\n\r",hts221.readHumidity());
+    }
+    else
+    {
+        bHTS221_present = false;
+        pc.printf(RED "HTS221 NOT DETECTED!\n\r");
+    }
+} //Init_HTS221()
+
+void Read_HTS221()
+{
+    if (bHTS221_present)
+    {
+        sprintf(SENSOR_DATA.Temperature, "%0.2f", CTOF(hts221.readTemperature()));
+        sprintf(SENSOR_DATA.Humidity, "%02d", hts221.readHumidity());
+    } //bHTS221_present
+} //Read_HTS221()
 
 #ifdef USE_VIRTUAL_SENSORS
 bool bUsbConnected = false;
@@ -497,14 +537,16 @@
 #ifdef USE_VIRTUAL_SENSORS
    pc.attach(&UsbUartRxCallback, MODSERIAL::RxIrq);
 #endif
+    Init_HTS221();
     Init_Si7020();
     Init_Si1145();
-    init_motion_sensor();
+    Init_motion_sensor();
 } //sensors_init
 
 void read_sensors(void)
 {
+    Read_HTS221();
     Read_Si7020();
     Read_Si1145();
-    read_motion_sensor();
+    Read_motion_sensor();
 } //read_sensors