chirpstack-api icon indicating copy to clipboard operation
chirpstack-api copied to clipboard

Add support for PHP

Open zakini opened this issue 3 years ago • 0 comments

  • [x] I have searched the issues of this repository and believe that this is not a duplicate.

Summary

gRPC supports PHP, so this should just be a case of generating client code for PHP.

What is the use-case?

I'm currently building a Laravel app that integrates with Chirpstack to communicate with IoT sensors out in the field. Having a gRPC client for Chirpstack would simplify things since I'm effectively writing a client from scratch using the REST API:

<?php

namespace App\Services;

use Illuminate\Http\Client\PendingRequest;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Str;

class Chirpstack
{
    public function listDevices(): array
    {
        return $this->http()
            ->get('devices')
            ->throw()
            ->json();
    }

    public function getDevice(string $deviceEui): array
    {
        return $this->http()
            ->get("devices/{$deviceEui}")
            ->throw()
            ->json();
    }

    public function enqueueOnDeviceQueue(string $deviceEui, string $data, int $lorawanPort): array
    {
        return $this->http()
            ->post("devices/{$deviceEui}/queue", [
                'deviceQueueItem' => [
                    'data' => $data,
                    'fPort' => $lorawanPort,
                ],
            ])
            ->throw()
            ->json();
    }

    protected function http(): PendingRequest
    {
        return Http::baseUrl(Str::finish(config('services.chirpstack.base_uri'), '/') . 'api')
            ->withHeaders([
                'Grpc-Metadata-Authorization' => 'Bearer ' . config('services.chirpstack.auth_token'),
            ]);
    }
}

Implementation description

Basically the same as the clients for the other supported languages?

Can you implement this by yourself and make a pull request?

I'm happy to give it a go, but I've never worked with gRPC before

zakini avatar Oct 20 '21 17:10 zakini