Skip to content

Add support for PHP #48

@zakini

Description

@zakini
  • 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions