AJAX framework

AJAX framework



Introduction to the AJAX framework


The Meshlium Manager System AJAX framework is designed to provide a easy way to power Meshlium Manager System plugins with AJAX content. In order to archieve this, some functions and features has been created.
The AJAX framework is not a mandatory addon. It is just an improvement that can be used, replaced or ignored by plugins.
To use the AJAX framework, you have to think in server and client sides. Client javascript, has to request actions from the plugin on the server side, and then plugin will serve the result of the actions to the client javascript.
This document will explain both client and server AJAX API.


Client Javascript.


Client side has two files that provides a basic layer to manage AJAX request.

AJAX calls


To make easiest the AJAX calls, a function named ajax_call is provided within the plugin skeleton. The function submits form data with an action tag so server side plugin can use data and performs actions.
The code of the function is:

function ajax_call(form_id,action,section,plugin,output_id)
{
    // This script will serialize the form indicated by an id and submit it
    // to the desired page.
    // Once the response has arrived it display the response inside the id
    // defined in output_id
    var json_field=json_encode(form_id);

    submit_data="section="+section+"&plugin="+plugin+"&action="+action+"&type=complex&"+"form_fields="+json_field;
    $.ajax({
        type: "POST",
        url: "index.php",
        data: submit_data,
        success: function(datos){
            // A JSON array is expected
            var ret = eval('(' + datos + ')');
            $.each(ret.item, function(i,item){
                if (item['type']=="script")
                {
                    eval(item['value']);
                }
                else if (item['type']=="return")
                {
                    $('#'+output_id).html(item['value']);
                }
                else if (item['type']=="html")
                {
                    $('#'+item['id']).html(item['value']);
                }
                else if (item['type']=="value")
                {
                    $('#'+item['id']).val(item['value']);
                }
                else if (item['type']=="append")
                {
                    $('#'+item['id']).append(item['value']);
                }
            });
        }
    });
}

This code is based on jquery that is default javascript framework for Meshlium Manager System, but can be modified for being use with prototype, mootools or your own ajax call.

File location: plugin_base_folder/javascript/ajax.js

JSON data management


Ajax call uses JSON to serialize data from a form and send it to the server. This is done to reduce the data send to the server and to make more easy the management of data on the server side.

To make more easy the work with JSON objects a function that serializes data has been provided. The funcion will search for data on a form and serialize it.
The code of the function is:

function json_encode(form_id)
{
    var fields = new Object();
    $("#"+form_id+" :input").each(function(){
        if($(this).attr("type")=="checkbox")
        {
            if(this.checked)
            {
                fields[$(this).attr("name")]=$(this).val();
            }
        }
        else if($(this).attr("type")=="radio")
        {
            if(this.checked)
            {
                fields[$(this).attr("name")]=$(this).val();
            }
        }
        else
        {
            if($(this).val()!='')
            {
                fields[$(this).attr("name")]=$(this).val();
            }
        }
    });
    return $.toJSON(fields);
}

File location: plugin_base_folder/javascript/json_encode.js


Server side AJAX framework.


AJAX return functions


Server side of a plugin receives data from client and after procesing data and performing actions data has to be sent to the client. To archieve this the Meshlium Manager System framework provides a response constructor that stores data that has to be sent to the client and finally send the data.

Each data stored, is a tuple that contains type, value and id and will be accesible by the client once submited.

$response_array=Array();
$response_iterator=0;
function response_additem($type,$value,$id="")
{
    global $response_array;
    global $response_iterator;
    $response_array['item'][$response_iterator]['type']=$type;
    $response_array['item'][$response_iterator]['value']=$value;
    if(!empty($id))
    {
        $response_array['item'][$response_iterator]['id']=$id;
    }
    $response_iterator++;
}
function response_return()
{
    global $response_array;
    echo json_encode($response_array);
}

File location: API/complex_ajax_return_functions.js

Server JSON manipulation


Server will receive the data in JSON format from the client. Function jsondecode decode the JSON submited by the client json_encode function and store it on a PHP array.

