Community
cancel
Showing results for 
Search instead for 
Did you mean: 
VGopa2
New Contributor I
2,259 Views

Libcurl not working after firmware upgrade

Jump to solution

Hi Intel,

We were using libcurl in C Edison (3.10.17-poky-edison+) and it was working fine. Recently we had done a firmware upgrade in Edison and it doesnt work any longer. We use the following example code for development: https://curl.haxx.se/libcurl/c/multi-post.html https://curl.haxx.se/libcurl/c/multi-post.html

We are doing http post to a cloud server. But some of the fields of this form are junk characters. Please help us to resolve this issue.

regards,

Vinu

0 Kudos
1 Solution
idata
Community Manager
163 Views

Hi Vinu,

 

 

We have updated libcurl5 version to 7.52.1 in the IoTDK 3.5 repository ( http://iotdk.intel.com/repos/3.5/iotdk/edison/core2-32/), so please try to re-install it again a let us know if it works for you.

 

 

Make sure the iotkit.conf points to the latest repository and run the following commands:

 

 

opkg update opkg install curl --force-reinstall

 

 

Have a nice day

 

 

Regards,

 

-Leonardo

View solution in original post

17 Replies
idata
Community Manager
163 Views

Hi Vinu,

 

 

Thanks for reaching out.

 

 

I tried to run the code in the link that you shared us, but I got some errors running it. Can you provide us the steps that you are following to try to replicate the issue?

 

 

We will be waiting for your reply to help you more.

 

 

Regards,

 

-Leonardo
VGopa2
New Contributor I
163 Views

Hi Leonardo,

Thanks for the reply. I am posting the code to be run in both the images. (3.10.17-poky-edison+ , 3.10.98-poky-edison+ ). I have given a Http post function (given below) which would post some fields to the request bin url. You can make use of https://requestb.in/ https://requestb.in/ to inspect the results.

Firstly set up request bin Url:

1. Open https://requestb.in/ https://requestb.in/ and click on Create Request Bin

2. Copy the url given in the box.

3. Replace the existing url with the new one. (Please see the function given below. Replace the bold url with your's)

4. Before running the code please create a file named as postit2.c in Edison.

5. Compile and run the code.

6. Now open the url in your browser and compare the result.

7. You will see junk characters in the request from new image.

Please ask if you have any clarifications on these. Thanks

Given below is the Http post function to be used:

/*This is a test code for http post using libcurl.

Example code taken from libcurl library*/

int simpleFormPost() {

CURL *curl;

CURLM *multi_handle;

int still_running;

struct curl_httppost *formpost=NULL;

struct curl_httppost *lastptr=NULL;

struct curl_slist *headerlist=NULL;

static const char buf[] = "Expect:";

/* Fill in the file upload field. This makes libcurl load data from

the given file name when curl_easy_perform() is called. */

curl_formadd(&formpost,

&lastptr,

CURLFORM_COPYNAME, "sendfile",

CURLFORM_FILE, "postit2.c",

CURLFORM_END);

/* Fill in the filename field */

curl_formadd(&formpost,

&lastptr,

CURLFORM_COPYNAME, "filename",

CURLFORM_COPYCONTENTS, "postit2.c",

CURLFORM_END);

/* Fill in the submit field too, even if this is rarely needed */

curl_formadd(&formpost,

&lastptr,

CURLFORM_COPYNAME, "submit",

CURLFORM_COPYCONTENTS, "send",

CURLFORM_END);

curl = curl_easy_init();

multi_handle = curl_multi_init();

/* initialize custom header list (stating that Expect: 100-continue is not

wanted */

headerlist = curl_slist_append(headerlist, buf);

if(curl && multi_handle) {

/* what URL that receives this POST */

curl_easy_setopt(curl, CURLOPT_URL, "http://requestb.in/17bw0zy1 http://requestb.in/17bw0zy1"); //COPY YOUR GENERATED URL HERE

curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);

curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);

curl_multi_add_handle(multi_handle, curl);

curl_multi_perform(multi_handle, &still_running);

do {

struct timeval timeout;

int rc; /* select() return code */

CURLMcode mc; /* curl_multi_fdset() return code */

fd_set fdread;

fd_set fdwrite;

fd_set fdexcep;

int maxfd = -1;

long curl_timeo = -1;

FD_ZERO(&fdread);

FD_ZERO(&fdwrite);

FD_ZERO(&fdexcep);

/* set a suitable timeout to play around with */

timeout.tv_sec = 1;

timeout.tv_usec = 0;

curl_multi_timeout(multi_handle, &curl_timeo);

if(curl_timeo >= 0) {

timeout.tv_sec = curl_timeo / 1000;

if(timeout.tv_sec > 1)

timeout.tv_sec = 1;

else

timeout.tv_usec = (curl_timeo % 1000) * 1000;

}

/* get file descriptors from the transfers */

mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);

if(mc != CURLM_OK) {

fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);

break;

}

/* On success the value of maxfd is guaranteed to be >= -1. We call

select(maxfd + 1, ...); specially in case of (maxfd == -1) there are

no fds ready yet so we call select(0, ...) --or Sleep() on Windows--

to sleep 100ms, which is the minimum suggested value in the

curl_multi_fdset() doc. */

if(maxfd == -1) {

# ifdef _WIN32

Sleep(100);

rc = 0;

# else

/* Portable sleep for platforms other than Windows. */

struct timeval wait = { 0, 100 * 1000 }; /* 100ms */

rc = select(0, NULL, NULL, NULL, &wait);

# endif

}

else {

/* Note that on some platforms 'timeout' may be modified by select().

If you need access to the original value save a copy beforehand. */

rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);

}

