SlideShare ist ein Scribd-Unternehmen logo
1 von 36
Downloaden Sie, um offline zu lesen
FrOSCon 2013
Controlling Arduino With PHP
About Me
● Thomas Weinert
– @ThomasWeinert
● papaya Software GmbH
– papaya CMS
● PHP, Javascript, XSLT
● XML Fanatic (JSON is BAD)
Arduino
Arduino Mega
Arduino Nano
Arduino Nano Breadboard
Arduino Nano Breakout
Arduino IDE
Firmata
● MIDI Based
● Serial Port
– Forks for TCP
● http://firmata.org
Non-Blocking I/O
● Event Loop
● Event Emitter
● Promises
Event Loop
Listeners
Loop
External
Process
External
Process
File
Event Loop
● Timeouts
● Intervals
● Stream Listeners
● Implementations
– StreamSelect
– LibEvent
– MySQLi
Browser Example
var e = document.getElementById('output');
var counter = 0;
var interval = window.setInterval(
function() {
e.textContent =
e.textContent +
counter.toString() +
', ';
counter++;
},
1000
);
Event Emitter
Object
Event
Callback
Callback
Event
Callback
Event Event
● Attach
● on(), once()
● Trigger
● emit()
Event Emitter Example
$stream = new StreamFile('c:/tmp/sample.txt');
$stream->events()->on(
'read-data',
function($data) {
echo $data;
}
);
$stream->events()->on(
'error',
function($error) use ($loop) {
echo $error;
$loop->stop();
}
);
Promises
● Asynchronous Condition
● Attach Callbacks
– done()
– fail()
– always()
● Change Status
– reject()
– resolve()
jQuery Example
jQuery(
function () {
jQuery
.get('hello-world.xml')
.done(
function (xml) {
$('#output').text(
$('data', xml).text()
);
}
);
}
);
Carica Projects
● Carica I/O
– https://bitbucket.org/ThomasWeinert/carica-io
● Carica Firmata
– https://bitbucket.org/ThomasWeinert/carica-firmata
● Carica Chip
– https://bitbucket.org/ThomasWeinert/carica-chip
Carica I/O
● Event Loop
– CaricaIoEventLoop
● Event Emitter
– CaricaIoEventEmitter
● Promises
– CaricaIoDeferred
– CaricaIoDeferredPromise
Timers
$loop = LoopFactory::get();
$i = 0;
$loop->setInterval(
function () use (&$i) {
echo $i++;
},
1000
);
$loop->setTimeout(
function () use ($loop) {
$loop->stop();
},
10000
);
$loop->run();
Asynchronous MySQL
$mysqlOne = new IoDeferredMySQL(
new mysqli('localhost')
);
$mysqlTwo = new IoDeferredMySQL(
new mysqli('localhost')
);
$time = microtime(TRUE);
$debug = function($result) use ($time) {
var_dump(iterator_to_array($result));
var_dump(microtime(TRUE) - $time);
};
$queries = IoDeferred::When(
$mysqlOne("SELECT 'Query 1', SLEEP(5)")
->done($debug),
$mysqlTwo("SELECT 'Query 2', SLEEP(1)")
->done($debug)
);
IoEventLoopFactory::run($queries);
Asynchronous MySQL
HTTP Server
Why?
HTTP Server
● PHP Daemons
– Single process for all pequests
– Share variables
Carica HTTP Server
<?php
include(__DIR__.'/../../src/Carica/Io/Loader.php');
CaricaIoLoader::register();
use CaricaIoNetworkHttp;
$route = new CaricaIoNetworkHttpRoute();
$route->startsWith(
'/files', new HttpRouteFile(__DIR__)
);
$server = new CaricaIoNetworkHttpServer($route);
$server->listen(8080);
CaricaIoEventLoopFactory::run();
Carica Firmata
Carica Firmata Board
<?php
$board = new FirmataBoard(
new IoStreamSerial(
CARICA_FIRMATA_SERIAL_DEVICE,
CARICA_FIRMATA_SERIAL_BAUD
)
);
$board
->activate()
->done(
function () use ($board) { ... }
);
CaricaIoEventLoopFactory::run();
Carica Firmata Pins
function () use ($board) {
$buttonPin = 2;
$ledPin = 13;
$board->pins[$buttonPin]->mode = FirmataPIN_STATE_INPUT;
$board->pins[$ledPin]->mode = FirmataPIN_STATE_OUTPUT;
$board->digitalRead(
$buttonPin,
function($value) use ($board, $ledPin) {
$board->pins[$ledPin]->digital =
$value == FirmataDIGITAL_HIGH;
}
);
}
Example: Blink
function () use ($board, $loop) {
$led = 9;
$board->pinMode($led, FirmataPIN_STATE_OUTPUT);
$loop->setInterval(
function () use ($board, $led) {
static $ledOn = TRUE;
echo 'LED: '.($ledOn ? 'on' : 'off')."n";
$board->digitalWrite(
$led,
$ledOn
? FirmataDIGITAL_HIGH : FirmataDIGITAL_LOW
);
$ledOn = !$ledOn;
},
1000
);
}
RGB Wheel
Carica Chip
● Hardware Abstraction
● Device Objects
LED
function () use ($board) {
$led = new CaricaChipLed($board, 9);
$led->blink();
}
RGB LED
function () use ($board) {
$colors = array('#F00', '#0F0', '#00F');
$led = new CaricaChipLedRgb($board, 10, 11, 9);
$led->setColor('#000');
$index = 0;
$next = function() use ($led, $colors, &$index, &$next) {
if (isset($colors[$index])) {
$color = $colors[$index];
$led->fadeTo($color)->done($next);
}
if (++$index >= count($colors)) {
$index = 0;
}
};
$next();
}
Servo
function () use ($board, $loop) {
$positions = array(
0, 45, 90, 180
);
$servo = new CaricaChipServo($board, 7, -180);
$index = 0;
$loop->setInterval(
$next = function () use ($servo, $positions, &$index) {
if (isset($positions[$index])) {
$position = $positions[$index];
$servo->moveTo($position);
echo $position, " Grad , ", $servo->getPosition(), " Gradn";
}
if (++$index >= count($positions)) {
$index = 0;
}
},
2000
);
$next();
}
Analog Sensor
function () use ($board) {
$sensor = new CaricaChipSensorAnalog($board, 14);
$sensor->onChange(
function ($sensor) {
echo $sensor, "n";
}
);
}
Thank You
● Questions?
● Twitter: @ThomasWeinert
● Blog: http://a-basketful-of-papayas.net

