Please Wait

Loading..

Mbed SDK 1.0.0

Create amazing realtime applications easily with Yalgaar Mbed SDK

Mbed SDK

1 Connect To Yalgaar

Note:

There is no support for SSL/TLS and 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(const char* clientKey,const char *uuid,void(*connectionCallback)(char * ));

Parameter:

  • clientKey
    • Description: Yalgaar provided authentic client key for project.
    • DataType: const char*
  • 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: const char*
  • connectionCallback
    • Description: Called when successfully connected to server or any error during connection.
    • DataType: char *


2 Publish Message

To publish message, use following method.

yalgaar_publish(const char* Channel, char* Message);

Parameter:

  • Channel
    • Description: Channel 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: const char*
  • Message
    • Description: Data to be send on given channel.
    • DataType: char *


3 Subscribe Message

To subscribe message, use following method.

yalgaar_subscribe(char * subscribe_channel,void(* sub_msg_callback)(char *),void(*presence_msg_callback)(char *), void(*error_msg_callback)(char *));	
yalgaar_subscribes(char **subscribe_channel,void(* sub_msg_callback)(char *),void(*presence_msg_callback)(char *), void(*error_msg_callback)(char *));

Parameter:

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


4 Unsubscribe Message

To unsubscribe message, use following method.

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


5 Disconnect

To disconnect connection with YalgaarClient, use following method.

yalgaar_disconnect();


You can publish/subscribe message like so :

/** @fileName <yalgaar_api>
 *  @brief - <yalgaar sdk apis>
 *
 *  @Version:V:01:00:000
 *
 *
 * @Copyright:
 * Copyright (c) 2010 System Level Solution (India) pvt.ltd. Corporation.  All rights reserved.
 *
 * License: Free License for Yalgaar Users
 * Disclaimer:
 * SLS MAKES NO REPRESENTATION, WARRANTY, OR CONDITION OF ANY KIND, EXPRESS,
 * IMPLIED, STATUTORY, OR OTHERWISE OR IN ANY COMMUNICATION WITH YOU, INCLUDING,
 * BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, SATISFACTORY
 * QUALITY, FITNESS FOR ANY PARTICULAR PURPOSE, NONINFRINGEMENT, AND THEIR
 * EQUIVALENTS.
 */
#include "yalgaar_api.h"
Serial pc(USBTX, USBRX,115200);
EthernetInterface  eth;
yalgaar yalgaar_client;
Yalgaar_Error_t ret = FAILURE;
char err_string[YALGAAR_ERROR_MESSAGE_LENGTH] = {'\0'};
int pub_count = 10;
//Subscribe message callback
void subscribe_message_callback(char *payload)
{
    pc.printf("subscribe_message_callback :%s\r\n",payload);
}
//presence message callback
void presence_message_callback(char *message)
{
    pc.printf("presence_message_callback: %s\r\n",message);
}
//subscribe error message callback
void error_message_callback(char *error)
{
    pc.printf("error_message_callback :%s\r\n",error);
}
//Connection callback
void connection_Callback(char* error_dec)
{
    if(yalgaar_client.yalgaar_connected())
    {
        pc.printf("connection callback :: %s\r\n",error_dec);
    }
    else
    {
        pc.printf("connection_Callback :%s\r\n",error_dec);
    }
}
int main()
{
    wait(2.0f);
    eth.init(); //Use DHCP
    do pc.printf("Connection...\r\n");
    while (eth.connect() != 0);
    pc.printf("IP Address is %s\r\n", eth.getIPAddress());
	//yalgaar connect function
    ret = yalgaar_client.yalgaar_connect("YourClientKey","UUID", connection_Callback);
    if (SUCCESS != ret) {
        yalgaar_client.enum_to_message(ret, err_string);
        pc.printf("Connection fail %s \r\n",err_string);
    }
    
       
    if (ret == SUCCESS) {
        //yalgaar subscribe function        
        ret = yalgaar_client.yalgaar_subscribe("YourChannel", subscribe_message_callback, presence_message_callback, error_message_callback);
        
        if (SUCCESS != ret) {
            yalgaar_client.enum_to_message(ret, err_string);
            pc.printf("subscribe failure %s \r\n",err_string);
        }
    } else {
        pc.printf(" try again in 5 seconds\r\n");
        // Wait 5 seconds before retrying
        wait(5.0f);
    }
    while(1) {
        // Once connected, publish an announcement...
        if (yalgaar_client.yalgaar_connected()) {
            if (pub_count) {
                wait(5.0f);
                //yalgaar publish function
                ret = yalgaar_client.yalgaar_publish("YourChannel", "This is Yalgaar mbed SDK Example");
                if (SUCCESS != ret) {
                    yalgaar_client.enum_to_message(ret, err_string);
                    pc.printf("publish failure %s \r\n",err_string);
                }
                pub_count--;
            }
        }
        yalgaar_client.yalgaar_loop();
    }
}