switch(rc) {

case -1:

/* select error */

break;

case 0:

default:

/* timeout or readable/writable sockets */

printf("perform!\n");

curl_multi_perform(multi_handle, &still_running);

printf("running: %d!\n", still_running);

break;

}

} while(still_running);

curl_multi_cleanup(multi_handle);

/* always cleanup */

curl_easy_cleanup(curl);

/* then cleanup the formpost chain */

curl_formfree(formpost);

/* free slist */

curl_slist_free_all(headerlist);

return 1;

}

}

idata
Community Manager
163 Views

Hi Vinu,

That's weird, can you send me a screenshot of the junk characters?

I followed the steps that you gave me, but I didn't have errors, check this photo:

I will be awaiting for your reply to help you more.

Regards,

 

-Leonardo
ss23
Beginner
163 Views

Hi Leonardo,

I work with Vinu.

Are you running this on an Edison with the latest firmware? We got the error after upgrading Edison firmware, before that it worked perfectly.

Thanks

Shafy

VGopa2
New Contributor I
163 Views

Hi Leonardo,

Can you post the remaining form-data fields that are received in request bin? As you mentioned, the data contained in the file (leo.c in your case) will be shown correctly. But the remaining fields are junk. I am attaching my results below. The junk values are highlighted.

Thanks,

Vinu

VGopa2
New Contributor I
163 Views

Hi Leonardo,

If you still cannot replicate this issue, please try running the following code on Edison. This code the same as the previous, but i have added it so that we dont miss anything. As mentioned above, you may have to generate new URL and create a test file named postit2.c. Write any dummy text into that file as well. You can also find my results screenshot attached below.

/*This is a test code for http post using libcurl.

Example code taken from libcurl library*/

/***************************************************************************

* _ _ ____ _

* Project ___| | | | _ \| |

* / __| | | | |_) | |

* | (__| |_| | _ <| |___

* \___|\___/|_| \_\_____|

*

* Copyright (C) 1998 - 2016, Daniel Stenberg, <</span>mailto:daniel@haxx.se daniel@haxx.se>, et al.

*

* This software is licensed as described in the file COPYING, which

* you should have received as part of this distribution. The terms

* are also available at https://curl.haxx.se/docs/copyright.html.

*

* You may opt to use, copy, modify, merge, publish, distribute and/or sell

* copies of the Software, and permit persons to whom the Software is

* furnished to do so, under the terms of the COPYING file.

*

* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY

* KIND, either express or implied.

*

***************************************************************************/

/*

* using the multi interface to do a multipart formpost without blocking

*

*/

# include

# include

# include

# include

void main(){

CURL *curl;

CURLM *multi_handle;

int still_running;

struct curl_httppost *formpost=NULL;

struct curl_httppost *lastptr=NULL;

struct curl_slist *headerlist=NULL;

static const char buf[] = "Expect:";

/* Fill in the file upload field. This makes libcurl load data from

the given file name when curl_easy_perform() is called. */

curl_formadd(&formpost,

&lastptr,

CURLFORM_COPYNAME, "sendfile",

CURLFORM_FILE, "postit2.c",

CURLFORM_END);

/* Fill in the filename field */

curl_formadd(&formpost,

&lastptr,

CURLFORM_COPYNAME, "filename",

CURLFORM_COPYCONTENTS, "postit2.c",

CURLFORM_END);

/* Fill in the submit field too, even if this is rarely needed */

curl_formadd(&formpost,

&lastptr,

CURLFORM_COPYNAME, "submit",

CURLFORM_COPYCONTENTS, "send",

CURLFORM_END);

curl = curl_easy_init();

multi_handle = curl_multi_init();

/* initialize custom header list (stating that Expect: 100-continue is not

wanted */

headerlist = curl_slist_append(headerlist, buf);

if(curl && multi_handle) {

/* what URL that receives this POST */

curl_easy_setopt(curl, CURLOPT_URL, " http://requestb.in/1o0t31e1"); //COPY YOUR GENERATED URL HERE

curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);

curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);

curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);

curl_multi_add_handle(multi_handle, curl);

curl_multi_perform(multi_handle, &still_running);

do {

struct timeval timeout;

int rc; /* select() return code */

CURLMcode mc; /* curl_multi_fdset() return code */

fd_set fdread;

fd_set fdwrite;

fd_set fdexcep;

int maxfd = -1;

long curl_timeo = -1;

FD_ZERO(&fdread);

FD_ZERO(&fdwrite);

FD_ZERO(&fdexcep);

/* set a suitable timeout to play around with */

timeout.tv_sec = 1;

timeout.tv_usec = 0;

curl_multi_timeout(multi_handle, &curl_timeo);

if(curl_timeo >= 0) {

timeout.tv_sec = curl_timeo / 1000;

if(timeout.tv_sec > 1)

timeout.tv_sec = 1;

else

timeout.tv_usec = (curl_timeo % 1000) * 1000;

}

/* get file descriptors from the transfers */

mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);

if(mc != CURLM_OK) {

fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc);

break;

}

/* On success the value of maxfd is guaranteed to be >= -1. We call

select(maxfd + 1, ...); specially in case of (maxfd == -1) there are

no fds ready yet so we call select(0, ...) --or Sleep() on Windows--

to sleep 100ms, which is the minimum suggested value in the

curl_multi_fdset() doc. */

if(maxfd == -1) {

# ifdef _WIN32

Sleep(100);

rc = 0;

# else

/* Portable sleep for platforms other than Windows. */

struct timeval wait = { 0, 100 * 1000 }; /* 100ms */

rc = select(0, NULL, NULL, NULL, &wait);

# endif

}

else {

/* Note that on some platforms 'timeout' may be modified by select().

If you need access to the original value save a copy beforehand. */

rc = select(maxfd+1, &fdread, &fdwrite, &fdexcep, &timeout);

}

switch(rc) {

case -1:

/* select error */

break;

case 0:

default:

/* timeout or readable/writable sockets */

printf("perform!\n");

curl_multi_perform(multi_handle, &still_running);

printf("...

idata
Community Manager
163 Views

Hi Vinu,

 

 

Thank you so much for the explanation, I have the same junk characters too.

 

 

That's weird, personally I recommend you to use the image 3.10.17-poky-edison+ as workaround. Now, let me investigate more about this issue in the latest image and I'll let you know when I have updates.

 

 

Have a nice day.

 

 

Regards,

 

-Leonardo
VGopa2
New Contributor I
163 Views

Hi Leonardo,

Thanks for the reply. The main reason behind going for the latest image was that we really needed the sleep mode of Edison to work. As you know, there was a sleep mode bug in the old version. When sleep mode got working, curl failed. This is very unfortunate. Please continue to investigate and let me know if you have any success.

regards,

Vinu

idata
Community Manager
163 Views

Hi Vinu,

 

 

Thanks for letting us know. We are investigating about this, I'll reply here when we got something.

 

 

Have a nice weekend.

 

 

Regards,

 

-Leonardo
VGopa2
New Contributor I
163 Views

Hi Leonardo,

Any updates on the issue?

thanks,

Vinu

idata
Community Manager
163 Views

Hi Vinu,

 

 

We are still working on this case. I will let you know when we have updates.

 

 

I appreciate your patience.

 

 

Have a nice day.

 

 

Regards,

 

-Leonardo
VGopa2
New Contributor I
163 Views

Hi Leonardo,

Any updates? We are stil waiting for your response.

Thanks,

Vinu

idata
Community Manager
164 Views

Hi Vinu,

 

 

We have updated libcurl5 version to 7.52.1 in the IoTDK 3.5 repository ( http://iotdk.intel.com/repos/3.5/iotdk/edison/core2-32/), so please try to re-install it again a let us know if it works for you.

 

 

Make sure the iotkit.conf points to the latest repository and run the following commands:

 

 

opkg update opkg install curl --force-reinstall

 

 

Have a nice day

 

 

Regards,

 

-Leonardo

View solution in original post

VGopa2
New Contributor I
163 Views

Thanks Leonardo. I will try that out and update you soon.

idata
Community Manager
163 Views

Hi Vinu,

 

 

Great! We will be awaiting for your response.

 

 

Regards,

 

-Leonardo
VGopa2
New Contributor I
163 Views

Hi Leonardo,

It is working now! So, the old libcurl was having issues in the new image. But i had to manually link the new curl to GCC.

 

Thanks for the support.

regards,

Vinu

idata
Community Manager
163 Views

Hi Vinu,

 

 

That's awesome! Thank you for letting us know.

 

 

Don't doubt to ask us when you have issues.

 

 

Have a nice day.

 

 

Regards,

 

-Leonardo
Reply