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"}
Diff: wnc_control.cpp
- Revision:
- 53:dcccf2881fa0
- Parent:
- 46:da9d788f5d5a
- Child:
- 62:73c564e883e9
--- a/wnc_control.cpp Sun Jul 24 22:10:12 2016 +0000 +++ b/wnc_control.cpp Tue Jul 26 20:32:00 2016 +0000 @@ -5,6 +5,12 @@ #include "SerialBuffered.h" #include "wnc_control.h" +// Outputs detailed WNC command info +#define WNC_CMD_DEBUG_ON + +// Full debug output, longer cmds and extra cellular status checking +#undef WNC_CMD_DEBUG_ON_VERBOSE + extern Serial pc; extern Serial mdm; extern string MyServerIpAddress; @@ -225,21 +231,26 @@ int regSts; int cmdRes1, cmdRes2; +#ifdef WNC_CMD_DEBUG_ON_VERBOSE pc.puts("<-------- Begin Cell Status ------------\r\n"); - +#endif cmdRes1 = at_send_wnc_cmd("AT+CSQ", &pRespStr, WNC_TIMEOUT_MS); // Check RSSI,BER cmdRes2 = at_send_wnc_cmd("AT+CPIN?", &pRespStr, WNC_TIMEOUT_MS); // Check if SIM locked if ((cmdRes1 != 0) && (cmdRes2 != 0)) { +#ifdef WNC_CMD_DEBUG_ON_VERBOSE pc.puts("------------ WNC No Response! --------->\r\n"); +#endif return (-2); } // If SIM Card not ready don't bother with commands! if (pRespStr->find("CPIN: READY") == string::npos) { +#ifdef WNC_CMD_DEBUG_ON_VERBOSE pc.puts("------------ WNC SIM Problem! --------->\r\n"); +#endif return (-1); } @@ -254,12 +265,16 @@ // 1 - registered home, 5 - registered roaming if ((regSts != 1) && (regSts != 5)) { +#ifdef WNC_CMD_DEBUG_ON_VERBOSE pc.puts("------------ WNC Cell Link Down! ------>\r\n"); +#endif return (-2); } } +#ifdef WNC_CMD_DEBUG_ON_VERBOSE pc.puts("------------ WNC Ready ---------------->\r\n"); +#endif return (0); } @@ -272,16 +287,37 @@ if (check_wnc_ready() < 0) { static string noRespStr; - string truncStr(s, 50); + +#ifdef WNC_CMD_DEBUG_ON pc.puts("FAIL send cmd: "); + #ifdef WNC_CMD_DEBUG_ON_VERBOSE + pc.puts(s); + #else + string truncStr(s, 50); + truncStr += "\r\n"; pc.puts(truncStr.c_str()); - pc.puts("\r\n"); + #endif +#else + pc.puts("FAIL send cmd!\r\n"); +#endif + WNC_MDM_ERR = WNC_CELL_LINK_DOWN; noRespStr.erase(); *r = &noRespStr; return (-3); } - + +#ifdef WNC_CMD_DEBUG_ON + #ifdef WNC_CMD_DEBUG_ON_VERBOSE + pc.puts("[---------- Network Status -------------\r\n"); + #endif + string * pRespStr; + at_send_wnc_cmd("AT@SOCKDIAL?", &pRespStr, 5000); + #ifdef WNC_CMD_DEBUG_ON_VERBOSE + pc.puts("---------------------------------------]\r\n"); + #endif +#endif + // If WNC ready, send user command cmdRes = at_send_wnc_cmd(s, r, ms_timeout); @@ -301,6 +337,11 @@ { static const char * rsp_lst[] = { "OK", "ERROR", NULL }; int len; + +#ifdef WNC_CMD_DEBUG_ON + #ifdef WNC_CMD_DEBUG_ON_VERBOSE + + #else if (strlen(s) > 60) { string truncStr(s,57); @@ -308,14 +349,22 @@ pc.printf("Send: <<%s>>\r\n",truncStr.c_str()); } else + #endif pc.printf("Send: <<%s>>\r\n",s); - +#endif + int res = mdm_sendAtCmdRsp(s, rsp_lst, ms_timeout, &wncStr, &len); *r = &wncStr; // Return a pointer to the static string if (res >= 0) - { + { + +#ifdef WNC_CMD_DEBUG_ON pc.puts("["); + #ifdef WNC_CMD_DEBUG_ON_VERBOSE + pc.puts(wncStr.c_str()); + pc.puts("]\r\n"); + #else if (wncStr.size() < 51) pc.puts(wncStr.c_str()); else @@ -323,7 +372,9 @@ string truncStr = wncStr.substr(0,50) + "..."; pc.puts(truncStr.c_str()); } - pc.puts("]\n\r"); + pc.puts("]\r\n"); + #endif +#endif if (res > 0) return -1;