function jsondecode ($json) {
    $json = substr($json, strpos($json,'{')+1, strlen($json));
    $json = substr($json, 0, strrpos($json,'}'));
    $json =preg_replace('/(^|,)([\\s\\t]*)([^:]*) (([\\s\\t]*)):(([\\s\\t]*))/s','$1"$3"$4:', trim($json));
    $json=str_replace('\\"','"',$json);
    $json=str_replace('\\"','"',$json);
    return json_decode('{'.$json.'}', true);
}

File location: API/json_api.js

Input validation

Input validation



is_ip($ip)


This function check if the variable $ip contains a valid ip address.
The function will return true if $ip contains a valid ip address and false otherwise.

File location: API/common_validators.php

Example of use:

if(is_ip($ip))
{
    echo "IP address has been validated.";
}
else
{
    echo "IP address is not valid.";
}


is_url($url)


This function check if $url contains a valid url address.
The function will return true if $url contains a valid url adress and false otherwise.

File location: API/common_validators.php

Example of use:

if(is_url($url))
{
    echo "URL has been validated.";
}
else
{
    echo "URL is not valid.";
}


is_mac($mac)


This function check if $mac contains a valid mac address.
The function will return true if $mac contains a valid mac adress and false otherwise.

File location: API/common_validators.php

Example of use:

if(is_mac($mac))
{
    echo "MAC address has been validated.";
}
else
{
    echo "MAC address is not valid.";
}

Server side form validation


To automatically validate forms, the file API/form_field_validators.php provide a set of functions that could be easily extended.


are_form_fields_valid ($post_data, $fields_check_types,$fileds_ms_ctes=Array())


This function will perform check actions provided on $fields_check_types over the form data received on $post_data.
As an option an array with information about the name of the error divs can be provided on the $fields_ms_ctes array.
This function will return true if all form fields pass the declared checks, false otherwise.

File location:API/form_fields_check.php

Example of use:

$fields_check_types = Array (
          'username'  => Array ('ms_alnum','ms_mandatory'),
          'password' => Array ('ms_mandatory'),
          'cnf_password' => Array ('ms_mandatory')
        );
foreach (array_keys($fields_check_types) as $id)
{
    $fileds_ms_ctes[$id] = "error_field_$id";
}
return are_form_fields_valid ($post_data, $fields_check_types,$fields_ms_ctes);


is_filled ($field)


This function check if $field is not empty

File location:API/form_fields_check.php

Example of use:

if(is_filled($field))
{
    echo "Form field not empty.";
}
else
{
    echo "Form field empty.";
}


is_numerical ($data)


This function check if $data only have numbers. No other character allowed.

File location:API/form_fields_check.php

Example of use:

if(is_numerical($data))
{
    echo "Form field is composed by numbers.";
}
else
{
    echo "Form field has not valid characters.";
}


is_text ($data)


This function check if $data only contains letters

File location:API/form_fields_check.php

Example of use:

if(is_text($data))
{
    echo "Form field is composed by letters.";
}
else
{
    echo "Form field has not valid characters.";
}


is_alnum ($data)


This function check if $data is only contains numbers and letters

File location:API/form_fields_check.php

Example of use:

if(is_alnum($data))
{
    echo "Form field is alphanumerical.";
}
else
{
    echo "Form field is not alphanumerical.";
}


is_ip ($ip)


This function check if $ip is a valid ip address

File location:API/form_fields_check.php

Example of use:

if(is_ip($ip))
{
    echo "Form field is an ip address.";
}
else
{
    echo "Form field is not an ip address.";
}


is_a_float($data)


This function check if $data is a float in decimal format.
For example, 10.2 or -2.2 will return true, but 10E-2 will return false.

File location:API/form_fields_check.php

Example of use:

if(is_a_float($data))
{
    echo "Form field is a float.";
}
else
{
    echo "Form field is not a float.";
}


is_host ($host)


This function check if $host is a host.
A host can be a server name like www.libelium.com or an ip address, but not an url like http://www.libelium.com

