Please Wait

Loading..

Raspberry Pi SDK 1.0.0

Create amazing realtime applications easily with Yalgaar Raspberry Pi SDK

Raspberry Pi SDK

1 Connect To Yalgaar

Notes:

This Yalgaar Raspberry Pi SDK is compatible with mosquitto 1.4.5 or above versions.

Current version does not support AES Encryption feature.

Download package and include "yalgaar_api.h" in your code.

#include "yalgaar_api.h"

To connect to a Yalgaar client, use following method, it must have valid Client Key.

yalgaar_connect(char *clientKey,bool isSecure,char *uuid,char *AES_SECURITY_KEY,unsigned int AESTYPE,void(*connectionCallback)(yalgaar_error_t error_msg));

Parameter:

  • clientKey
    • Description: Yalgaar provided authentic client key for project.
    • DataType: unsigned char
  • isSecure
    • Description: Specified connection is establish with SSL or not.
    • DataType: boolean (value must be true or false)
  • AES_SECURITY_KEY
    • Description: Secret key use for encrypt/decrypt message.
    • DataType: unsigned char
  • AESTYPE
    • Description: Type of AES algorithm use for encrypt/decrypt message. Support AES type 128,192 and 256.
    • DataType: unsigned int
  • uuid
    • Description: Any unique user name for user to enable presence feature for client. UUID is CASE SENSITIVE and only alpha numeric, hyphens,@,underscore allowed and maximum length must be 50.
    • DataType: String
  • ConnectionCallback
    • Description: Called when successfully connected to server or any error during connection.
    • DataType: ENUM (yalgaar_error_t)


2 Publish Message

To publish message, use following method.

yalgaar_publish(const unsigned char *channel,char *message);

Parameter:

  • Message
    • Description: Data to be send on given channel.
    • DataType: unsigned char
  • Channel
    • Description: Channels name on which message will be published. Channel name is CASE SENSITIVE. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: unsigned char


3 Subscribe Message

To subscribe message, use following method.

yalgaar_subscribe(char *channel,void(*subscribeMessageCallback)(void  *),void(*presenceMessageCallback)(struct presence_t *), void(*errorMessageCallback)(void *));
yalgaar_subscribes(char **channel,void(*subscribeMessageCallback)(void  *),void(*presenceMessageCallback)(struct presence_t *), void(*errorMessageCallback)(void *));

Parameter:

  • channel
    • Description: channel name on which message will be subscribed. For multiple channel names use "yalgaar_subscribes" function. Channel name is CASE SENSITIVE. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: unsigned char
  • subscribe_message_callback
    • Description: Callback function to consume received message.
    • DataType: void *
  • presence_message_callback
    • Description: Callback function to consume presence events such as join or leave.
    • DataType: struct presence_t *
  • error_message_callback
    • Description: Callback is called on system error occurred during subscription.
    • DataType: void *


4 Unsubscribe Message

To unsubscribe message, use following method.

yalgaar_unsubscribe(channel);
  • channel
    • Description: Channel name to be unsubscribe. Only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: unsigned char


5 Get User List

To get list of all user subscribe with specified channel name, use following method.

yalgaar_GetUserList(char *channel,void(*userListCallback)(Sll *),void(*errorMessageCallback)(void *));

Parameter:

  • channel
    • Description: Valid channel name. Channel name is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: unsigned char
  • userListCallback
    • Description: Callback is called when successfully get user list.
    • DataType: Sll *
  • errorMessageCallback
    • Description: Callback is called on system error occurred during getting user list.
    • DataType: void *


6 Get Channel List

To get list of all channels subscribed by specified user, use following method.

yalgaar_GetChannelList(char *UUID,void(*channelListCallback)(Sll *),void(*errorMessageCallbacks)(void *));

Parameter:

  • UUID
    • Description: Valid UUID. UUID is CASE SENSITIVE and only alpha numeric, hyphens,@,underscore allowed and maximum length must be 50.
    • DataType: unsigned char
  • channelListCallback
    • Description: Callback is called when successfully get channel list.
    • DataType: DataCallback
  • errorMessageCallback
    • Description: Callback is called on system error occurred during getting channel list.
    • DataType: void *


7 History Message

To get message history from specified channel name, use following method.

yalgaar_GetHistoryMessage(char *channel,int messageCount, void(*historymessagecallback)(Sll *),void(*errorMessageCallback)(void *));

Parameter:

  • channel
    • Description: Valid channel name. Channel name is CASE SENSITIVE and only alpha numeric, hyphens, @, underscore allowed and maximum length must be 50.
    • DataType: unsigned char
  • messageCount
    • Description: How many messages that you want to fetch. Maximum 100 messages allow at a time.
    • DataType: int
  • historymessagecallback
    • Description: Callback is called when successfully get history message list.
    • DataType: Sll *


8 Disconnect

To disconnect connection with YalgaarClient, use following method.

yalgaar_disconnect();


You can publish/subscribe message like so :

#include "yalgaar_api.h"
void connection_Callback(int result,char *error_msg);
void subscribe_message_callback(void *payload)
{
	printf(stderr,"\n\nsubscribe_message_callback=%s\n",(char *)payload);	
}
void error_message_callback(void *error_msg)
{	
	printf("\n Error :%s \n",( char *)error_msg);
}
void connection_Callback(int result,char *error_msg)
{	
	yalgaar_error_t rc = FAILURE;
		
	char err_string[YALGAAR_ERROR_MESSAGE_LENGTH];
	if(!result)
	{			
		printf("\n Connected..\n");	
		rc = yalgaar_subscribe("YourChannel",&subscribe_message_callback,NULL,&error_message_callback);
		
		if(SUCCESS != rc)
		{
			enum_to_message(rc,err_string);
			printf("\nError subscribing : %s ", err_string);fflush(stdout);			
		}
		
		yalgaar_publish("YourChannel","This is Yalgaar Raspberry Pi SDK Example");				
		
	}
	else
	{
		printf("\nError:%s",error_msg);fflush(stdout);
	}
}
int main(int argc, char**argv)
{
	yalgaar_error_t rc = FAILURE;
	char err_string[YALGAAR_ERROR_MESSAGE_LENGTH];
	
	/**Yalgaar connect Method called*/
	rc = yalgaar_connect("YourClientKey",1,"UUID",0,0,&connection_Callback);
	if(SUCCESS != rc)
	{
		printf("\nError yalgaar_connect : %d ", rc);
		disconnectCallbackHandler();
		return -1;
	}	
	
	while(1)
	{
		/**this function is call to wait for receive from yalgaar */
		yalgaar_wait_to_read();				 
	}
	if(SUCCESS != rc)
	{
		printf("\nAn error occurred in the loop. %d\n",rc);
	}
	rc = yalgaar_disconnect();
	return rc;
}