Code Monkey home page Code Monkey logo

tuyapiphp's Introduction

Tuya Cloud Api PHP Client

This is a simple php client to interact with devices that support the tuya api.

If you are looking for a more ready to use solution or u need to control devices from different brands, you can use this tool with nodejs.

Requirements

I believe all is needed is php curl for the requests.

Installation

With composer:

Add the package to your composer.json file

"require": 
{

        "tuyapiphp/tuyapiphp": "*"
}

and run composer update

Stand Alone:

You must require all the needed classes manually, or you can use an autoloader like this one.

Basic Usage

Use these setup instructions for how to find the needed parameters.

Create new instance

$config =
[
	'accessKey' 	=> 'xxxxxxxxxxxxxxxxx' ,
	'secretKey' 	=> 'xxxxxxxxxxxxxxxxx' ,
	'baseUrl'		=> 'https://openapi.tuyaus.com'
];

$tuya = new \tuyapiphp\TuyaApi( $config );

Get an access token

$data = $tuya->token->get_new( );	

Example device operations

$app_id = 'xxxxxxxxxxxxxxxxxxxx';

$device_id = 'xxxxxxxxxxxxxxxxxxx';

// Get a token
$token = $tuya->token->get_new( )->result->access_token;

// Get list of devices connected with tuya/smart life app
$tuya->devices( $token )->get_app_list( $app_id );

// Get device status
$tuya->devices( $token )->get_status( $device_id );

// Set device name
$tuya->devices( $token )->put_name( $device_id , [ 'name' => 'FAN' ] );

// Send command to device
$payload = [ 'code' => 'switch_1' , 'value' => false ];
$tuya->devices( $token )->post_commands( $device_id , [ 'commands' => [ $payload ] ] );

Example camera stream

$app_id = 'xxxxxxxxxxxxxxxxxx';

$camera_id = 'xxxxxxxxxxxxxxxxxxxx';

$tuya = new \tuyapiphp\TuyaApi( $config );

// Get a token
$token = $tuya->token->get_new( )->result->access_token;

// Get camera stream link
$stream = $tuya->devices( $token )->post_stream_allocate( $app_id , $camera_id , [ 'type' => 'rtsp' ] );
        

Use the returned url to open the stream: ffplay -i rtsps://xxxxxxxxx

tuyapiphp's People

Contributors

ground-creative avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.