PubNub Example.
Copyright (c) 2016-2018 Microchip Technology Inc. and its subsidiaries.
#include "socket/include/socket.h"
Data Structures | |
struct | pubnub |
Macros | |
#define | PUBNUB_BUF_MAXLEN (256) |
#define | PUBNUB_CTX_MAX (2) |
#define | PUBNUB_ORIGIN "pubsub.pubnub.com" |
#define | PUBNUB_ORIGIN_PORT (80) |
#define | PUBNUB_PRINTF(x) |
Use PUBNUB_ENABLE_DEBUG macro to enable/disable PubNub debug. More... | |
#define | PUBNUB_REPLY_MAXLEN (512) |
#define | PUBNUB_REQUEST "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: PubNub-WINC1500\r\nConnection: Keep-Alive\r\n\r\n" |
Typedefs | |
typedef struct pubnub | pubnub_t |
Enumerations | |
enum | pubnub_res { PNR_OK, PNR_TIMEOUT, PNR_IO_ERROR, PNR_HTTP_ERROR, PNR_FORMAT_ERROR, PNR_CANCELLED, PNR_STARTED, PNR_IN_PROGRESS, PNR_RX_BUFF_NOT_EMPTY, PNR_TX_BUFF_TOO_SMALL } |
enum | pubnub_state { PS_IDLE, PS_WAIT_DNS, PS_WAIT_CONNECT, PS_WAIT_SEND, PS_WAIT_RECV, PS_RECV } |
enum | pubnub_trans { PBTT_NONE, PBTT_SUBSCRIBE, PBTT_PUBLISH, PBTT_LEAVE } |
Functions | |
void | handle_dns_found (const char *name, uint32_t hostip) |
void | handle_tcpip (SOCKET sock, uint8_t u8Msg, void *pvMsg) |
char const * | pubnub_get (pubnub_t *pb) |
pubnub_t * | pubnub_get_ctx (uint8_t index) |
Return a context for the given index. More... | |
void | pubnub_init (pubnub_t *pb, const char *publish_key, const char *subscribe_key) |
Initialize the PubNub Client API. More... | |
bool | pubnub_publish (pubnub_t *pb, const char *channel, const char *message) |
bool | pubnub_subscribe (pubnub_t *pb, const char *channel) |
#define PUBNUB_BUF_MAXLEN (256) |
Referenced by handle_transaction().
#define PUBNUB_CTX_MAX (2) |
Referenced by handle_dns_found(), handle_tcpip_recv(), pubnub_find_ctx(), pubnub_get_ctx(), and valid_ctx_prt().
#define PUBNUB_ORIGIN "pubsub.pubnub.com" |
Referenced by handle_dns_found(), handle_start_connect(), and handle_transaction().
#define PUBNUB_ORIGIN_PORT (80) |
Referenced by handle_start_connect().
#define PUBNUB_PRINTF | ( | x | ) |
Use PUBNUB_ENABLE_DEBUG macro to enable/disable PubNub debug.
Referenced by handle_tcpip(), handle_tcpip_connect(), handle_tcpip_recv(), handle_transaction(), and pubnub_publish().
#define PUBNUB_REPLY_MAXLEN (512) |
Referenced by pubnub_subscribe().
#define PUBNUB_REQUEST "GET %s HTTP/1.1\r\nHost: %s\r\nUser-Agent: PubNub-WINC1500\r\nConnection: Keep-Alive\r\n\r\n" |
Referenced by handle_transaction().
enum pubnub_res |
Enumerator | |
---|---|
PNR_OK |
Success. Transaction finished successfully. |
PNR_TIMEOUT |
Time out before the request has completed. |
PNR_IO_ERROR |
Communication error (network or HTTP response format). |
PNR_HTTP_ERROR |
HTTP error. |
PNR_FORMAT_ERROR |
Unexpected input in received JSON. |
PNR_CANCELLED |
Request cancelled by user. |
PNR_STARTED |
Transaction started. Await the outcome via process message. |
PNR_IN_PROGRESS |
Transaction (already) ongoing. Can't start a new transaction. |
PNR_RX_BUFF_NOT_EMPTY |
Receive buffer (from previous transaction) not read, new subscription not allowed. |
PNR_TX_BUFF_TOO_SMALL |
The buffer is to small. Increase PUBNUB_BUF_MAXLEN. |
enum pubnub_state |
enum pubnub_trans |
void handle_dns_found | ( | const char * | name, |
uint32_t | hostip | ||
) |
References handle_start_connect(), m_aCtx, PS_WAIT_DNS, PUBNUB_CTX_MAX, PUBNUB_ORIGIN, pubnub_origin_addr, in_addr::s_addr, sockaddr_in::sin_addr, and pubnub::state.
Referenced by socket_resolve_cb().
void handle_tcpip | ( | SOCKET | sock, |
uint8_t | u8Msg, | ||
void * | pvMsg | ||
) |
References handle_tcpip_connect(), handle_tcpip_recv(), handle_transaction(), NULL, PS_WAIT_RECV, PS_WAIT_SEND, tstrSocketRecvMsg::pu8Buffer, pubnub_find_ctx(), PUBNUB_PRINTF, tstrSocketRecvMsg::s16BufferSize, SOCKET_MSG_CONNECT, SOCKET_MSG_RECV, SOCKET_MSG_SEND, pubnub::state, and tstrSocketRecvMsg::u16RemainingSize.
Referenced by m2m_tcp_socket_handler().
char const* pubnub_get | ( | pubnub_t * | pb | ) |
References pubnub::http_reply, pubnub::msg_end, pubnub::msg_ofs, NULL, and valid_ctx_prt().
Referenced by main().
pubnub_t* pubnub_get_ctx | ( | uint8_t | index | ) |
Return a context for the given index.
Contexts are statically allocated by the PubNub library and this is the only to get a pointer to one of them.
References m_aCtx, and PUBNUB_CTX_MAX.
Referenced by main().
void pubnub_init | ( | pubnub_t * | pb, |
const char * | publish_key, | ||
const char * | subscribe_key | ||
) |
Initialize the PubNub Client API.
References pubnub::auth, pubnub::last_result, NULL, PNR_IO_ERROR, PS_IDLE, pubnub::publish_key, pubnub::state, pubnub::subscribe_key, pubnub::tcp_socket, pubnub::timetoken, pubnub::uuid, and valid_ctx_prt().
Referenced by main().
References handle_start_connect(), handle_transaction(), pubnub::http_buf, pubnub::http_buf_len, pubnub::last_result, PBTT_PUBLISH, PNR_OK, PS_IDLE, PS_WAIT_SEND, pubnub::publish_key, PUBNUB_PRINTF, pubnub::state, pubnub::subscribe_key, pubnub::trans, pubnub::url, and valid_ctx_prt().
Referenced by main().
References pubnub::auth, handle_start_connect(), handle_transaction(), pubnub::http_buf, pubnub::http_buf_len, pubnub::http_reply, pubnub::last_result, PBTT_SUBSCRIBE, PNR_OK, PS_IDLE, PS_WAIT_SEND, PUBNUB_REPLY_MAXLEN, pubnub::state, pubnub::subscribe_key, pubnub::timetoken, pubnub::trans, pubnub::url, pubnub::uuid, and valid_ctx_prt().
Referenced by main().