![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Sample program for using Pubnub on AT&T IoT Starter Kit (which has the WNC modem)
Dependencies: Pubnub_mbed2_sync WNCInterface mbed-rtos mbed
Fork of WNCInterface_M2XMQTTdemo by
Revision 10:f05fb235b75b, committed 2016-11-11
- Comitter:
- sveljko
- Date:
- Fri Nov 11 22:49:05 2016 +0000
- Parent:
- 9:dcb02cfdc63c
- Commit message:
- Added generating the UUID, using the rand() and setting srand() from pubnub_time()
Changed in this revision
Pubnub_mbed2_sync.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r dcb02cfdc63c -r f05fb235b75b Pubnub_mbed2_sync.lib --- a/Pubnub_mbed2_sync.lib Thu Nov 10 22:48:18 2016 +0000 +++ b/Pubnub_mbed2_sync.lib Fri Nov 11 22:49:05 2016 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/users/sveljko/code/Pubnub_mbed2_sync/#9fbec3606b08 +https://developer.mbed.org/users/sveljko/code/Pubnub_mbed2_sync/#4d49720c7200
diff -r dcb02cfdc63c -r f05fb235b75b main.cpp --- a/main.cpp Thu Nov 10 22:48:18 2016 +0000 +++ b/main.cpp Fri Nov 11 22:49:05 2016 +0000 @@ -2,13 +2,31 @@ #include "WNCInterface.h" #include "pubnub_sync.h" +#include "srand_from_pubnub_time.h" + #define CRLF "\r\n" WNCInterface eth; MODSERIAL pc(USBTX,USBRX,256,256); -extern "C" int myprintf(char *, ...) { return 0; } + +static void generate_uuid(pubnub_t *pbp) +{ + char const *uuid_default = "zeka-peka-iz-jendeka"; + struct Pubnub_UUID uuid; + static struct Pubnub_UUID_String str_uuid; + + if (0 != pubnub_generate_uuid_v4_random(&uuid)) { + pubnub_set_uuid(pbp, uuid_default); + } + else { + str_uuid = pubnub_uuid_to_string(&uuid); + pubnub_set_uuid(pbp, str_uuid.uuid); + pc.printf("Generated UUID: %s\n", str_uuid.uuid); + } +} + int main() { @@ -20,8 +38,12 @@ pc.printf("IP Address: %s" CRLF, eth.getIPAddress()); eth.doDebug(1); + pubnub_t *pbp = pubnub_alloc(); pubnub_init(pbp, "demo", "demo"); + + srand_from_pubnub_time(pbp); + generate_uuid(pbp); while (true) { pubnub_res rslt = pubnub_publish(pbp, "hello_world", "\"Hello world from MBed WNC!\"");