yalgaar Ruby SDK for real-time messaging
Dependencies: EthernetInterface mbed-rtos mbed Yalgaar
Diff: main.cpp
- Revision:
- 2:6ffd515f6e9e
- Parent:
- 0:c13577b7577e
diff -r 9602cba80990 -r 6ffd515f6e9e main.cpp --- a/main.cpp Tue Mar 14 05:49:41 2017 +0000 +++ b/main.cpp Tue Mar 14 11:19:01 2017 +0000 @@ -3,17 +3,13 @@ Serial pc(USBTX, USBRX,115200); -DigitalOut redLED(LED_RED); -DigitalOut greenLED(LED_GREEN); -DigitalOut blueLED(LED_BLUE); - EthernetInterface eth; -yalgaar yalgaar_client((char *)YALGAAR_HOST,(int)YALGAAR_PORT); +yalgaar yalgaar_client; Yalgaar_Error_t ret = FAILURE; char err_string[YALGAAR_ERROR_MESSAGE_LENGTH] = {'\0'}; -int pub_count = 2; +int pub_count = 10; void subscribe_message_callback(char *payload) { @@ -34,9 +30,6 @@ if(yalgaar_client.yalgaar_connected()) { pc.printf("connection callback :: %s\r\n",error_dec); - greenLED = !greenLED; - wait(1.0f); - greenLED = !greenLED; } else { @@ -57,34 +50,22 @@ pc.printf("IP Address is %s\r\n", eth.getIPAddress()); - ret = yalgaar_client.yalgaar_connect("YourClientKey","uuid", connection_Callback); + ret = yalgaar_client.yalgaar_connect("YourClientKey","UUID", connection_Callback); if (SUCCESS != ret) { - redLED = !redLED; - wait(1.0f); - redLED = !redLED; yalgaar_client.enum_to_message(ret, err_string); pc.printf("Connection fail %s \r\n",err_string); } if (ret == SUCCESS) { - pc.printf("connected to yalgaar\r\n"); - greenLED = !greenLED; - wait(1.0f); - greenLED = !greenLED; - - + 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 fail %s \r\n",err_string); + pc.printf("subscribe failure %s \r\n",err_string); } } else { - redLED = !redLED; - wait(1.0f); - redLED = !redLED; pc.printf(" try again in 5 seconds\r\n"); // Wait 5 seconds before retrying wait(5.0f); @@ -96,13 +77,12 @@ if (yalgaar_client.yalgaar_connected()) { if (pub_count) { wait(5.0f); - ret = yalgaar_client.yalgaar_publish("YourChannel", "This is Yalgaar mBed SDK Example"); + 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 fail %s \r\n",err_string); + pc.printf("publish failure %s \r\n",err_string); } pub_count--; - greenLED = !greenLED; } } yalgaar_client.yalgaar_loop();