File location:API/form_fields_check.php

Example of use:

if(is_host($host))
{
    echo "Form field is a host.";
}
else
{
    echo "Form field is not a host.";
}


is_mac ($mac)


This function check if $mac is a MAC address

File location:API/form_fields_check.php

Example of use:

if(is_mac($mac))
{
    echo "Form field is a MAC address.";
}
else
{
    echo "Form field is not a MAC address.";
}


is_subnet ($address)


This function check if $address is a ip address or a subnet.
Subnet should be in the format 192.168.1.0/24.

File location:API/form_fields_check.php

Example of use:

if(is_subnet($address))
{
    echo "Form field is valid.";
}
else
{
    echo "Form field is not valid.";
}


is_url ($url)


This function check if $url is an URL address

File location:API/form_fields_check.php

Example of use:

if(is_url($url))
{
    echo "Form field contains an URL.";
}
else
{
    echo "Form field do not contain a valid URL.";
}


is_email($email)


This function check if $email is an email address

File location:API/form_fields_check.php

Example of use:

if(is_email($email))
{
    echo "Form field is an email address.";
}
else
{
    echo "Form field is not an email address.";
}


is_hex($data)


This function check if $data is a hexadecimal value

File location:API/form_fields_check.php

Example of use:

if(is_hex($data))
{
    echo "Form field is hexadecimal.";
}
else
{
    echo "Form field is not hexadecimal.";
}


is_path($data)


This function check if $data is a path string. Note that only those characters are allowed:
Characters from 0 to 9, A to Z and a to z. And the symbols dot, underscore, minus, slash.

File location:API/form_fields_check.php

Example of use:

if(is_path($data))
{
    echo "Form field is an allowed path.";
}
else
{
    echo "Form field is not an allowed path.";
}

Configuration files framework

Configuration files framework



Introduction


The Meshlium Manager System provides an easy way to write and load configuration files from and to arrays.


load_conf_file ($filepath)


This function will load configuration file provide by $filepath to an array and return it.

File location: API/conf_file.php

Example of use:

$config_data=load_config_file('/etc/myplugin.conf');


save_conf_file ($filepath, $data, $writepath='')


This function saves the array $data to the file provided on $filepath.
This function uses a temporal file, the path for the temporal file can be defined too using $writepath. If no $writepath is provided the plugin will use $base_plugin.'data/temp_config' as default temporal file.

File location: API/conf_file.php

Example of use:

save_conf_file('/etc/myplugin.conf',$config_data);

Network interface manipulation

Network interface manipulation



is_active($interface)


This function check if an interface is active. This check is performed in real time when the function is called.
The function will return true if the interface is active and false otherwise.

File location: API/is_active.php

Example of use:

        if(is_active('ath0'))
        {
            echo "Interface ath0 is active";
        }
        else
        {
            echo "Interface ath0 is down";
        }
    


parse_interfaces ( $filepath )


This function implements a parser for meshlium /etc/network/interfaces file. Other systems may have alternates path so the path to interfaces file has to be passed to the function.
The function will return an array with all the interfaces configuration of the $filepath file.

File location: API/parser_interfaces.php

Example of use:

        $interfaces=parse_interfaces('/etc/network/interfaces');
        if($interfaces['eth0']['iface']=='dhcp')
        {
            echo "eth0 interface is using dhcp client to configurate.";
        }
        else
        {
            echo "eth0 interface address is ".$interfaces['eth0']['address'];
        }

    


saveInterfaces ($interface,$post,$read_path,$write_path)


This function save a new interface configuration to the interfaces configuration file.
$interface is the name of the interface that will be modified. $post should be an array with the configuration of the interface that will be saved. The variable $read_path should contain the file with the system interfaces configuration, the function will parse $read_path file and update this configuration with the values of $post for the $interface. The new configuration file will be saved on $write_path file.
Note that to $write_path should be writeable by apache
The function will return an array with all the interfaces configuration that has been written to $write_path.

File location: API/save_interfaces.php

Example of use:

        $post_data=jsondecode($_POST['form_fields']);
        saveInterfaces($_POST['interface'],$post_data,$base_plugin."data/interfaces",$base_plugin."data/interfaces");
    


write_interfaces ( $filepath,$input,$writepath='')


This low level function saves an parsed interfaces array to a configuration file.
$filepath should contain the path to the file where the interfaces configuration file will be stored.
$input should contain the interfaces array that will be saved. (Note that write_interfaces don't check for interaces defined on the system. write interfaces just look for interfaces on $input and save a configuration file with the interfaces it found.)
$writepath can be provided with an alternate path for temporal file. If $writepath is not defined write_interfaces will try to write on the folder data inside the plugin path.
Note that to $filepath and $writepath should be writeable by apache
The function will return an array with all the interfaces configuration of the $filepath file.

File location: API/write_interfaces.php

Example of use:

        $interfaces=parse_interfaces('/etc/network/interfaces');
        write_interfaces('/tmp/interfaces_copy',$interfaces);
    


make_wpa_files($hide,$pass,$mode,$ssid,$interface,$channel,$abg)


This low level function can save needed files to stablish a WPA connection. It can save hostapd.conf or wpa_supplicant.conf files. hostapd.conf is used by hostapd when meshlium is used as a AP with WPA, and wpa_supplicant.conf is needed when meshlium connects to an WPA ciphered network.
$hide sets if the network is hidden, $pass has the string with the WPA key, $mode can be setted to master when hostapd.conf should be saved or as managed when a wpa_supplicant.conf file has to be saved. $ssid has the ssid of the network, $interface the interface name that is going to be used, $channel has to store the network channel and finally $abg sets if wich protocol 11a, 11b or 11g is going to be used, $abg should contain 1 for 11b, 2 for 11g and 3 for 11a.
The function will return true. And files will be stored on /etc/wpa_supplicant.conf or /etc/hostapd/hostapd.conf in function of $mode value.

File location: API/write_wpa_files.php

Example of use:

        make_wpa_files('0','0123456789','master','MY_OWN','ath0','2','2');
    


add_mac_filter($mac,$interface,$type)


This function add a mac to the interface whitelist or blacklist. $mac should contain the MAC address, $interface the interface that will add the MAC and $type must contain value 1 for whitelist or value 2 for blacklist.
The function will return true.

File location: API/modify_mac_filter.php

Example of use:

        if(is_mac($_POST['mac']))
        {
            add_mac_filter($_POST['mac'],'ath0','2');
        }
    


del_mac_filter($mac,$interface,$type)


This function delete a mac from the interface whitelist or blacklist. $mac should contain the MAC address, $interface the interface that will add the MAC and $type must contain value 1 for whitelist or value 2 for blacklist.
The function will return true.

File location: API/modify_mac_filter.php

Example of use:

        if(is_mac($_POST['mac']))
        {
            del_mac_filter($_POST['mac'],'ath0','2');
        }
    


change_list_type($type,$interface)


This function changes the list type for an interface. $type should contain value 1 for whitelist or value 2 for blacklist. $inteface must have the interface name.
The function will return true.

File location: API/modify_mac_filter.php

Example of use:

        change_list_type('2','ath0');
    


modify_mac_filter($interface,$data,$action,$type,$readpath='',$writepath='')


This function can be called directly but is designed for being called from add_mac_filter, del_mac_filter or change_list_type. $interface should contain interface name, $data the MAC that is going to be modified or added, $action declares de action to perform, $action values can be 'change' or 'add'.
The function will return true.

File location: API/modify_mac_filter.php

Example of use:

        // This will perform the same action as the example for change_list_type;
        modify_mac_filter('ath0','','change','2');
    

Bluetooth interfaces manipulation

Bluetooth interfaces manipulation



hciconfig_parser()


This function parses in real time hciconfig output and generate an array with the information about the bluetooth interfaces and it's configuration. Data parsed is address, antenna name and antenna state.
The function will return an array with all the bluetooth interfaces state.

File location: API/parser_hciconfig.php

Example of use:

$hciconfig=hciconfig_parser();
echo "hci0 address is: ".$hciconfig[0]['address'];


parse_hcid($read_file='')


This function parses a hcid configuration file. A path to the hcid config file can be setted as an argument with $read_file variable. If $read_file variable is not provided or is empty, parse_hcid will check for data/hcid.conf file on the plugin folder.

The function will return an array with the configuration of the hcid file.

File location: API/parser_hcid.php

Example of use:

$hcid_conf=parse_hcid('/etc/bluetooth/hcid.conf');
if($hcid_conf['iscan']=='enable')
{
echo "Bluetooth iscan is enabled";
}


save_hcid($hci_config,$save_file='')


This function saves to a file the content of a configuration array passed in the variable $hci_config. The path to the file to save can be passed with the $save_file variable. If $save_file is empty or not setted the file will be saved on data/new_hcid.conf on the plugin folder.
Apache should be able to write on $save_file path or in the data folder within the plugin folder.

The does not have any return.

File location: API/save_hcid.php

Example of use:

$hcid_configuration=jsondecode($_POST['form_fields']);
save_hcid($hcid_configuration,$base_plugin.'data/hcid.conf');


hciconfig_parser()


This function returns an array with information parsed from the output of the hciconfig command.

File location: API/parser_hciconfig.php

Example of use:

$hciconfig=hciconfig_parser();

GPRS interface manipulation

GPRS interface manipulation



parse_wvdial ( $filepath )


This function parses wvdial configuration files. The path to the file to parse should be specified with $filepath variable.
The function will return an array with wvdial configuration.

File location: API/parser_wvdial.php

Example of use:

$data=parse_wvdial('/etc/wvdial.conf');


list_operators($readpath)


Libelium has merged information avaible on internet with the configuration parameters for different mobile companies in the world. list_operators loads on an array the avaible information needed to connect. The information about companies has been grouped by country, and contains operator name, APN, username, password and dns. Not all operators provide or need all the fields so some of them can be empty.
The function will return an array with the configuration of the operators file. The array will contain a list of the countries, the count of countries, and for each country a subarray with the count of operators, the name of the operators, and for each operator the apn, username, password and dns.

File location: API/list_operators.php

Example of use:
Just a call to the functions with the name of the file is needed.

$data=list_operators($base_plugin.'data/operators.txt');
echo '<pre>'.print_r($data,true).'</pre>';

This code will produce the following output (Note that .. means that some data has been cut for display performance):

Array
(
[list] => Australia//Austria//Belgium//Canada//..//Taiwan//Thailand//Turkey//UK//USA
[count] => 36
[Australia] => Array
(
[count] => 4
[list] => Optus//Telstra//Three//Vodafone
[Optus] => Array
(
[apn] => internet
[username] =>
[password] =>
[dns] => 202.139.83.3, 192.65.91.129
)

[Telstra] => Array
(
[apn] => telstra.internet
[username] =>
[password] =>
[dns] => 139.130.4.4, 203.50.170.2
)

..

)

[Austria] => Array
(
[count] => 6
[list] => Connect Austria//Max Online//Max Online Business//Max Online Metro//Mobilkom A1//Tele.Ring
[Connect Austria] => Array
(
[apn] => web.one.at
[username] => user specific
[password] => user specific
[dns] => 194.24.128.100, 194.24.128.102
)

[Max Online] => Array
(
[apn] => gprsinternet
[username] => GPRS
[password] =>
[dns] => 213.162.64.1, 213.162.64.2
)
..



function save_gprs($post,$write_path='')


This function saves a wvdial configuration file with the content of an array. The array fields can be
Apache should be able to write on $save_file path or in the data folder within the plugin folder.
This function does not have any return.

File location: API/save_gprs.php

Example of use:

$data=jsondecode($_POST['form_fields']);
save_gprs($data);

DHCP server manipulation

DHCP server manipulation



parse_dhcp_server()


This function parses dnsmasq configuration file and stores the configuration on an array.
The function will return an array with the dnsmasq configuration.

File location: API/parser_dhcp_server_new.php

Example of use:

    $entries=parse_dhcp_server('ath0');
if(isset($entries['ath0'])
{
echo "dhcp over ath0 is setted.";
}


update_dhcp($dhcp_configuration)


This function checks $dhcp_configuration array (usually provided by a html form) and stores data on an array that can be used with save_dhcp_server function.
The function will return an array with the dnsmasq configuration that can be understood by save_dhcp_server().
This is the fields that can be defined on $dhcp_configuration:

  •  dhcp_server_XXXX: Usually used interfaces are eth0, ath0 or ath1 but future supported interfaces can be added for DHCP server. If this field contains string 'on', the funtion will process the interface dhcp configuration fields.
  • dhcp_start_XXXX:  This field must contain a valid IP Address. This address will be the first value used by dhcp server for new dhcp request.
  • dhcp_end_XXXX: This field must contain a valid IP Address. This will be the last avaible address that dhcp server can assign to dhcp requests.
  • dhcp_expire_XXXX: This field must be a number. This is the number of hours that the dhcp lease will stand for.

File location: API/save_dhcp_server_new.php

Example of use:

$dhcp_configuration=update_dhcp($form_fields);
save_dhcp_server($dhcp_configuration);


save_dhcp_server($dhcp_configuration,$save_file='')


This function saves a dnsmasq configuration file with the values stored on $dhcp_configuration. A path for the file to write can be passed within $save_file variable. If no $save_file variable is passed or is empty $base_plugin.'data/dnmasq.more.conf' will be used as default.
The function will return an array with the dnsmasq configuration.

File location: API/save_dhcp_server_new.php

Example of use:

$dhcp_configuration=jsondecode($_POST['form_fields']);
save_dhcp_server($dhcp_configuration);

OLSRD manipulation

OLSRD manipulation



parse_olsrd ( $filepath )


This function parses olsrd configuration file. A path to the configuration file should be passed in the $filepath variable.
The function return an array containing all the configuration parameters parsed.

File location: API/parser_olsrd.php

Example of use:

    parse_olsrd('/etc/olsrd/olsrd.conf');


parse_olsrd_txt_info ($path)


This function parses olsrd text info provided by the plugin olsrd_txtinfo.so.0.1 A path to the file generated by the olsrd daemon should be passed in the $filepath variable.
The function return an array containing all the brothers ip parsed, the number of brothers, the topology and the number of the number of topology subarrays.

File location: API/parser_olsrd_txt_info.php

Example of use:

    <?php
        echo print_r(parse_olsrd_txt_info('olsrd.txt'),true);
    ?>

This is an example of the output

Array
(
    [brothers] => Array
        (
            [0] => 192.168.1.250
            [1] => 192.168.1.14
            [2] => 192.168.1.110
            [3] => 192.168.1.251
        )
    [num_brothers] => 4
    [num_top] => 2
    [top] => Array
        (
            [0] => Array
                (
                    [1] => 192.168.1.250
                    [2] => 192.168.1.14
                )
            [1] => Array
                (
                    [1] => 192.168.1.14
                    [2] => 192.168.1.250
                )
        )
)


save_olsrd($post,$write_path='',$read_path='')


This function will save data stored in $post (usually a html form) on the file declared on $write_path, aditionally a path to a olsd file can be provided with $read_path. If $write_path is empty or not declared $base_plugin.'data/new_olsd.conf' will be used as defalult value, if $read_path is empty or not declared /etc/olsrd/olsrd.conf will be used.
The function will call parse_olsr($read_path) and data provided by parse_olsr will be updated with data in $post and saved to $write_path.
This allows to have a subset of configure options avaible for users on an html form and a default skeleton. Skeleton will be completed with form values and write a new olsrd configuration file declared on $write_path.
The function has no return value.

File location: API/save_olsrd.php

Example of use:

    $post_data=jsondecode($_POST['form_fields']);
    save_olsrd($post_data,$base_plugin.'data/saved_data',$base_plugin.'data/read_data');

Fresnel configuration

Fresnel configuration



set_fresnel($interface,$distance)


The objetive of fresnel configuration is to set better configuration parameters for a given distance for wifi interfaces.
This function sets interface configuration to fit a given distance. Once setted the values will be saved on $base_plugin.'data/fresnel_'.$interface.'.conf' so configuration can be loaded each time the system restarts.
$interface specifies the interface that will be setted and $distance is the distance in kilometers that will be used for configuration parameters.
The function has no return.

File location: API/set_fresnel.php

Example of use:

set_fresnel('ath0','1.4');

Join networks configuration

Join networks configuration



save_join($join,$conf_file='',$rules_file='')


Meshlium provides several interfaces that can be joined to allow that networks on interface A can reach networks on interface B. Save_join function is used to write a file that will configure meshlium to allow those interface joins, and calls write_rule to save the new rule for manager system usage.
$join should be a vector where it's components are numered from 0 to 2, rules are defined on positions [0][1][2]. The rules should contain on first and last component the interfaces name, and in the second component the rule that can have values:

  • Right: first interface can reach second interface only.
  • Bidirectional: Both interfaces can reach eachother.
  • Left: second interface can reach first interface only.

The function has no return.

File location: API/save_join_new.php

Example of use:

$rule=array('eth0','Bidirectional','ath0');
save_join($rule);


write_rule($join,$base,$fp)


Write_join function is used to write a new rule to a configuration file that will be used by meshlium to allow those interface joins.
$join should be a vector where it's components are numered from 0 to 2, rules are defined on positions [0][1][2]. The rules should contain on first and last component the interfaces name, and in the second component the rule that can have values:

  • Right: first interface can reach second interface only.
  • Bidirectional: Both interfaces can reach eachother.
  • Left: second interface can reach first interface only.
$base can have a pointer to the first element on the $join vector. This is a feature that
can be used by advanced developers to minify the memory comsumption when they need to iterate on several
rules on one vector, by default should contain value 0. $fp should be the file descriptor of the file that will contain the rules.

The function has no return.

File location: API/save_join_new.php

Example of use:

$rule=array('eth0','Bidirectional','ath0');
$fp=fopen($base_plugin.'data/join','w');
write_rule($join,0,$fp);


delete_join_rule($rule_number,$conf_file='',$rules_file='')


delete_join_rule function will delete a rule from the configuration files on meshlium.
Function should be called with the possition of the rule to delete. A custom configuration file and custom rules file can be passed to function as optional arguments.

The function has no return.

File location: API/save_join_new.php

Example of use:

$rule=array('eth0','Bidirectional','ath0');
save_rule($join);
delete_join_rule(0);

System check

System check



parse_crypto ()


The function will return an array with the status of the ciphered partitions that can be on meshlium.

File location: API/parser_crypto.php

Example of use:

    echo print_r(parse_crypto(),true);


parse_hardware()


The function will return an array with information about hardware modules installed on meshlium.
This function can not recover information of modules connected over serial interface like zigbee.

File location: API/parser_hardware.php

Example of use:

    echo print_r(parse_hardware(),true);


parse_list_scan ( $interface )


The function will scan for wireless networks detected by a wifi interface.
The function will return an array with information about networks detected, the array contains the following information for each network:

  • id: Cell ID
  • mac: MAC of the AP.
  • essid: Essid of the network
  • mode: Network mode.
  • channel: Network channel.
  • quality: Quality of the link.
  • encr: Encription type of the network.

File location: API/parser_hardware.php

Example of use:

    $networks=parse_list_scan('ath0');
    foreach ($networks as $network)
    {
        echo "Channel ".$network['channel']." for network ".$network['essid'];
    }


proc_net_dev()


This function return information about the system interfaces parsed from /proc/net/dev.
The function will return an array with information of interfaces.

File location: API/parser_proc_net_dev.php

Example of use:

    echo print_r(proc_net_dev(),true);
    sleep(2);
    echo print_r(proc_net_dev(),true);

GPS manipulation

GPS manipulation



parse_NMEA($input)


This function parses some of the NMEA strings and stores it's data on a more usable array.
The NMEA strings that can be parsed and it's array components that will be output are:

  • $GPGGA
    • type: Message ID, GGA protocol header
    • utc: UTC time (hhmmss.sss)
    • lat: Latitude (ddmm.mmmm)
    • ns: North/South Indicator
    • lat-google: Latitude converted to a value that can be understanded by google maps (positive for north negative for south)
    • long: Longitude (dddmm.mmmm)
    • ew: East/West Indicator
    • long-google: Longitude converted to values that can be understanded by google maps (positive for east, negative for west)
    • gpsqual: Position Fix Indicator
    • numsat: Satellites used. A number between 0 and 12 represents the number of valid satellites in sight.
    • hdp: Horizontal dilution of precision.
    • alt: altitude.
    • un_alt: units of the altitude value.
    • geoidal: Geoid separation.
    • un_geoidal: Geoid value units.
    • dpgs: GPGS value.
  • $GPVTG
    • type: Message ID, VTG protocol header
    • trkdeg1:Measured heading
    • t: True
    • trkdeg2:Measured heading
    • m: Magnetic1
    • spdknots: Measured horizontal speed
    • knots: Knots
    • spdkmph: Measured horizontal speed
    • kph: Kilometers per hour
  • $GPRMC
    • type: Message ID, RMC protocol header
    • utc: UTC time (hhmmss.sss)
    • statusrmc: A=data valid or V=data not valid
    • lat: Latitude (ddmm.mmmm)
    • ns: North/South Indicator
    • long: Longitude (dddmm.mmmm)
    • ew: East/West Indicator
    • speed: Speed over ground
    • track: Course over ground
    • date: Date (ddmmyy)
    • magvar: Magnetic variation
    • mag_ew: E=east or W=west
  • $GPGSA
    • type: Message ID, GSA protocol header
    • selectmode: Manual or automatic.
    • mode: Fix not avaible, 2D or 3D
    • sat1: Sv on channel 1
    • sat2: Sv on channel 2
    • sat3: Sv on channel 3
    • sat4: Sv on channel 4
    • sat5: Sv on channel 5
    • sat6: Sv on channel 6
    • sat7: Sv on channel 7
    • sat8: Sv on channel 8
    • sat9: Sv on channel 9
    • sat10: Sv on channel 10
    • sat11: Sv on channel 11
    • sat12: Sv on channel 12
    • pdop: Position dilution of precision.
    • hdop: Horizontal dilution of precision.
    • vdop: Vertical dilution of precision.
  • $GPGSV
    • type: Message ID, GSV protocol header
    • satmessages: 1 to 3.
    • messnum: message number.
    • satview: Satellites in view.
    • satnum_1: satellite ID.
    • elevdeg_1: Elevation.
    • azimuthdeg_1: Azimuth
    • SNR_1: Range 0 to 99, or null when not tracking.
    • satnum_2: satellite ID.
    • elevdeg_2: Elevation.
    • azimuthdeg_2: Azimuth
    • SNR_2: Range 0 to 99, or null when not tracking.
    • satnum_3: satellite ID.
    • elevdeg_3:Elevation.
    • azimuthdeg_3: Azimuth
    • SNR_3: Range 0 to 99, or null when not tracking.
    • satnum_4: satellite ID.
    • elevdeg_4: Elevation.
    • azimuthdeg_4: Azimuth
    • SNR_4: Range 0 to 99, or null when not tracking.

File location: API/parser_NMEA.php

Example of use:

$response=parse_NMEA($line);
if (!empty($response['type'])) // ONLY SHOW RECOGNIZED CHAINS
{
    switch ($response['type'])
    {
        case 'GPGGA':
            if ($response['numsat']>=0)
            {
                echo "google's latitude ".$response['lat-google'];
                echo "google's longitude ".$response['long-google'];
                break 2;
            }
    }
}

© Libelium Comunicaciones Distribuidas S.L.

| Terms of use