Weitere ähnliche Inhalte

Was ist angesagt?

Comparison between ipv4 and ipv6
Comparison between ipv4 and ipv6Comparison between ipv4 and ipv6
Comparison between ipv4 and ipv6Dharmesh Patel
 
Windows内核技术介绍
Windows内核技术介绍Windows内核技术介绍
Windows内核技术介绍jeffz
 
Timeline of Processors
Timeline of ProcessorsTimeline of Processors
Timeline of ProcessorsDevraj Goswami
 
MikroTik MTCNA
MikroTik MTCNAMikroTik MTCNA
MikroTik MTCNAAli Layth
 
Light Weight Cryptography for IOT.pptx
Light Weight Cryptography for IOT.pptxLight Weight Cryptography for IOT.pptx
Light Weight Cryptography for IOT.pptxDineshBoobalan
 
Evolution of Computer Networking
Evolution of Computer NetworkingEvolution of Computer Networking
Evolution of Computer NetworkingIlamparithiM3
 
Ssl Vpn presentation at CoolTech club
Ssl Vpn presentation at CoolTech clubSsl Vpn presentation at CoolTech club
Ssl Vpn presentation at CoolTech clubiplotnikov
 
Lecture 6 - Wireless Sensors LoRa vs LoRaWAN
Lecture 6 - Wireless Sensors LoRa vs LoRaWANLecture 6 - Wireless Sensors LoRa vs LoRaWAN
Lecture 6 - Wireless Sensors LoRa vs LoRaWANAlexandru Radovici
 
