Languages

Menu
Sites
Language
gear : curl proxy possible with bluetooth to phone ?
Hi, I'm using curl to get json api from internet, but when wifi is not connected, curl is not working, (while connected to phone that CONNECTED to internet) I read there's proxy that has to be configured, but another answer must use SAP, and in the SAP documentation there's no internet connection Oh, and there's another answer that we have to create android app to send internet data to gear So, what is the solution exactly ? Thanks

Responses

9 Replies
Shaswati Saha

Both of the options will work in this case. You may try anyone of these. Previously I also didn't know that CURL requests can be made using the internet connection of mobile device ( even though Gear device isn't connected to wifi ). But I've recently tested the thing that it can be done using proxy address. So according to my understanding, both of the ways are ok. In case of using proxy address just add the lines of code below to get the proxy address before calling curl_easy_perform() function.

char *proxy_address;
int conn_err;
conn_err = connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address);
curl_easy_setopt(curl, CURLOPT_PROXY, proxy_address);

For more details you may go through this link.

Hope it'll be helpful for you.

Tizen is me
Hi, thanks for answering Do you have sample code that you tried works with bluetooth without wifi ? I asked this because I already tried using the proxy like you described but its not working here's my approximate code : curl_global_init(CURL_GLOBAL_DEFAULT); // buffer = (char *) malloc (sizeof(char)*100000); progressbuffer = (char*) malloc(100000); curl = curl_easy_init(); char *proxy_address; // using proxy conn_err = connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address); if (conn_err == CONNECTION_ERROR_NONE && proxy_address) curl_easy_setopt(curl, CURLOPT_PROXY, proxy_address); // proxy changed callback conn_err = connection_set_proxy_address_changed_cb(connection, __proxy_address_changed_cb, NULL); if (conn_err != CONNECTION_ERROR_NONE) { /* Error handling */ return; } conn_err = connection_create(&connection); if (conn_err != CONNECTION_ERROR_NONE) { /* Error handling */ return; } then after that just regular curl get data (works with wifi, but after I disconnect the wifi, it just cannot work even the proxy changed callback is never called)
Shaswati Saha

My code is almost same as your's but I didn't call the proxy changed callback. Have a look into the code snippet below if it can come to help.

connection_h connection;

int conn_err;
conn_err = connection_create(&connection);
char *proxy_address;
conn_err = connection_get_proxy(connection, CONNECTION_ADDRESS_FAMILY_IPV4, &proxy_address);

CURL *curl;
CURLcode curl_err;
curl = curl_easy_init();

if (conn_err == CONNECTION_ERROR_NONE && proxy_address)
	curl_easy_setopt(curl, CURLOPT_PROXY, proxy_address);

curl_easy_setopt(curl, CURLOPT_URL, "URL_PROVIDING_JSON_DATA");

curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk);
curl_err = curl_easy_perform(curl);
curl_easy_cleanup(curl);
connection_destroy(connection);

And I've written the WriteMemoryCallback as below:

static size_t
WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
    size_t realsize = size * nmemb;
	struct MemoryStruct *mem = (struct MemoryStruct *)userp;

	mem->memory = realloc(mem->memory, mem->size + realsize + 1);
	if(mem->memory == NULL) {
		return 0;
	}

	memcpy(&(mem->memory[mem->size]), contents, realsize);
	mem->size += realsize;
	mem->memory[mem->size] = 0;

	return realsize;
}

Note: Please don't forget to add the privileges below:

<privilege>http://tizen.org/privilege/network.get</privilege>
<privilege>http://tizen.org/privilege/network.set</privilege>
<privilege>http://tizen.org/privilege/internet</privilege>
<privilege>http://tizen.org/privilege/network.profile</privilege>

 

Tizen is me

Thanks, I'll try again

Tizen is me

Hi, I tried your code and it works, and after some digging, I found out that if using proxy, it will connect ONLY

via BT, and if not using proxy it will connect ONLY via wifi. So with proxy, if I connect to wifi AND bt and my phone is

not connected to network, it fails to connect, is there any seamless solution for this ?

 

Thanks

Shaswati Saha

In that case, would you please try to unset the proxy settings if connection type changes to wifi?

Tizen is me

Hi, I think that wont work since, I'm both using wifi and BT in my gear, maybe for next tizen version it can automatically

route the connection ? Will we get tizen 4.0 BTW ?

Shaswati Saha

According to this link, we may get Tizen 4.0 around the middle of this year!

Tizen is me

Cant wait for it ! Thanks