Please Wait

Loading..

Arduino SDK 1.0.0

Create amazing realtime applications easily with Yalgaar Arduino SDK

Arduino SDK

1 Connect To Yalgaar

Notes:

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, const 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: const char*


3 Subscribe Message

To subscribe message, use following method.

yalgaar_subscribe(char* channel, void(*subscribe_message_callback)(char*,int), void(* yalgaar_presence_message_recv)(char *,int), void(*error_msg_callback)(void *));	
yalgaar_subscribes(char** channel, void(*subscribe_message_callback)(char*,int), void (* yalgaar_presence_message_recv)(char *,int), void(*error_msg_callback)(void *));

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 *
  • subscribe_message_callback
    • Description: Callback function to consume received message.
    • DataType: void *
  • yalgaar_presence_message_recv
    • Description: Callback function to consume presence events such as join or leave.
    • DataType: void *
  • error_msg_callback
    • Description: Callback is called on system error occurred during subscription.
    • DataType: void *


4 Unsubscribe Message

To unsubscribe message, use following method.

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


5 Disconnect

To disconnect connection with YalgaarClient, use following method.

yalgaar_disconnect();


You can publish/subscribe message like so :

#include "yalgaar_api.h"
EthernetClient ethClient;
yalgaar yalgaarclient(ethClient);
int pub_count = 5;
Yalgaar_Error_t ret = FAILURE;
char err_string[YALGAAR_ERROR_MESSAGE_LENGTH] = {'\0'};
// Update these with values suitable for your network.
byte mac[] = {MAC-ADDRESS};
IPAddress ip(IP-ADDRESS); // This is for static ip 
void subscribe_message_callback(char *payload, int length)
{
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();
}
void presence_message_callback(char *message, int length)
{
  for (int i = 0; i < length; i++) {
    Serial.print((char)message[i]);
  }
  Serial.println();
}
void error_message_callback(char *error)
{
  Serial.println("error_message_callback");
  Serial.println(error);
}
void connection_Callback(char* error_dec)
{
  Serial.print("Error Message:");
  Serial.println(error_dec);
}
void setup() {
  // put your setup code here, to run once:
  Serial.begin(57600);
  Ethernet.begin(mac, ip); //this is for static IP, For dynamic IP pass only mac address
  // Allow the hardware to sort itself out
  delay(1500);
  Serial.println("Attempting Yalgaar connection...");
  //Connect to Yalgaar
  ret = yalgaarclient.yalgaar_connect("YourClientKey","UUID", connection_Callback);
  if (SUCCESS != ret)
  {
    yalgaarclient.enum_to_message(ret, err_string);
    Serial.println(err_string);
  }
  if (ret == SUCCESS) {
    Serial.println("connected");
    ret = yalgaarclient.yalgaar_subscribe("YourChannel", subscribe_message_callback, presence_message_callback, error_message_callback);
    if (SUCCESS != ret)
    {
      yalgaarclient.enum_to_message(ret, err_string);
      Serial.println(err_string);
    }
  }
}
void loop() {
  // Once connected, publish an announcement...
  if (yalgaarclient.is_connected())
  {
    if (pub_count)
    {
      delay(2000);
      ret = yalgaarclient.yalgaar_publish("YourChannel","This is Yalgaar Arduino SDK Example");
      if (SUCCESS != ret)
      {
        yalgaarclient.enum_to_message(ret, err_string);
        Serial.println(err_string);
      }
      pub_count--;
    }
  }
  yalgaarclient.yalgaar_loop();
}