2017 © Pedro Peláez
 

library arduino-php-wrapper

image

marabesi/arduino-php-wrapper

  • Saturday, May 26, 2018
  • by marabesi
  • Repository
  • 1 Watchers
  • 15 Stars
  • 41 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 3 Forks
  • 0 Open issues
  • 2 Versions
  • 21 % Grown

The README.md

arduino-php-wrapper (inspired by Johnny-Five JS)

Codacy Badge Build Status Latest Stable Version Total Downloads composer.lock, (*1)

If you are wondering how to control the Arduino serial port via PHP, here is the solution. The arduino:// wrapper is a easy and straightforward way to write and read data from Arduino., (*2)

Install

composer require marabesi/arduino-php-wrapper

Usage

To read data from Arduino serial just use the regular I/O functions in PHP such as fread or file_get_contents, (*3)

``` php \Arduino\Wrapper::register();, (*4)

//reads data from Arduino $resource = fopen('arduino://ttyUSB0', 'r+'); print fread($resource, 1024);, (*5)


Or if you prefer, you can use **file_get_contents** and get the same result ``` php print file_get_contents('arduino://ttyUSB0');

To write data in the Arduino serial is as easy as it could be, (*6)

``` php \Arduino\Wrapper::register();, (*7)

//writes data to Arduino $resource = fopen('arduino://ttyUSB0', 'r+'); print fwrite('hello Arduino');, (*8)


``` php \Arduino\Wrapper::register(); print file_put_contents('arduino://hello Arduino');

OOP

You can use in your project in a OOP style, (*9)

Sending data

``` php $writer = new Arduino\Writer(new Arduino\Wrapper()); $bytes = $writer->out('ttyUSB0', 'from oop');, (*10)


### Reading data ``` php $arduino = new \Arduino\Wrapper(); $writer = new \Arduino\Reader($arduino); while (true) { print $writer->from('/dev/cu.usbmodem1411'); }

Improvements

As you can see is really simple and we can improve it much more as the sensors are identified., (*11)

  • Prevent arduino from reload everytime a request is made by PHP

Slides (talks based on this lib)

SlideShare Introduction to IoT and PHP - Nerdzão day #1, (*12)

SlideShare IoT powered by PHP and streams - PHPExperience2017, (*13)

SlideShare Control your house with the elePHPant - PHPConf2016, (*14)

The Versions

26/05 2018

dev-master

9999999-dev

  Sources   Download

The Development Requires

by Avatar marabesi

20/08 2017

v1.0.0

1.0.0.0

  Sources   Download

The Development Requires

by Avatar marabesi