libcurl examples

Home Forums MultiConnect OCG libcurl examples

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #5577
    Greg Ludewig
    Participant

    I’m trying to write a C application that uses libcurl to submit HTTP POST, PUT, and GET requests, and I was wondering if there are any examples available of how to use libcurl in the CoreCDP environment. The requests I want to send are fairly complex, and I’m having trouble figuring out how to use the various libcurl functions to generate the requests I want.

    I can generate a curl string and submit it via the system() call, and my requests work, but there doesn’t seem to be a way to capture the curl output (such as the HTTP response code) in that case. It looks like using libcurl will allow me to capture the response code, but as I said, I’m having trouble understanding how to generate the proper request. Are there any examples avaiable of how to use libcurl, or of how to capture the output if I submit a curl command directly using the system() call.

    Below is an example of a curl request I need to generate and submit:

    curl -X POST -v -H Content-Type:application/json -d ‘{“id”:{“mn”: “ammptest”,”sn”: “ammptestvunder3″},”pingRate”: 15}’ $’http://minnetronix-sandbox-connect.axeda.com/ammp/assets/1′

    #5588
    Darrik Spaude
    Keymaster

    Hi Greg,

    There were 4 topic submissions that were flagged as spam. Do you want the content of this one modified since it is a public forum?

    #5590
    Greg Ludewig
    Participant

    Darrik,

    Thanks for the response. I’m not sure why they were flagged as spam, but I submitted the same post multiple times because it never seemed to show up on the list of forum topics after I submitted it. I’m OK with this post as is, if someone could help me with some libcurl examples, that would be great.

    Greg

    #5593
    Bryan Tran
    Moderator

    Hi Greg,

    To capture the output of a curl command directly using the system() call, you could try this: curl -vs google.com > myfile 2>&1

    This will redirect the output/error of the curl command to: myfile.

    Notes: Should be written into a directory one of the mounted tmpfs (in RAM) filesystems or to a removable SD card.

    Thanks,

    BT

    #5597
    Greg Ludewig
    Participant

    Thanks Bryan, that seems to do the trick.

    I do have a couple of questions, though.

    1) Why do I need to write the output to the RAM filesystem or the SD card? It seems to work OK if I use the main filesystem.
    2) I can’t find any documentation on how to access/use the RAM filesystem. Is it simply the filesystem at /mnt/ram (which appears to be linked to /media/ram)?

    Thanks again.

    Greg

    #5598
    Bryan Tran
    Moderator

    Hi Greg,

    1. If your application is not write to the flash on a regular basis, then it is ok to write to main file system. However, if it is writing on regular basis, then it should be in RAM file system. This is so that you don’t wear out the flash.

    2. It is simply the file system at /media/ram. You can just create file in that folder.

    Notes: If the device is reset, then all the files that you created there will be lost.

    Regards,

    BT

    #5610
    Greg Ludewig
    Participant

    Bryan,

    Thanks, that makes sense. I will use the RAM file system. That brings up another question for me, though. What about the system log file (/var/log/messages)? Is it in flash, so that I should avoid writing to the log on a regular basis?

    Greg

    #5611
    Jesse Gilles
    Blocked

    Greg,

    There are multiple RAM-based filesystems on the unit by default. If you run ‘mount’ you can look for filesystems of type ‘tmpfs’.

    You will find that /var/volatile is also a tmpfs and if you run ‘ls -l’ in /var, you will see that /var/log is a soft link to /var/volatile/log. So /var/log is actually in the tmpfs and therefore in RAM.

    Jesse

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.