Thinger IO action in a php page?

Does anyone know how to integrate the API thinger.io in a PHP page (wordpress)?
I would like to add a button in a wordpress page that will change a true/false value in a ESP8266 (led, relay, solenoide, …)

Hi! This is possible by making an API Request to your device and passing true/false according to your needs (if you are trying to control a led, a relay, and so on).

Here it is a simple example that makes an api request with php and can be used in your code. I will elaborate this post later and probably I will make a HowTo about this. But in essence you have to set your device id, your user id, the resource you are trying to control (the name you set in your device code for controlling your led, relay, etc.), and the auth token. You can generate an authorization token in the device dashboard.

For example, I have a device with name “nodemcu”, my user id is “alvarolb”, and the resource I want to control is called “led”. I can just replace those terms in the code and it should turn on a light!

<?php
$device = 'device'; // the device id
$user = 'user'; // your user id
$resource = 'resource'; // your resource name like 'led', 'relay', and so on.
$authorization = 'authToken'; // a device access token for controlling all or this resource only
$state = true; // or false depending if you to turn it off

$url = "https://api.thinger.io/v2/users/{$user}/devices/{$device}/{$resource}?authorization={$authorization}";

$data = array(
    'in' => $state 
);

$options = array(
  'http' => array(
    'method'  => 'POST',
    'content' => json_encode( $data ),
    'header'=>  "Content-Type: application/json\r\n" .
                "Accept: application/json\r\n"
    )
);

$context  = stream_context_create( $options );
$result = file_get_contents( $url, false, $context );
$response = json_decode( $result );
?>

I will try to comment more on this later… but hope it helps in the meantime.

Thx,
I’ll try it soon.

Good! If you make it work, please let us see your project!