Skip to content

Commit

Permalink
V1.5 added Bluetooth Support
Browse files Browse the repository at this point in the history
  • Loading branch information
JanStevens committed Sep 17, 2012
1 parent 7453ed4 commit 4999a3a
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 10 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ I also want to thank the following authors/scripts/plugins for making my coding

Warning: Before checking out the repo, please make sure you have a basic understanding of HTML, CSS, PHP and jQuery (and C++)

# Update
I've added Bluetooth support, for more information check out my blog at [http://fritz-hut.com](http://fritz-hut.com)

##More Information & Options
Check my blog for more information how to use the API: [blog](http://www.fritz-hut.com/all-projects/arduinopi/)
More information on how to connect the Raspberry Pi with the Arduino and how everything works can be found on my blog:
Expand Down
2 changes: 1 addition & 1 deletion api/arduino_pi.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct($device)
// Setup the serial connection, call the parent constructor
try {
parent::__construct();
$this->deviceSet("/dev/ttyAMA0");
$this->deviceSet("/dev/rfcomm0");
$this->confBaudRate(115200);
$this->confParity("none");
$this->confCharacterLength(8);
Expand Down
30 changes: 28 additions & 2 deletions api/php_serial.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @thanks Jim Wright for OSX cleanup/fixes.
* @copyright under GPL 2 licence
*
* Changed by Fritz to support ArduinoPi Error handeling and global mistakes corrected
* Changed by Fritz to support ArduinoPi Error handeling and mistakes corrected
*/
class phpSerialException extends Exception
{
Expand All @@ -33,6 +33,7 @@ class phpSerial
var $_dState = SERIAL_DEVICE_NOTSET;
var $_buffer = "";
var $_os = "";
var $_bluetooth_pid = null;

/**
* This var says if buffer should be flushed by sendMessage (true) or manualy (false)
Expand Down Expand Up @@ -112,6 +113,17 @@ public function deviceSet($device)
$this->_device = $device;
$this->_dState = SERIAL_DEVICE_SET;
return true;
} elseif (preg_match("/^\/dev\/rfcomm[0-9]+$/", $device, $matches)) {
// No connection is made with the bluetooth device, so create it.
$this->_exec_bg("rfcomm connect $device");
// Wait for the device to connect
sleep(2.5);
if ($this->_is_running($this->_bluetooth_pid)) {
$this->_device = $device;
$this->_dState = SERIAL_DEVICE_SET;
return true;
}
throw new phpSerialException("Could not connect with Bluetooth Device");
}
} elseif ($this->_os === "osx") {
if ($this->_exec("stty -f " . $device) === 0) {
Expand Down Expand Up @@ -154,7 +166,6 @@ public function deviceOpen($mode = "r+b")
if (!preg_match("@^[raw]\+?b?$@", $mode)) {
throw new phpSerialException("Invalid opening mode : " . $mode . ". Use fopen() modes.");
}

$this->_dHandle = @fopen($this->_device, $mode);

if ($this->_dHandle !== false) {
Expand Down Expand Up @@ -561,6 +572,21 @@ private function _exec($cmd, &$out = null)
return $retVal;
}

private function _exec_bg($cmd)
{
$retVal = proc_open("$cmd &> /dev/null 2> /dev/null &", array(), $pid);
$status = proc_get_status($retVal);
proc_close($retVal);
$this->_bluetooth_pid = $status["pid"] + 1;
return $retVal;
}

private function _is_running($pid)
{
exec("ps $pid", $state);
return (count($state) >= 2);
}

//
// INTERNAL TOOLKIT -- {STOP}
//
Expand Down
4 changes: 2 additions & 2 deletions basic.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@
<div class="span12">
<div class="page-header"><h1>Basic examples</h1>

<p>Calling commands using the ArduinoPi 1.0 is changed a lot so I will cover the eight default commands.
<p>
Every command can be called using ether GET or POST. I use jQuery to dynamically call the ArduinoPi API
when a
user clicks a button. For more information visit: <a
href="http://fritz-hut.com">http://fritz-hut.com</a></p></div>
href="http://fritz-hut.com">http://fritz-hut.com</a></p></div>
<div class="row-fluid">
<div class="span9">
<section id="pwm">
Expand Down
4 changes: 2 additions & 2 deletions header.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

<title>The ArduinoPi 1.0</title>
<title>The ArduinoPi 1.5</title>
<meta name="description" content="">
<meta name="author" content="">

Expand Down Expand Up @@ -43,7 +43,7 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="index.php">ArduinoPi 1.0</a>
<a class="brand" href="index.php">ArduinoPi 1.5</a>

<div class="nav-collapse">
<ul class="nav">
Expand Down
7 changes: 4 additions & 3 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@
?>
<div class="row-fluid">
<section>
<div class="page-header"><h1>The ArduinoPi 1.0</h1>
<div class="page-header"><h1>The ArduinoPi 1.5</h1>

<p>The ArduinoPi 1.0 is a PHP class with API support that allows for easy controll using PHP and
<p>The ArduinoPi 1.5 is a PHP class with API support that allows for easy controll using PHP and
jQuery.<br/>
You can use a simple post or get request to switch ports on the Arduino. The basic page contains
all the basic information.<br/>Hover, Color Picker and Sensor are examples used with the basic commands.
all the basic information.<br/>Hover, Color Picker and Sensor are examples used with the basic commands.<br/>
It also supports Bluetooth devices for wireless transmission.
</p>

<p>
Expand Down

0 comments on commit 4999a3a

Please sign in to comment.