Tugas troubleshooting jaringan
Tugas troubleshooting jaringanTugas troubleshooting jaringan
Tugas troubleshooting jaringantutik wiranti
 
Bluethooth Protocol stack/layers
Bluethooth Protocol stack/layersBluethooth Protocol stack/layers
Bluethooth Protocol stack/layersJay Nagar
 
Design of a campus network
Design of a campus networkDesign of a campus network
Design of a campus networkAalap Tripathy
 
Network modem
Network modemNetwork modem
Network modemOnline
 

Was ist angesagt? (20)

Intel microprocessors
Intel microprocessorsIntel microprocessors
Intel microprocessors
 
Comparison between ipv4 and ipv6
Comparison between ipv4 and ipv6Comparison between ipv4 and ipv6
Comparison between ipv4 and ipv6
 
Introduction to telnet
Introduction to telnetIntroduction to telnet
Introduction to telnet
 
Windows内核技术介绍
Windows内核技术介绍Windows内核技术介绍
Windows内核技术介绍
 
Timeline of Processors
Timeline of ProcessorsTimeline of Processors
Timeline of Processors
 
Ppt mikrotik
Ppt mikrotikPpt mikrotik
Ppt mikrotik
 
Internet Protocol
Internet ProtocolInternet Protocol
Internet Protocol
 
MikroTik MTCNA
MikroTik MTCNAMikroTik MTCNA
MikroTik MTCNA
 
Light Weight Cryptography for IOT.pptx
Light Weight Cryptography for IOT.pptxLight Weight Cryptography for IOT.pptx
Light Weight Cryptography for IOT.pptx
 
waspmote Presentation
waspmote Presentationwaspmote Presentation
waspmote Presentation
 
Evolution of Computer Networking
Evolution of Computer NetworkingEvolution of Computer Networking
Evolution of Computer Networking
 
Ssl Vpn presentation at CoolTech club
Ssl Vpn presentation at CoolTech clubSsl Vpn presentation at CoolTech club
Ssl Vpn presentation at CoolTech club
 
Lecture 6 - Wireless Sensors LoRa vs LoRaWAN
Lecture 6 - Wireless Sensors LoRa vs LoRaWANLecture 6 - Wireless Sensors LoRa vs LoRaWAN
Lecture 6 - Wireless Sensors LoRa vs LoRaWAN
 
Tugas troubleshooting jaringan
Tugas troubleshooting jaringanTugas troubleshooting jaringan
Tugas troubleshooting jaringan
 
Ip address
Ip addressIp address
Ip address
 
Dns server
Dns serverDns server
Dns server
 
Bluethooth Protocol stack/layers
Bluethooth Protocol stack/layersBluethooth Protocol stack/layers
Bluethooth Protocol stack/layers
 
Design of a campus network
Design of a campus networkDesign of a campus network
Design of a campus network
 
Network modem
Network modemNetwork modem
Network modem
 
Kelompok 4 media transmisi wireless
Kelompok 4 media transmisi wirelessKelompok 4 media transmisi wireless
Kelompok 4 media transmisi wireless
 

Ähnlich wie Controlling Arduino With PHP

Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGIPhpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGIMarcelo Gornstein
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHPThomas Weinert
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers StealBen Scofield
 
YAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEYAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEThiago Rondon
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScriptQiangning Hong
 
Job Managment Portlet
Job Managment PortletJob Managment Portlet
Job Managment Portletriround
 
Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Samuel Lampa
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploySimon Su
 
Application Layer in PHP
Application Layer in PHPApplication Layer in PHP
Application Layer in PHPPer Bernhardt
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)dantleech
 
Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Jacopo Romei
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiJérémy Derussé
 
PHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnPHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnSandro Zaccarini
 
Jakob Holderbaum - Managing Shared secrets using basic Unix tools
Jakob Holderbaum - Managing Shared secrets using basic Unix toolsJakob Holderbaum - Managing Shared secrets using basic Unix tools
Jakob Holderbaum - Managing Shared secrets using basic Unix toolsDevSecCon
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiInfluxData
 
