Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for PHP #48

Open
1 task done
zakini opened this issue Oct 20, 2021 · 0 comments
Open
1 task done

Add support for PHP #48

zakini opened this issue Oct 20, 2021 · 0 comments

Comments

@zakini
Copy link

zakini commented Oct 20, 2021

  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant