2017 © Pedro Peláez
 

library bbt_php

PhP library for interfacing with Beebotte

image

beebotte/bbt_php

PhP library for interfacing with Beebotte

  • Friday, February 23, 2018
  • by beebotte
  • Repository
  • 1 Watchers
  • 2 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Beebotte PHP SDK

what where
overview http://beebotte.com/overview
tutorials http://beebotte.com/tutorials
apidoc http://beebotte.com/api
source https://github.com/beebotte/bbt_php

Bugs / Feature Requests

Think you have found a bug? Want to see a new feature in Beebotte? Please open an issue in github. Please provide as much information as possible about the issue type and how to reproduce it., (*1)

https://github.com/beebotte/bbt_php/issues, (*2)

Install

The Beebotte PHP library is available as a composer package called bbt_php (See https://packagist.org/packages/beebotte/bbt_php)., (*3)

composer require beebotte/bbt_php

Or add the following to composer.json in your project:, (*4)

"require": {
    "beebotte/bbt_php": "*"
}

and then run composer update., (*5)

If you don't have composer, you can still get Beebotte PHP library by cloning the project from github:, (*6)

git clone https://github.com/beebotte/bbt_php.git

or by downloading the library source files., (*7)

Usage

To use the library, you need to be a registered user. If this is not the case, create your account at http://beebotte.com and note your access credentials., (*8)

As a reminder, Beebotte resource description uses a two levels hierarchy:, (*9)

  • Channel: physical or virtual connected object (an application, an arduino, a coffee machine, etc) providing some resources
  • Resource: most elementary part of Beebotte, this is the actual data source (e.g. temperature from a domotics sensor)

Beebotte Constructor

Use your account api and secret keys to initialize Beebotte connector:, (*10)

  $api_key    = 'YOUR_API_KEY';
  $secret_key = 'YOUR_SECRET_KEY';
  $bbt = new Beebotte($api_key, $secret_key);

Reading Data

You can read data from one of your channel resources using:, (*11)

  $records = $bbt->read("channel1", "resource1", 5 /* read last 5 records */);

You can read data from a public channel by specifying the channel owner:, (*12)

  $records = $bbt->publicRead("owner", "channel1", "resource1", 5 /* read last 5 records */);

Writing Data

You can write data to a resource of one of your channels using:, (*13)

  $bbt->write("channel1", "resource1", "Hello Horld");

If you have multiple records to write (to one or multiple resources of the same channel), you can use the bulk write method:, (*14)

  $bbt->writeBulk("channel1", array(array("resource" => "resource1", "data" => "Hello"), array("resource" => "resource2", "data" => "World")));

Publishing Data

You can publish data to a channel resource using:, (*15)

  $bbt->publish("any_channel", "any_resource", "Hello World");

Published data is transient. It will not saved to any database; rather, it will be delivered to active subscribers in real time. The Publish operations do not require that the channel and resource be actually created. They will be considered as virtual: the channel and resource exist as long as you are publishing data to them. By default, published data is public, publish a private message, you need to add private- prefix to the channel name like this:, (*16)

  $bbt->publish("private-any_channel", "any_resource", "Hello World");

If you have multiple records to publish (to one or multiple resources of the same channel), you can use the bulk publish method:, (*17)

  $bbt->publishBulk("channel1", array(array("resource" => "resource1", "data" => "Hello"), array("resource" => "resource2", "data" => "World")));

Resource Object

The library provides a Resource Class that can be used as follows, (*18)

  //Create the resource object
  $resource = new Resource($bbt, "channel1", "resource1");

  //Read data from public resource
  $records = $resource->read("owner", 2 /* last 2 records */);

  //Read data
  $records = $resource->read(null, 2 /* last 2 records */);

  //Read the last written record
  $record = $resource->recentValue();

  //Write data
  $resource->write("Hello World");

  //Publish data
  $resource->publish("Hola amigo");

Signing subscribe Requests

As described in https://beebotte.com/docs/clientauth, you need to implement an authentication endpoint to grant users of your Web application access to privileged channel resources on your Beebotte account., (*19)

The library provides utility functions to simplify the implementation of such endpoints:, (*20)

  // authenticate client subscribe request given all parameters
  $sig = $bbt->auth_client($sid, $channel, $resource, $ttl, $read, $write);

you can also build the string to sign yourself and feed it to the library to get it signed:, (*21)

  $r = $read ? "true" : "false";
  $w = $write? "true" : "false";
  $stringToSign = $sid . ":" . $channel . "." . $resource . ":ttl=" . $ttl . ":read=" . $r . ":write=" . $w;
  $sig = $bbt->sign($stringToSign);

License

Copyright 2013 - 2019 Beebotte., (*22)

The MIT License, (*23)

The Versions

23/02 2018

dev-master

9999999-dev https://github.com/beebotte/bbt_php

PhP library for interfacing with Beebotte

  Sources   Download

MIT

The Requires

  • php >=5.2
  • ext-curl *

 

api rest restful realtime iot device internet of things websockets pubsub beebotte connected