To Make a table in PHP with the data

Hello, could you please help me, I’m from telecommunications, this issue of applications or platforms that are new to me. I already have the data but I need to make a table (I think I can use PHP) and present it, could you suggest any solution please, how should I use these values.

{
	"iss": "chirpstack-application-server", // issuer of the claim
	"aud": "chirpstack-application-server", // audience for which the claim is intended
	"nbf": 1489566958,                  // unix time from which the token is valid
	"exp": 1489653358,                  // unix time when the token expires
	"sub": "user",                      // subject of the claim (an user)
	"username": "admin"                 // username the client claims to be
}

Your help please…

hey Carlos
i did a lot with php and the chirpstack project. so i think i can help you with this. but i can’t really understand what you want to do.

as far as i see, this is just the “data” out of the Auth-Page from chirpstack.io.

what exactly do you want to do? you want to grab data (for example gateways) from the chirpstack application server via the API and show them in a PHP Page / Table?

1 Like

Thank you, Yes I have several nodes and for each of them I will receive a data.

Well, then take this data and make a table, I could not perform the uthentication, I do not know the parameters that I must fill or where I generate them, when I install the app server I generate a jw_secret key (base 64), I only have that.

you can generate a JWT via API as well… and with this JWT you can use the rest of the api-functions.

here is a function to generate a JWT

function getJWT() {
        $url = "http://your-chipstark-app-server:8080/api/internal/login";
        $data = array(
                'password' => 'YourPassword',
                'username' => 'YourUsername',
        );
        $payload = json_encode($data);

        $ch = curl_init($url);
        $request_headers = array();
        $request_headers[] = 'Content-Type: application/json';
        $request_headers[] = 'Accept: application/json';

        curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $answer = curl_exec($ch);
        $data = json_decode($answer);
        return $data->jwt;
        curl_close($ch);
}

this generates a JWT which can be used for the rest of the commands - for example if you want to get all your gateways:

 $jwt = getJWT();
$orgid = getOrgID($id);
$gwlimit = getGWLimit($server, $orgid, $jwt);

// jSON URL which should be requested
$url = $server . "gateways?limit=" . $gwlimit . "&organizationID=" . $orgid;
$ch = curl_init($url);

$request_headers = array();
$request_headers[] = 'Accept: application/json';
$request_headers[] = 'Grpc-Metadata-Authorization: Bearer '.$jwt.'';


// Setting curl options
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

// Getting results
//$result = curl_exec($ch); // Getting jSON result string
$answer = curl_exec ($ch) ; // Getting jSON result string
$data =  json_decode($answer);

now you have a array ($data) with json_decoded values (the gateways)

then you have to loop the array to get all the data:

if (count($data->result)) {
// echo “<table id="test123" class="uk-table">”;
echo “<table id="test123" class="uk-table table table-striped table-bordered">”;

    echo "<thead>";
    echo "<tr>";
    echo "<th>Gateway-Name</th>";
    echo "<th>Gateway-ID</th>";
    echo "<th>Description</th>";
    echo "<th>Details</th>";
    echo "</tr>";

    echo "</thead>";
    // Cycle through the array
    echo "<tbody>";
    foreach ($data->result as $idx => $result) {
    // Output a row
            echo "<tr>";
            echo "<td>$result->name</td>";
            echo "<td>$result->id</td>";
            echo "<td>$result->description</td>";
            echo "<td> <a href=\"index.php/iot/gwdetails?gwid=" . $result->id . "\">  Details </a> </td>";
            echo "</tr>";
    }
    echo "</tbody>";
    // Close the table
    echo "</table>";

}

you can see in the part of this part - building the html table in php. second part (// Cycle through the array) you loop the array to get all the data.

i hope it makes the idea clear. of course, if you need something else then gateways, your neet to change the url.

1 Like

Sorry I was with other tasks, including learning the basics of PHP.
Could you help me, please what file I should configure and how?, so that it allows me to do the integration of the http.
At the moment it is as indicated by the installation settings.
https://www.chirpstack.io/application-server/install/config/

no idea what you exactly want.

i assume you have a running chripstack-enviroment… so you can use the api with a php file without any additional configuration.

if you need further help, please try to make your question more clear.

1 Like