Channel Groups API for Mbed SDK
Channel groups allow PubNub developers to bundle thousands of channels into a group that can be identified by a name. These channel groups can then be subscribed to, receiving data from the many back-end channels the channel group contains.
Channel group operations
You can't publish to a channel group. You can only subscribe to it. To publish within the channel group, you need to publish to each channel individually.
Add channels to a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the PubNub Admin Portal. Read the support page on enabling add-on features on your keys.
This function adds channels to a channel group.
Method(s)
Adding Channels
is accomplished by using the following method(s) in the mbed SDK:
1enum pubnub_res pubnub_add_channel_to_group (pubnub_t *p, char const *channel, char const *channel_group)
Parameter | Description |
---|---|
p *Type: pubnub_t* | Pointer to PubNub client context. |
channel *Type: char const* | The channel to add |
channel_group *Type: char const* | The channel group to add to |
Sample code
Add channels
1static char *channel_group = "family";
1enum pubnub_res res;
2res = pubnub_add_channel_to_group(pn, "wife", channel_group);
3return check_response(pn, res);
Rest response from server
1{
2 "service" : "channel-registry",
3 "status" : 200,
4 "error" : false,
5 "message" : "OK"
6}
List channels in a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function lists all channels in a channel group.
Method(s)
Listing Channels
is accomplished by using the following method(s) in the mbed SDK:
1enum pubnub_res pubnub_list_channel_group (pubnub_t *p, char const *channel_group)
Parameter | Description |
---|---|
p *Type: pubnub_t* | Pointer to PubNub client context. |
channel_group *Type: char const* | The channel group to list channels from |
Sample code
List channels
1static char *channel_group = "family";
1pubnub_list_channel_group(ctx, channel_group);
2pbresult = pubnub_await(ctx);
3if (PNR_OK == pbresult) {
4 char const *json_response = pubnub_get(ctx);
5}
Rest response from server
1{
2 "status" : 200,
3 "payload" : {
4 "channels" : ["hi"],
5 "group" : "abcd"
6 },
7 "service" : "channel-registry",
8 "error" : False
9}
Remove channels from a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function removes channels from a channel group.
Method(s)
Removing Channels
is accomplished by using the following method(s) in the mbed SDK:
1enum pubnub_res pubnub_remove_channel_from_group (pubnub_t *p, char const *channel, char const *channel_group)
Parameter | Description |
---|---|
p *Type: pubnub_t* | Pointer to PubNub client context. |
channel *Type: char const* | The channel to remove |
channel_group *Type: char const* | The channel group to remove from |
Sample code
Removing channels :
1static char *channel_group = "family";
1enum pubnub_res res;
2res = pubnub_remove_channel_from_group(pn, "son", channel_group);
3return check_response(pn, res);
Rest response from server
1{
2 "status" : 200,
3 "message" : "OK",
4 "service" : "channel-registry",
5 "error" : False
6}
Delete a channel group
Requires Stream Controller add-on
This method requires that the Stream Controller add-on is enabled for your key in the Admin Portal. Read the support page on enabling add-on features on your keys.
This function deletes a channel group.
Method(s)
Deleting Channel Group
is accomplished by using the following method(s) in the mbed SDK:
1enum pubnub_res pubnub_remove_channel_group (pubnub_t *p, char const *channel_group)
Parameter | Description |
---|---|
p *Type: pubnub_t* | Pointer to PubNub client context. |
channel_group *Type: char const* | The channel group to remove. |
Sample code
Delete channel group
1static char *channel_group = "family";
1enum pubnub_res res;
2res = pubnub_remove_channel_group(pn, channel_group);
3return check_response(pn, res);
Rest response from server
1{
2 "status" : 200,
3 "message" : "OK",
4 "service" : "channel-registry",
5 "error" : False
6}