こわくないよ❤️ Playframeworkソースコードリーディング入門
こわくないよ❤️ Playframeworkソースコードリーディング入門こわくないよ❤️ Playframeworkソースコードリーディング入門
こわくないよ❤️ Playframeworkソースコードリーディング入門tanacasino
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers ToolboxStefan
 
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Herokuronnywang_tw
 

Ähnlich wie Controlling Arduino With PHP (20)

Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGIPhpconf 2013 - Agile Telephony Applications with PAMI and PAGI
Phpconf 2013 - Agile Telephony Applications with PAMI and PAGI
 
Asynchronous I/O in PHP
Asynchronous I/O in PHPAsynchronous I/O in PHP
Asynchronous I/O in PHP
 
Hacking with hhvm
Hacking with hhvmHacking with hhvm
Hacking with hhvm
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
YAPC::Brasil 2009, POE
YAPC::Brasil 2009, POEYAPC::Brasil 2009, POE
YAPC::Brasil 2009, POE
 
服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript服务框架: Thrift & PasteScript
服务框架: Thrift & PasteScript
 
Job Managment Portlet
Job Managment PortletJob Managment Portlet
Job Managment Portlet
 
Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...
 
Nko workshop - node js crud & deploy
Nko workshop - node js crud & deployNko workshop - node js crud & deploy
Nko workshop - node js crud & deploy
 
Application Layer in PHP
Application Layer in PHPApplication Layer in PHP
Application Layer in PHP
 
Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)Exploring Async PHP (SF Live Berlin 2019)
Exploring Async PHP (SF Live Berlin 2019)
 
Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011Symfony CMF - PHP Conference Brazil 2011
Symfony CMF - PHP Conference Brazil 2011
 
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry PiGrâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
Grâce aux tags Varnish, j'ai switché ma prod sur Raspberry Pi
 
PHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnPHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vuln
 
Jakob Holderbaum - Managing Shared secrets using basic Unix tools
Jakob Holderbaum - Managing Shared secrets using basic Unix toolsJakob Holderbaum - Managing Shared secrets using basic Unix tools
Jakob Holderbaum - Managing Shared secrets using basic Unix tools
 
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry PiMonitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
Monitoring Your ISP Using InfluxDB Cloud and Raspberry Pi
 
こわくないよ❤️ Playframeworkソースコードリーディング入門
こわくないよ❤️ Playframeworkソースコードリーディング入門こわくないよ❤️ Playframeworkソースコードリーディング入門
こわくないよ❤️ Playframeworkソースコードリーディング入門
 
A CTF Hackers Toolbox
A CTF Hackers ToolboxA CTF Hackers Toolbox
A CTF Hackers Toolbox
 
2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku2012 coscup - Build your PHP application on Heroku
2012 coscup - Build your PHP application on Heroku
 
Rack Middleware
Rack MiddlewareRack Middleware
Rack Middleware
 

Mehr von Thomas Weinert

PHPUG CGN: Controlling Arduino With PHP
PHPUG CGN: Controlling Arduino With PHPPHPUG CGN: Controlling Arduino With PHP
PHPUG CGN: Controlling Arduino With PHPThomas Weinert
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesThomas Weinert
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend PerformanceThomas Weinert
 
Experiences With Pre Commit Hooks
Experiences With Pre Commit HooksExperiences With Pre Commit Hooks
Experiences With Pre Commit HooksThomas Weinert
 
The Lumber Mill - XSLT For Your Templates
The Lumber Mill  - XSLT For Your TemplatesThe Lumber Mill  - XSLT For Your Templates
The Lumber Mill - XSLT For Your TemplatesThomas Weinert
 
The Lumber Mill Xslt For Your Templates
The Lumber Mill   Xslt For Your TemplatesThe Lumber Mill   Xslt For Your Templates
The Lumber Mill Xslt For Your TemplatesThomas Weinert
 
