int pubnub_send(char *p_data)
{
	enum pubnub_res l_response;
	char const *l_responseChannel = "parkingdevice-resp";
	struct Pubnub_UUID uuid;
	struct Pubnub_UUID_String str_uuid;
	pubnub_t *l_publish = pubnub_alloc();
	if (NULL == l_publish) 
	{
		printf("Failed to allocate Pubnub context!\n");
		return -1;
	}
	pubnub_init(l_publish, pub_key, sub_key);

	if (0 != pubnub_generate_uuid_v4_random(&uuid)) 
	{
		pubnub_set_uuid(l_publish, "zeka-peka-iz-jendeka");
	}
	else 
	{
		str_uuid = pubnub_uuid_to_string(&uuid);
		pubnub_set_uuid(l_publish, str_uuid.uuid);
		printf("Generated UUID: %s\n", str_uuid.uuid);
	}

	pubnub_set_auth(l_publish, "danaske");
	puts("Publishing...");
	l_response = pubnub_publish(l_publish, l_responseChannel, p_data);
	if(l_response != PNR_STARTED) 
	{
		printf("pubnub_publish() returned unexpected: %d\n", l_response);
		pubnub_free(l_publish);
		return -1;
	}
	l_response = pubnub_await(l_publish);
	if (l_response == PNR_STARTED) 
	{
		printf("pubnub_await() returned unexpected: PNR_STARTED(%d)\n", l_response);
		pubnub_free(l_publish);
		return -1;
	}
	if (PNR_OK == l_response) {
	printf("Published! Response from Pubnub: %s\n", pubnub_last_publish_result(l_publish));
	return 0;
	}
	else if (PNR_PUBLISH_FAILED == l_response) {
	printf("Published failed on Pubnub, description: %s\n", pubnub_last_publish_result(l_publish));
	}
	else {
	printf("Publishing failed with code: %d\n", l_response);
	}
	pubnub_free(l_publish);
	return 0;
}
Ejemplo n.º 2
0
static void generate_uuid(pubnub_t *pbp)
{
    char const *uuid_default = "zeka-peka-iz-jendeka";
    struct Pubnub_UUID uuid;
    static struct Pubnub_UUID_String str_uuid;

    if (0 != pubnub_generate_uuid_v4_random(&uuid)) {
        pubnub_set_uuid(pbp, uuid_default);
    }
    else {
        str_uuid = pubnub_uuid_to_string(&uuid);
        pubnub_set_uuid(pbp, str_uuid.uuid);
        printf("Generated UUID: %s\n", str_uuid.uuid);
    }
}