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
pubnub_config.h@10:f05fb235b75b, 2016-11-11 (annotated)
- Committer:
- sveljko
- Date:
- Fri Nov 11 22:49:05 2016 +0000
- Revision:
- 10:f05fb235b75b
- Parent:
- 8:57a5d7fbba6d
Added generating the UUID, using the rand() and setting srand() from pubnub_time()
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sveljko | 8:57a5d7fbba6d | 1 | /* -*- c-file-style:"stroustrup"; indent-tabs-mode: nil -*- */ |
sveljko | 8:57a5d7fbba6d | 2 | #if !defined INC_PUBNUB_CONFIG |
sveljko | 8:57a5d7fbba6d | 3 | #define INC_PUBNUB_CONFIG |
sveljko | 8:57a5d7fbba6d | 4 | |
sveljko | 8:57a5d7fbba6d | 5 | |
sveljko | 8:57a5d7fbba6d | 6 | /* -- Next few definitions can be tweaked by the user, but with care -- */ |
sveljko | 8:57a5d7fbba6d | 7 | |
sveljko | 8:57a5d7fbba6d | 8 | /** Maximum number of PubNub contexts. It is used only if the |
sveljko | 8:57a5d7fbba6d | 9 | * contexts are statically allocated. |
sveljko | 8:57a5d7fbba6d | 10 | * A context is used to publish messages or subscribe to (get) them. |
sveljko | 8:57a5d7fbba6d | 11 | * |
sveljko | 8:57a5d7fbba6d | 12 | * Doesn't make much sense to have less than 1. :) |
sveljko | 8:57a5d7fbba6d | 13 | * OTOH, don't put too many, as each context takes (for our purposes) |
sveljko | 8:57a5d7fbba6d | 14 | * a significant amount of memory - app. 128 + @ref PUBNUB_BUF_MAXLEN + |
sveljko | 8:57a5d7fbba6d | 15 | * @ref PUBNUB_REPLY_MAXLEN bytes. |
sveljko | 8:57a5d7fbba6d | 16 | * |
sveljko | 8:57a5d7fbba6d | 17 | * A typical configuration may consist of a single pubnub context for |
sveljko | 8:57a5d7fbba6d | 18 | * channel subscription and another pubnub context that will periodically |
sveljko | 8:57a5d7fbba6d | 19 | * publish messages about device status (with timeout lower than message |
sveljko | 8:57a5d7fbba6d | 20 | * generation frequency). |
sveljko | 8:57a5d7fbba6d | 21 | * |
sveljko | 8:57a5d7fbba6d | 22 | * Another typical setup may have a single subscription context and |
sveljko | 8:57a5d7fbba6d | 23 | * maintain a pool of contexts for each publish call triggered by an |
sveljko | 8:57a5d7fbba6d | 24 | * external event (e.g. a button push). |
sveljko | 8:57a5d7fbba6d | 25 | * |
sveljko | 8:57a5d7fbba6d | 26 | * Of course, there is nothing wrong with having just one context, but |
sveljko | 8:57a5d7fbba6d | 27 | * you can't publish and subscribe at the same time on the same context. |
sveljko | 8:57a5d7fbba6d | 28 | * This isn't as bad as it sounds, but may be a source of headaches |
sveljko | 8:57a5d7fbba6d | 29 | * (lost messages, etc). |
sveljko | 8:57a5d7fbba6d | 30 | */ |
sveljko | 8:57a5d7fbba6d | 31 | #define PUBNUB_CTX_MAX 2 |
sveljko | 8:57a5d7fbba6d | 32 | |
sveljko | 8:57a5d7fbba6d | 33 | /** Maximum length of the HTTP buffer. This is a major component of |
sveljko | 8:57a5d7fbba6d | 34 | * the memory size of the whole pubnub context, but it is also an |
sveljko | 8:57a5d7fbba6d | 35 | * upper bound on URL-encoded form of published message, so if you |
sveljko | 8:57a5d7fbba6d | 36 | * need to construct big messages, you may need to raise this. */ |
sveljko | 8:57a5d7fbba6d | 37 | #define PUBNUB_BUF_MAXLEN 32000 |
sveljko | 8:57a5d7fbba6d | 38 | |
sveljko | 8:57a5d7fbba6d | 39 | /** Set to 0 to use a static buffer and then set its size via |
sveljko | 8:57a5d7fbba6d | 40 | #PUBNUB_REPLY_MAXLEN. Set to anything !=0 to use a dynamic |
sveljko | 8:57a5d7fbba6d | 41 | buffer, that is, dynamically try to allocate as much memory as |
sveljko | 8:57a5d7fbba6d | 42 | needed for the buffer. |
sveljko | 8:57a5d7fbba6d | 43 | */ |
sveljko | 8:57a5d7fbba6d | 44 | #define PUBNUB_DYNAMIC_REPLY_BUFFER 1 |
sveljko | 8:57a5d7fbba6d | 45 | |
sveljko | 8:57a5d7fbba6d | 46 | #if !PUBNUB_DYNAMIC_REPLY_BUFFER |
sveljko | 8:57a5d7fbba6d | 47 | |
sveljko | 8:57a5d7fbba6d | 48 | /** Maximum length of the HTTP reply when using a static buffer. The |
sveljko | 8:57a5d7fbba6d | 49 | * other major component of the memory size of the PubNub context, |
sveljko | 8:57a5d7fbba6d | 50 | * beside #PUBNUB_BUF_MAXLEN. Replies of API calls longer than this |
sveljko | 8:57a5d7fbba6d | 51 | * will be discarded and an error will be reported. Specifically, this |
sveljko | 8:57a5d7fbba6d | 52 | * may cause lost messages returned by subscribe if too many too large |
sveljko | 8:57a5d7fbba6d | 53 | * messages got queued on the Pubnub server. */ |
sveljko | 8:57a5d7fbba6d | 54 | #define PUBNUB_REPLY_MAXLEN 32000 |
sveljko | 8:57a5d7fbba6d | 55 | |
sveljko | 8:57a5d7fbba6d | 56 | #endif |
sveljko | 8:57a5d7fbba6d | 57 | |
sveljko | 8:57a5d7fbba6d | 58 | /** This is the URL of the Pubnub server. Change only for testing |
sveljko | 8:57a5d7fbba6d | 59 | purposes. |
sveljko | 8:57a5d7fbba6d | 60 | */ |
sveljko | 8:57a5d7fbba6d | 61 | #define PUBNUB_ORIGIN "pubsub.pubnub.com" |
sveljko | 8:57a5d7fbba6d | 62 | |
sveljko | 8:57a5d7fbba6d | 63 | /** Set to 0 to disable changing the origin from the default |
sveljko | 8:57a5d7fbba6d | 64 | #PUBNUB_ORIGIN. Set to anything != 0 to enable changing the |
sveljko | 8:57a5d7fbba6d | 65 | origin (per context). |
sveljko | 8:57a5d7fbba6d | 66 | */ |
sveljko | 8:57a5d7fbba6d | 67 | #define PUBNUB_ORIGIN_SETTABLE 1 |
sveljko | 8:57a5d7fbba6d | 68 | |
sveljko | 8:57a5d7fbba6d | 69 | /** Duration of the transaction timeout set during context initialization, |
sveljko | 8:57a5d7fbba6d | 70 | in milliseconds. Can be changed later by the user. |
sveljko | 8:57a5d7fbba6d | 71 | */ |
sveljko | 8:57a5d7fbba6d | 72 | #define PUBNUB_DEFAULT_TRANSACTION_TIMER 310000 |
sveljko | 8:57a5d7fbba6d | 73 | |
sveljko | 8:57a5d7fbba6d | 74 | #define PUBNUB_HAVE_MD5 0 |
sveljko | 8:57a5d7fbba6d | 75 | #define PUBNUB_HAVE_SHA1 0 |
sveljko | 8:57a5d7fbba6d | 76 | |
sveljko | 8:57a5d7fbba6d | 77 | |
sveljko | 8:57a5d7fbba6d | 78 | /** The size of the stack (in kilobytes) for the "polling" thread, when using |
sveljko | 8:57a5d7fbba6d | 79 | the callback interface. We don't need much, so, if you want to conserve |
sveljko | 8:57a5d7fbba6d | 80 | memory, you can try small values. It's hard to say what is the minumum, |
sveljko | 8:57a5d7fbba6d | 81 | as it depends on the OS functions we call, but, you probably |
sveljko | 8:57a5d7fbba6d | 82 | shouldn't try less than 64 KB. |
sveljko | 8:57a5d7fbba6d | 83 | |
sveljko | 8:57a5d7fbba6d | 84 | Set to `0` to use the default stack size. |
sveljko | 8:57a5d7fbba6d | 85 | */ |
sveljko | 8:57a5d7fbba6d | 86 | #define PUBNUB_CALLBACK_THREAD_STACK_SIZE_KB 0 |
sveljko | 8:57a5d7fbba6d | 87 | |
sveljko | 8:57a5d7fbba6d | 88 | |
sveljko | 8:57a5d7fbba6d | 89 | /** If true (!=0), enable support for (HTTP/S) proxy */ |
sveljko | 8:57a5d7fbba6d | 90 | #define PUBNUB_PROXY_API 0 |
sveljko | 8:57a5d7fbba6d | 91 | |
sveljko | 8:57a5d7fbba6d | 92 | /** The maximum length (in characters) of the host name of the proxy |
sveljko | 8:57a5d7fbba6d | 93 | that will be saved in the Pubnub context. |
sveljko | 8:57a5d7fbba6d | 94 | */ |
sveljko | 8:57a5d7fbba6d | 95 | #define PUBNUB_MAX_PROXY_HOSTNAME_LENGTH 63 |
sveljko | 8:57a5d7fbba6d | 96 | |
sveljko | 8:57a5d7fbba6d | 97 | /** If true (!=0), enable support for message encryption/decryption */ |
sveljko | 8:57a5d7fbba6d | 98 | #define PUBNUB_CRYPTO_API 0 |
sveljko | 8:57a5d7fbba6d | 99 | |
sveljko | 8:57a5d7fbba6d | 100 | |
sveljko | 8:57a5d7fbba6d | 101 | #include <MODSERIAL.h> |
sveljko | 8:57a5d7fbba6d | 102 | extern MODSERIAL pc; |
sveljko | 8:57a5d7fbba6d | 103 | #define PUBNUB_LOG_PRINTF(...) pc.printf(__VA_ARGS__) |
sveljko | 8:57a5d7fbba6d | 104 | |
sveljko | 8:57a5d7fbba6d | 105 | |
sveljko | 8:57a5d7fbba6d | 106 | #endif /* !defined INC_PUBNUB_CONFIG */ |