COSCUP 2022
讓PHP再次偉大 By Laravel Taiwan
Peter
2022/07/31
Is it possible to build a Smart home for PHP developers?
Slide
About me
-
Peter, GitHub
-
Active open source contributor
-
Speaker
-
COSCUP、MOPCON......
-
-
An associate engineer
-
DevOps
-
Back-end
-
System Architecture Researching
-
Web Application Security
-
PHP, Python and JavaScript
-
-
Industrial Technology Research Institute
-
Smart Grid Technology (2017~2021)
-
-
Institute for Information Industry
-
Database, Data platform architecture (2021~)
-
Outlines
-
The motivation
-
IoT and smart home introduction
-
Choosing the proper IoT devices, manual or existed?
-
The fundamentals are for initializing selected IoT devices setting
-
What's IFTTT? And how to use the IFTTT service?
-
The demonstration for Integrating the IoT devices with IFTTT
-
Using the PHP program to develop the Webhook on IFTTT service
-
The demonstration for the completed smart home application
-
Estimating the budget & Summary
The motivation
-
It's hard for the old people to switch the night light
-
I don't like to switch the night light manually everyday
The motivation
IoT and smart home introduction
-
Internet of Things
-
Smart Home
Choosing the proper IoT devices, manual or existed?
-
Manual
-
Pros
-
It can control all of components. E.g. hardware and software.
-
It's for maker
-
-
Cons
-
It's hard and unfriendly for web or software developers.
-
-
-
Existed
-
Pros
-
It's the completed products.
-
It's friendly for web and software developers.
-
-
Cons
-
It cannot set some detailed setting for the products.
-
It's not full-control for the hardware.
-
Customized hardware specifications or behaviors are limited.
-
-
Choosing the proper IoT devices, manual or existed?
Manual
Choosing the proper IoT devices, manual or existed?
Existed
The fundamentals are for initializing selected IoT devices setting
-
Prepare for the WiFi at home
-
Download the Wemo App
-
Check the Wemo device id
-
Pairing the device in the App
-
Done!
The fundamentals are for initializing selected IoT devices setting
Pairing the device in the App
The fundamentals are for initializing selected IoT devices setting
Pairing the device in the App
The fundamentals are for initializing selected IoT devices setting
Pairing the device in the App
The fundamentals are for initializing selected IoT devices setting
Pairing the device in the App
The fundamentals are for initializing selected IoT devices setting
-
Prepare for the WiFi at home
-
Download the Wemo App
-
Check the Wemo device id
-
Pairing the device in the App
-
Done!
The fundamentals are for initializing selected IoT devices setting
Pairing the device in the App
The fundamentals are for initializing selected IoT devices setting
Pairing the device in the App
The fundamentals are for initializing selected IoT devices setting
Pairing the device in the App
Short summary about architecture
What's IFTTT?
-
if this then that
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
And how to use the IFTTT service?
The demonstration for Integrating the IoT devices with IFTTT
And how to use the IFTTT service?
Discussing the issue
-
Date and time trigger is not good enough
-
It's not good enough to customized specific date time
-
-
Consider using the webhook trigger
The Webhook fundemental
And how to use the IFTTT service?
Using the Webhook example
And how to use the IFTTT service?
Using the Webhook example
And how to use the IFTTT service?
Using the Webhook example
And how to use the IFTTT service?
Using the Webhook example
And how to use the IFTTT service?
Using the Webhook example (Find the service key)
And how to use the IFTTT service?
Using the Webhook example (Create Applet)
And how to use the IFTTT service?
Using the Webhook example (Write the PHP program)
And how to use the IFTTT service?
Using the Webhook example (Result)
And how to use the IFTTT service?
Integrating the Existed Componenets with WeMo Smart Plug
And how to use the IFTTT service?
Integrating the Existed Componenets with WeMo Smart Plug
And how to use the IFTTT service?
Integrating the Existed Componenets with WeMo Smart Plug
And how to use the IFTTT service?
Integrating the Webhook with WeMo Smart Plug
Using the PHP program to develop the Webhook on IFTTT service
And how to use the IFTTT service?
Integrating the Webhook with D-Link Smart Plug
Using the PHP program to develop the Webhook on IFTTT service
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
localadmin@clickhouse02:~$ mkdir light-dlink
localadmin@clickhouse02:~$ cd light-dlink/
localadmin@clickhouse02:~/light-dlink$ php ~/composer.phar require lee/light-controller
Info from https://repo.packagist.org: #StandWithUkraine
Using version ^0.1.0 for lee/light-controller
......
Generating autoload files
4 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
localadmin@clickhouse02:~/light-dlink$
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
localadmin@clickhouse02:~/light-dlink$ cat light.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use lee\Light;
$light = new Light('webhook-maker-service-key', 'dlink-light-on');
$response = $light->sendRequest();
var_dump($response);
localadmin@clickhouse02:~/light-dlink$ php light.php
object(GuzzleHttp\Psr7\Response)#29 (6) {
["reasonPhrase":"GuzzleHttp\Psr7\Response":private]=>
string(2) "OK"
["statusCode":"GuzzleHttp\Psr7\Response":private]=>
int(200)
["headers":"GuzzleHttp\Psr7\Response":private]=>
array(13) {
["Content-Type"]=>
array(1) {
[0]=>
string(24) "text/html; charset=utf-8"
........
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
localadmin@clickhouse02:~/light-dlink$ cat light.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use lee\Light;
$light = new Light('webhook-maker-service-key', 'dlink-light-off');
$response = $light->sendRequest();
var_dump($response);
localadmin@clickhouse02:~/light-dlink$ php light.php
object(GuzzleHttp\Psr7\Response)#29 (6) {
["reasonPhrase":"GuzzleHttp\Psr7\Response":private]=>
string(2) "OK"
["statusCode":"GuzzleHttp\Psr7\Response":private]=>
int(200)
["headers":"GuzzleHttp\Psr7\Response":private]=>
array(13) {
["Content-Type"]=>
array(1) {
[0]=>
string(24) "text/html; charset=utf-8"
........
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
<?php
require_once __DIR__ . '/vendor/autoload.php';
use lee\Light;
$light = new Light('webhook-maker-service-key', 'dlink-light-on');
$response = $light->sendRequest();
var_dump((string)$response->getBody());
localadmin@clickhouse02:~/light-dlink$
ocaladmin@clickhouse02:~/light-dlink$ php light.php
string(59) "Congratulations! You've fired the dlink-light-on json event"
localadmin@clickhouse02:~/light-dlink$
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
Demonstration
The demonstration for the completed smart home application
D-Link DSP-W215 Example
localadmin@clickhouse02:~/light-dlink$ cat light.php
<?php
require_once __DIR__ . '/vendor/autoload.php';
use lee\Light;
$light = new Light('webhook-maker-service-key', 'dlink-light-off');
$response = $light->sendRequest();
var_dump((string)$response->getBody());
localadmin@clickhouse02:~/light-dlink$ php light.php
string(60) "Congratulations! You've fired the dlink-light-off json event"
localadmin@clickhouse02:~/light-dlink$
同場加映
Acer Air Monitor
Download the App
Pair the device
Pair the device
Successful Pairing the device
Connect the Acer Air Monitor
Connect the Acer Air Monitor
Create Acer Air Monitor Trigger
Create Acer Air Monitor Trigger
Create Acer Air Monitor Trigger
Create Acer Air Monitor Trigger
Create Acer Air Monitor Trigger
Collecting the time series data by yourself
Create Acer Air Monitor Trigger
Create Acer Air Monitor Trigger
Create Acer Air Monitor Trigger
Create Acer Air Monitor Trigger
High Temperature Triggering result
Checking whether it's high temperature every five minutes!
Create Acer Air Monitor Trigger
High Temperature Triggering (complex)
Create Acer Air Monitor Trigger
High Temperature Triggering (complex)
Create Acer Air Monitor Trigger
High Temperature Triggering (delay.php)
root@web-monetization-demo:~# cat /var/www/2020datathon.peterli.website/html/delay.php
<?php
$postdata = file_get_contents("php://input", 'r');
$decoded = json_decode($postdata, true);
sleep(60);
$eventname = 'dlink-light-off';
$key = 'webhook-maker-key';
$url = sprintf('https://maker.ifttt.com/trigger/%s/json/with/key/%s', $eventname, $key);
$curl = curl_init($url);
curl_exec($curl);
curl_close($curl);
Estimating the Budget & Summary
-
Hardware Device
-
Wemo Smart Plug: NT $899
-
D-Link DSP-W215: NT $499
-
(Acer Air Monitor): NT $1990 or NT $4490
-
-
DigitalOcean VM
-
NT $300/month (NT $3600/year)
-
-
Upgrading IFTTT Plan (Choosing the one of)
-
NT $150/month
-
NT $75/month
-
Known issues
-
The paired Smart plug Device will be gone
-
Pairing the device again
-
The reason is about WiFi signal is unstable
-
Trying to improve the WiFi signal
-
-
The light bulb is broken
-
This reason cannot be avoided
-
This situation is not happened frequently
-
It only switch the bulb manually
-
-
The light switch is turned off
-
The light switch always should be turned on
-
The reason is someone turn off the light switch
-
Telling them: don't switch the light
-
References
-
https://ifttt.com/maker_webhooks
-
https://ifttt.com/wemo_switch
-
https://ifttt.com/mydlink
-
https://ifttt.com/Air_Monitor
-
https://github.com/peter279k/ifttt-web-monitor
-
https://github.com/peter279k/ifttt-wemo-light-controller
-
https://github.com/peter279k/light-controller
Any Questions?
COSCUP 2022
By peter279k
COSCUP 2022
COSCUP 2022, Making PHP great again community talk
- 565