03.12.2015 Views

laravel4cookbook

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Embedded Systems 303<br />

the message event listener, the return values will be received and reflected in the sensor input field.<br />

Spinning Up<br />

To connect to the Arduino, you should run the following command:<br />

1 php artisan embedded:serve /dev/cu.usbmodem1411<br />

On my system, the Arduino is reflected as /dev/cu.usbmodem1411 by this may differ on yours. For<br />

instance, my Ubuntu machine shows it as /dev/ttyACM0. The easiest way to find out what it is, is<br />

to unplug it, then run the following command:<br />

1 ls /dev/tty*<br />

Look over the list to familiarise yourself with the devices you see there. The plug the Arduino in,<br />

wait a couple seconds and run that command again. This time you should see a new addition to the<br />

list of devices. This is most likely your Arduino.<br />

.<br />

You may be wondering why my device starts with cu and not tty. I first tried the tty version of<br />

the Arduino and it would cause the server to hang. I experimented and found that the cu version<br />

let me connect and communicate with the Arduino. Go figure…<br />

I usually like to include Vagrant configurations for running these projects. This time I found it<br />

confusing to try and communicate with an Arduino through the host machine. So instead I decided<br />

to try the server.php script bundled with Laravel applications. Turns out you can run the server with<br />

the following command:<br />

1 php -S 127.0.0.1:8080 -t ./public server.php<br />

Now you can go to http://127.0.0.1:8080 and see the interface we created earlier. You need to start<br />

the serve command successfully before this interface will work. If everything is running correctly,<br />

you should immediately start to see the sensor values being updated in the interface.<br />

You can now adjust the LED input to control the brightness of the LED, and the x and y inputs to<br />

control the rotation of the servos.<br />

Adding A Webcam<br />

Streaming video from a web cam can be tricky, so we’re going to take time-lapse photos instead…

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!