void test_subunsub_thng(CuTest* tc) { PRINT_START_MEM_STATS evrythng_handle_t h1; common_tcp_init_handle(&h1); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngConnect(h1)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubThngAction(h1, THNG_1, ACTION_1, 0, test_sub_callback)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubThngAction(h1, THNG_1, ACTION_2, 0, test_sub_callback)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngUnsubThngAction(h1, THNG_1, ACTION_2)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubThngProperty(h1, THNG_1, PROPERTY_1, 0, test_sub_callback)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngUnsubThngProperty(h1, THNG_1, PROPERTY_1)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubThngProperty(h1, THNG_1, PROPERTY_1, 0, test_sub_callback)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubThngProperty(h1, THNG_1, PROPERTY_2, 0, test_sub_callback)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngUnsubThngProperty(h1, THNG_1, PROPERTY_1)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubThngProperties(h1, THNG_1, 0, test_sub_callback)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngUnsubThngProperties(h1, THNG_1)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubThngActions(h1, THNG_1, 0, test_sub_callback)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngUnsubThngActions(h1, THNG_1)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubThngLocation(h1, THNG_1, 0, test_sub_callback)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngUnsubThngLocation(h1, THNG_1)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngDisconnect(h1)); EvrythngDestroyHandle(h1); PRINT_END_MEM_STATS }
void test_sub_diffpubstate(CuTest* tc) { PRINT_START_MEM_STATS evrythng_handle_t h1; common_tcp_init_handle(&h1); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngConnect(h1)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubThngProperty(h1, THNG_1, PROPERTY_1, 0, test_sub_callback)); CuAssertIntEquals(tc, EVRYTHNG_ALREADY_SUBSCRIBED, EvrythngSubThngProperty(h1, THNG_1, PROPERTY_1, 1, test_sub_callback)); EvrythngDisconnect(h1); EvrythngDestroyHandle(h1); PRINT_END_MEM_STATS }
void test_pubsub_thng_prop(CuTest* tc) { START_SINGLE_CONNECTION CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngSubThngProperty(h1, THNG_1, PROPERTY_1, 0, test_sub_callback)); CuAssertIntEquals(tc, EVRYTHNG_SUCCESS, EvrythngPubThngProperty(h1, THNG_1, PROPERTY_1, PROPERTY_VALUE_JSON)); END_SINGLE_CONNECTION }
static void evrythng_task(void* pvParameters) { cmd_opts* opts = (cmd_opts*)pvParameters; EvrythngInitHandle(&opts->evt_handle); EvrythngSetLogCallback(opts->evt_handle, log_callback); EvrythngSetConnectionCallbacks(opts->evt_handle, conlost_callback, conrestored_callback); EvrythngSetUrl(opts->evt_handle, opts->url); EvrythngSetKey(opts->evt_handle, opts->key); EvrythngSetThreadPriority(opts->evt_handle, 5); log("Connecting to %s", opts->url); while(EvrythngConnect(opts->evt_handle) != EVRYTHNG_SUCCESS) { log("Retrying"); platform_sleep(2000); } log("Evrythng client Connected"); if (opts->sub) { log("Subscribing to property %s", opts->prop); EvrythngSubThngProperty(opts->evt_handle, opts->thng, opts->prop, 1, print_property_callback); while (!stop) { platform_sleep(2000); } } else { while (!stop) { int value = rand() % 100; char msg[128]; sprintf(msg, "[{\"value\": %d}]", value); log("Publishing value %d to property %s", value, opts->prop); EvrythngPubThngProperty(opts->evt_handle, opts->thng, opts->prop, msg); platform_sleep(1000); } } EvrythngDisconnect(opts->evt_handle); EvrythngDestroyHandle(opts->evt_handle); vTaskEndScheduler(); }