Deliver Files With PHP
Deliver Files With PHPDeliver Files With PHP
Deliver Files With PHPThomas Weinert
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend PerformanceThomas Weinert
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend PerformanceThomas Weinert
 

Mehr von Thomas Weinert (13)

PHPUG CGN: Controlling Arduino With PHP
PHPUG CGN: Controlling Arduino With PHPPHPUG CGN: Controlling Arduino With PHP
PHPUG CGN: Controlling Arduino With PHP
 
Decoupling Objects With Standard Interfaces
Decoupling Objects With Standard InterfacesDecoupling Objects With Standard Interfaces
Decoupling Objects With Standard Interfaces
 
Lumberjack XPath 101
Lumberjack XPath 101Lumberjack XPath 101
Lumberjack XPath 101
 
FluentDom
FluentDomFluentDom
FluentDom
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend Performance
 
Experiences With Pre Commit Hooks
Experiences With Pre Commit HooksExperiences With Pre Commit Hooks
Experiences With Pre Commit Hooks
 
The Lumber Mill - XSLT For Your Templates
The Lumber Mill  - XSLT For Your TemplatesThe Lumber Mill  - XSLT For Your Templates
The Lumber Mill - XSLT For Your Templates
 
The Lumber Mill Xslt For Your Templates
The Lumber Mill   Xslt For Your TemplatesThe Lumber Mill   Xslt For Your Templates
The Lumber Mill Xslt For Your Templates
 
SVN Hook
SVN HookSVN Hook
SVN Hook
 
Deliver Files With PHP
Deliver Files With PHPDeliver Files With PHP
Deliver Files With PHP
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend Performance
 
PHP 5.3/6
PHP 5.3/6PHP 5.3/6
PHP 5.3/6
 
Optimizing Your Frontend Performance
Optimizing Your Frontend PerformanceOptimizing Your Frontend Performance
Optimizing Your Frontend Performance
 

Kürzlich hochgeladen

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfhans926745
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 

Kürzlich hochgeladen (20)

The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 

