Percobaan cloud4pi dengan PHP

<!--?php
// A sample PHP Script to POST data using cURL
// Data in JSON format

$json= '&#91;{"name":"Temperature","type":"numeric"},{"name":"LEDOn","type":"bool"}&#93;';
$arr=json_decode($json, false);

echo '

<pre-->';
print_r($arr);
echo '


';

$employee_object = new stdClass;
$employee_object-&gt;name = "Temperature";
$employee_object-&gt;type = "numeric";
$employee_object1 = new stdClass;
$employee_object1-&gt;name = "LEDOn";
$employee_object1-&gt;type = "bool"; 

$data = array
  (
  $employee_object,
  $employee_object1
);

$payload = json_encode($data);
echo "==&gt;".$payload;

$token = '2HSmdfzsEAXB3puVUTi6ZoirV';

// Prepare new cURL resource
$ch = curl_init('https://cloud4rpi.io/api/devices/'.$token.'/config');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/json',
    'Content-Length: ' . strlen($payload))
);

// Submit the POST request
$result = curl_exec($ch);

echo $result;
// Close cURL session handle
curl_close($ch);

$json = '{"ts":"date","payload":{"Temperature":24,"LEDOn":true}}';
$arr=json_decode($json, true);

echo '









<pre>';
print_r($arr);
echo '</pre>
';

$dt = date(DateTime::ISO8601);

$carss = array
(
"ts"=&gt;$dt,
"payload"=&gt;array("Temperature"=&gt;22,"LEDOn"=&gt;0)
);

$payload = json_encode($carss);
echo "==&gt;".$payload;

$token = '2HSmdfzsEAXB3puVUTi6ZoirV';

// Prepare new cURL resource
$ch = curl_init('https://cloud4rpi.io/api/devices/'.$token.'/data');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

// Set HTTP Header for POST request
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($payload))
);

// Submit the POST request
$result = curl_exec($ch);

echo $result;
// Close cURL session handle
curl_close($ch);

?&gt;

Pemanfaatan Timer pada ESP8266

Interrupt Software Timer

#include <ESP8266WiFi.h>
#include <Ticker.h>  
Ticker blinker;
#define LED 2  //On board LED
void changeState()
{
  digitalWrite(LED, !(digitalRead(LED)));  
}

void setup()
{
    pinMode(LED,OUTPUT);
    blinker.attach(0.5, changeState); //atau attach_ms dalam milisecond
}

void loop()
{
}

Interrupt Hardware Timer (Timer1), Timer0 tidak bisa digunakan karena untuk koneksi WiFi

#include <ESP8266WiFi.h>
#include <Ticker.h>
Ticker blinker;
#define LED 2  //On board LED
void ICACHE_RAM_ATTR onTimerISR(){
    digitalWrite(LED,!(digitalRead(LED)));  //Toggle LED Pin
    timer1_write(600000);//12us

}


void setup()

{

    pinMode(LED,OUTPUT);

 


    timer1_attachInterrupt(onTimerISR);

    timer1_enable(TIM_DIV16, TIM_EDGE, TIM_SINGLE);

    timer1_write(600000); //120000 us

}


void loop()

{

}


Sumber:

https://circuits4you.com/category/esp8266/

https://www.switchdoc.com/category/esp8266/