Search code examples
chttpcurllibcurldata-extraction

Extract value of a dynamic data through http using cURL and C API


I'm trying to extract the RSSI value of a Wifi access point in my network. The only solution available is to connect it using its ip adress and try to read the value in its status page. During my research I found the cURL library and I write a some code to connect and extract the status page. But I only have the code of the page and not the value that I need to get.

So, I need your help to find the right way to extract the value of the data.

My configuration: Linux Ubuntu for now, but SW will be used in a raspberry like interface, Eclipse CDT.

The code that I writed:

CURL *curl;
CURLcode res;

curl = curl_easy_init();
if (curl)
{
    curl_easy_setopt(curl, CURLOPT_USERPWD, "admin:password");
    curl_easy_setopt(curl, CURLOPT_URL, "http://192.168.5.179");
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);

    res = curl_easy_perform(curl);
    /* Check for errors */
    if(res != CURLE_OK)
      fprintf(stderr, "curl_easy_perform() failed: %s\n",
              curl_easy_strerror(res));

    /* always cleanup */
    curl_easy_cleanup(curl);

}

The data that I need to read (wlan1_signal):

Signal Strength:</td>

                                            <td >

                                                <div class="style2">

                                                    &nbsp;<span id="wlan1_signal">None</span>&nbsp;</div>

                                            </td>

Thanks for your help.

EDIT: On the html code of the page, I found that a script is executed to generate the dynamics values:

<script language="javascript" src="js/status.js" type="text/javascript"></script>

In this script (http://192.168.5.179/en/js/status.js), I found the code line that generate the RSSI value:

remote_call("get_wifi_info", wlan_devs[index].cdev, 
                function(data){ ...
$("#wlan"+index+"_signal").html(get_regex(data, /Link Quality=(\S+)/));
...

But my issue remain the same: how to read the value generated??


Solution

  • If you only need to retrieve the value, regardless of performance, you could use a bash command.

    curl -s -u admin:password "http://192.168.5.179" | grep -Po '(?<=<span id="wlan1_signal">)[^<]+'