Controlling Arduino With PHP

  • 2. About Me ● Thomas Weinert – @ThomasWeinert ● papaya Software GmbH – papaya CMS ● PHP, Javascript, XSLT ● XML Fanatic (JSON is BAD)
  • 9. Firmata ● MIDI Based ● Serial Port – Forks for TCP ● http://firmata.org
  • 10. Non-Blocking I/O ● Event Loop ● Event Emitter ● Promises
  • 12. Event Loop ● Timeouts ● Intervals ● Stream Listeners ● Implementations – StreamSelect – LibEvent – MySQLi
  • 13. Browser Example var e = document.getElementById('output'); var counter = 0; var interval = window.setInterval( function() { e.textContent = e.textContent + counter.toString() + ', '; counter++; }, 1000 );
  • 14. Event Emitter Object Event Callback Callback Event Callback Event Event ● Attach ● on(), once() ● Trigger ● emit()
  • 15. Event Emitter Example $stream = new StreamFile('c:/tmp/sample.txt'); $stream->events()->on( 'read-data', function($data) { echo $data; } ); $stream->events()->on( 'error', function($error) use ($loop) { echo $error; $loop->stop(); } );
  • 16. Promises ● Asynchronous Condition ● Attach Callbacks – done() – fail() – always() ● Change Status – reject() – resolve()
  • 17. jQuery Example jQuery( function () { jQuery .get('hello-world.xml') .done( function (xml) { $('#output').text( $('data', xml).text() ); } ); } );
  • 18. Carica Projects ● Carica I/O – https://bitbucket.org/ThomasWeinert/carica-io ● Carica Firmata – https://bitbucket.org/ThomasWeinert/carica-firmata ● Carica Chip – https://bitbucket.org/ThomasWeinert/carica-chip
  • 19. Carica I/O ● Event Loop – CaricaIoEventLoop ● Event Emitter – CaricaIoEventEmitter ● Promises – CaricaIoDeferred – CaricaIoDeferredPromise
  • 20. Timers $loop = LoopFactory::get(); $i = 0; $loop->setInterval( function () use (&$i) { echo $i++; }, 1000 ); $loop->setTimeout( function () use ($loop) { $loop->stop(); }, 10000 ); $loop->run();
  • 21. Asynchronous MySQL $mysqlOne = new IoDeferredMySQL( new mysqli('localhost') ); $mysqlTwo = new IoDeferredMySQL( new mysqli('localhost') ); $time = microtime(TRUE); $debug = function($result) use ($time) { var_dump(iterator_to_array($result)); var_dump(microtime(TRUE) - $time); }; $queries = IoDeferred::When( $mysqlOne("SELECT 'Query 1', SLEEP(5)") ->done($debug), $mysqlTwo("SELECT 'Query 2', SLEEP(1)") ->done($debug) ); IoEventLoopFactory::run($queries);
  • 24. HTTP Server ● PHP Daemons – Single process for all pequests – Share variables
  • 25. Carica HTTP Server <?php include(__DIR__.'/../../src/Carica/Io/Loader.php'); CaricaIoLoader::register(); use CaricaIoNetworkHttp; $route = new CaricaIoNetworkHttpRoute(); $route->startsWith( '/files', new HttpRouteFile(__DIR__) ); $server = new CaricaIoNetworkHttpServer($route); $server->listen(8080); CaricaIoEventLoopFactory::run();
  • 27. Carica Firmata Board <?php $board = new FirmataBoard( new IoStreamSerial( CARICA_FIRMATA_SERIAL_DEVICE, CARICA_FIRMATA_SERIAL_BAUD ) ); $board ->activate() ->done( function () use ($board) { ... } ); CaricaIoEventLoopFactory::run();
  • 28. Carica Firmata Pins function () use ($board) { $buttonPin = 2; $ledPin = 13; $board->pins[$buttonPin]->mode = FirmataPIN_STATE_INPUT; $board->pins[$ledPin]->mode = FirmataPIN_STATE_OUTPUT; $board->digitalRead( $buttonPin, function($value) use ($board, $ledPin) { $board->pins[$ledPin]->digital = $value == FirmataDIGITAL_HIGH; } ); }
  • 29. Example: Blink function () use ($board, $loop) { $led = 9; $board->pinMode($led, FirmataPIN_STATE_OUTPUT); $loop->setInterval( function () use ($board, $led) { static $ledOn = TRUE; echo 'LED: '.($ledOn ? 'on' : 'off')."n"; $board->digitalWrite( $led, $ledOn ? FirmataDIGITAL_HIGH : FirmataDIGITAL_LOW ); $ledOn = !$ledOn; }, 1000 ); }
  • 31. Carica Chip ● Hardware Abstraction ● Device Objects
  • 32. LED function () use ($board) { $led = new CaricaChipLed($board, 9); $led->blink(); }
  • 33. RGB LED function () use ($board) { $colors = array('#F00', '#0F0', '#00F'); $led = new CaricaChipLedRgb($board, 10, 11, 9); $led->setColor('#000'); $index = 0; $next = function() use ($led, $colors, &$index, &$next) { if (isset($colors[$index])) { $color = $colors[$index]; $led->fadeTo($color)->done($next); } if (++$index >= count($colors)) { $index = 0; } }; $next(); }
  • 34. Servo function () use ($board, $loop) { $positions = array( 0, 45, 90, 180 ); $servo = new CaricaChipServo($board, 7, -180); $index = 0; $loop->setInterval( $next = function () use ($servo, $positions, &$index) { if (isset($positions[$index])) { $position = $positions[$index]; $servo->moveTo($position); echo $position, " Grad , ", $servo->getPosition(), " Gradn"; } if (++$index >= count($positions)) { $index = 0; } }, 2000 ); $next(); }
  • 35. Analog Sensor function () use ($board) { $sensor = new CaricaChipSensorAnalog($board, 14); $sensor->onChange( function ($sensor) { echo $sensor, "n"; } ); }
  • 36. Thank You ● Questions? ● Twitter: @ThomasWeinert ● Blog: http://a-basketful-of-papayas.net