Pubnub demo for AT&T IoT Starter Kit. Functionally similar to the Flow demo.
Dependencies: FXOS8700CQ MODSERIAL mbed
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 57:d184175b6b03, committed 2016-07-28
- Comitter:
- stefanrousseau
- Date:
- Thu Jul 28 23:55:06 2016 +0000
- Parent:
- 56:cb42ff383dab
- Child:
- 58:c417fbc39c22
- Commit message:
- Found that a merge at some point used an older version of sensors.cpp. Replacing the omitted changes...
Changed in this revision
sensors.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/sensors.cpp Thu Jul 28 17:21:31 2016 +0000 +++ b/sensors.cpp Thu Jul 28 23:55:06 2016 +0000 @@ -1,15 +1,13 @@ #include "mbed.h" +#include "sensors.h" #include "hardware.h" -#include "sensors.h" +#include "FXOS8700CQ.h" //I2C for pmod sensors: #define Si1145_PMOD_I2C_ADDR 0xC0 //this is for 7-bit addr 0x60 for the Si7020 #define Si7020_PMOD_I2C_ADDR 0x80 //this is for 7-bit addr 0x4 for the Si7020 -#include "FXOS8700CQ.h" -// Pin names for the motion sensor FRDM-K64F board: -FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1) -// Storage for the data from the sensor +// Storage for the data from the motion sensor SRAWDATA accel_data; SRAWDATA magn_data; //InterruptIn fxos_int1(PTC6); // unused, common with SW2 on FRDM-K64F @@ -18,7 +16,7 @@ void trigger_fxos_int2(void) { fxos_int2_triggered = true; - //us_ellapsed = t.read_us(); + } /*------------------------------------------------------------------------------ @@ -265,25 +263,29 @@ //printf("PS2_Data = %d\n", PS2); //printf("PS3_Data = %d\n", PS3); //OBJECT PRESENT? +#if (0) if(PS1 < 22000){ //printf("Object Far\n"); - sprintf(SENSOR_DATA.Proximity, "Object Far"); + sprintf(SENSOR_DATA.Proximity, "Object Far\0"); } else if(PS1 < 24000) { //printf("Object in Vicinity\n"); - sprintf(SENSOR_DATA.Proximity, "Object in Vicinity"); + sprintf(SENSOR_DATA.Proximity, "Object in Vicinity\0"); } else if (PS1 < 30000) { //printf("Object Near\n"); - sprintf(SENSOR_DATA.Proximity, "Object Near"); + sprintf(SENSOR_DATA.Proximity, "Object Near\0"); } else { //printf("Object Very Near\n"); - sprintf(SENSOR_DATA.Proximity, "Object Very Near"); + sprintf(SENSOR_DATA.Proximity, "Object Very Near\0"); } +#else + sprintf(SENSOR_DATA.Proximity, "%d\0", PS1); +#endif //Force ALS read: //WriteTo_Si1145_Register(REG_COMMAND, 0x06); @@ -312,8 +314,11 @@ bool bMotionSensor_present = false; 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: + FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1) int iWhoAmI = fxos.get_whoami(); - + printf("FXOS8700CQ WhoAmI = %X\r\n", iWhoAmI); // Iterrupt for active-low interrupt line from FXOS // Configured with only one interrupt on INT2 signaling Data-Ready @@ -332,8 +337,12 @@ 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: + FXOS8700CQ fxos(PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1); // SDA, SCL, (addr << 1) if (bMotionSensor_present) { + fxos.enable(); fxos.get_data(&accel_data, &magn_data); //printf("Roll=%5d, Pitch=%5d, Yaw=%5d;\r\n", magn_data.x, magn_data.y, magn_data.z); sprintf(SENSOR_DATA.MagnetometerX, "%5d", magn_data.x);