Example #1
0
 public function readTemperature()
 {
     require_once __DIR__ . '/lib/IPConnection.php';
     require_once __DIR__ . '/lib/BrickletTemperatureIR.php';
     $host = $this->A("TinkerforgeServerIP");
     $port = 4223;
     $ipcon = new IPConnection($host, $port);
     $t = new BrickletTemperatureIR("9nA");
     $ipcon->addDevice($t);
     echo json_encode(array(array(time() * 1000, $t->getAmbientTemperature() / 10.0), array(time() * 1000, $t->getObjectTemperature() / 10.0)));
     $ipcon->destroy();
 }
Example #2
0
// full speed forward and full speed backward
function cb_reached($velocity, $userData)
{
    $dc = $userData;
    if ($velocity == 32767) {
        echo "Velocity: Full Speed forward, turning backward\n";
        $dc->setVelocity(-32767);
    } elseif ($velocity == -32767) {
        echo "Velocity: Full Speed backward, turning forward\n";
        $dc->setVelocity(32767);
    } else {
        echo "Error\n";
        // Can only happen if another program sets velocity
    }
}
$ipcon = new IPConnection();
// Create IP connection
$dc = new BrickDC(UID, $ipcon);
// Create device object
$ipcon->connect(HOST, PORT);
// Connect to brickd
// Don't use device before ipcon is connected
// Register "velocity reached callback" to cb_reached
// cb_reached will be called every time a velocity set with
// set_velocity is reached
$dc->registerCallback(BrickDC::CALLBACK_VELOCITY_REACHED, 'cb_reached', $dc);
$dc->enable();
// The acceleration has to be smaller or equal to the maximum acceleration
// of the DC motor, otherwise cb_reached will be called too early
$dc->setAcceleration(5000);
// Slow acceleration
<?php

require_once 'Tinkerforge/IPConnection.php';
require_once 'Tinkerforge/BrickletRealTimeClock.php';
use Tinkerforge\IPConnection;
use Tinkerforge\BrickletRealTimeClock;
const HOST = 'localhost';
const PORT = 4223;
const UID = 'XYZ';
// Change XYZ to the UID of your Real-Time Clock Bricklet
$ipcon = new IPConnection();
// Create IP connection
$rtc = new BrickletRealTimeClock(UID, $ipcon);
// Create device object
$ipcon->connect(HOST, PORT);
// Connect to brickd
// Don't use device before ipcon is connected
// Get current date and time
$date_time = $rtc->getDateTime();
echo "Year: " . $date_time['year'] . "\n";
echo "Month: " . $date_time['month'] . "\n";
echo "Day: " . $date_time['day'] . "\n";
echo "Hour: " . $date_time['hour'] . "\n";
echo "Minute: " . $date_time['minute'] . "\n";
echo "Second: " . $date_time['second'] . "\n";
echo "Centisecond: " . $date_time['centisecond'] . "\n";
echo "Weekday: " . $date_time['weekday'] . "\n";
// Get current timestamp (unit is ms)
$timestamp = $rtc->getTimestamp();
echo "Timestamp: {$timestamp} ms\n";
echo "Press key to exit\n";
Example #4
0
	shmop_close($shmid);
		
	$BLight->setVoltage(($trigger == "1" AND $lastVolt !== false) ? $lastVolt : 0);
	
	$shmid = shmop_open(1, "w", 0644, 1);
	shmop_write($shmid, substr(decbin($valueMask), -1, 1), 0);
	shmop_close($shmid);
}*/
use Tinkerforge\IPConnection;
use Tinkerforge\BrickletTemperatureIR;
#use Tinkerforge\BrickletAnalogOut;
#use Tinkerforge\BrickletIO4;
$host = '192.168.7.227';
$port = 4223;
$uid = '9nA';
$ipcon = new IPConnection();
$BTemp = new BrickletTemperatureIR($uid, $ipcon);
$ipcon->connect($host, $port);
#$BTemp->setDebouncePeriod(60000);
$BTemp->setObjectTemperatureCallbackPeriod(20000);
#$tir->setAmbientTemperatureCallbackPeriod(1000);
$BTemp->registerCallback(BrickletTemperatureIR::CALLBACK_OBJECT_TEMPERATURE, 'cb_temp');
#$BTemp->setObjectTemperatureCallbackThreshold('>', 30*10, 0);
$ipcon->dispatchCallbacks(-1);
$ipcon->disconnect();
/*
$pid = pcntl_fork();

$shmid = shmop_open(0xff3, "c", 0644, 4);
shmop_write($shmid, "0000", 0);
shmop_close($shmid);
Example #5
0
			echo $ex->getClassName();
			echo "\n";
		}
		
	}
	$connections[$T->getID()]->dispatchCallbacks(-1);
	$connections[$T->getID()]->disconnect();
}*/
$nextRequest = array();
$counter = array();
while (true) {
    $AC = anyC::get("Tinkerforge");
    while ($T = $AC->getNextEntry()) {
        #echo "go\n";
        try {
            $connection = new IPConnection();
            $connection->connect($T->A("TinkerforgeServerIP"), $T->A("TinkerforgeServerPort"));
        } catch (Exception $e) {
            echo $e->getMessage();
            continue;
        }
        $ACB = anyC::get("TinkerforgeBricklet", "TinkerforgeBrickletTinkerforgeID", $T->getID());
        while ($B = $ACB->getNextEntry()) {
            $Type = "Tinkerforge\\" . $B->A("TinkerforgeBrickletType");
            if (!isset($counter[$B->getID()])) {
                $counter[$B->getID()] = 0;
            }
            try {
                switch ($B->A("TinkerforgeBrickletType")) {
                    case "BrickletTemperatureIR":
                        if (isset($nextRequest[$B->getID()]) and $nextRequest[$B->getID()] > time()) {
Example #6
0
<?php

require_once 'Tinkerforge/IPConnection.php';
use Tinkerforge\IPConnection;
const HOST = 'localhost';
const PORT = 4223;
// Print incoming enumeration
function cb_enumerate($uid, $connectedUid, $position, $hardwareVersion, $firmwareVersion, $deviceIdentifier, $enumerationType)
{
    echo "UID:               {$uid}\n";
    echo "Enumeration Type:  {$enumerationType}\n";
    if ($enumerationType == IPConnection::ENUMERATION_TYPE_DISCONNECTED) {
        echo "\n";
        return;
    }
    echo "Connected UID:     {$connectedUid}\n";
    echo "Position:          {$position}\n";
    echo "Hardware Version:  {$hardwareVersion['0']}.{$hardwareVersion['1']}.{$hardwareVersion['2']}\n";
    echo "Firmware Version:  {$firmwareVersion['0']}.{$firmwareVersion['1']}.{$firmwareVersion['2']}\n";
    echo "Device Identifier: {$deviceIdentifier}\n";
    echo "\n";
}
// Create IP connection and connect to brickd
$ipcon = new IPConnection();
$ipcon->connect(HOST, PORT);
// Register enumerate callback to "cb_enumerate"
$ipcon->registerCallback(IPConnection::CALLBACK_ENUMERATE, 'cb_enumerate');
$ipcon->enumerate();
echo "Press ctrl+c to exit\n";
$ipcon->dispatchCallbacks(-1);
// Dispatch callbacks forever
<?php

require_once 'Tinkerforge/IPConnection.php';
require_once 'Tinkerforge/BrickletAmbientLight.php';
require_once 'Tinkerforge/BrickletAmbientLightV2.php';
require_once 'Tinkerforge/BrickletHumidity.php';
require_once 'Tinkerforge/BrickletBarometer.php';
use Tinkerforge\IPConnection;
use Tinkerforge\BrickletAmbientLight;
use Tinkerforge\BrickletAmbientLightV2;
use Tinkerforge\BrickletHumidity;
use Tinkerforge\BrickletBarometer;
$ipcon = new IPConnection();
// NOTE: if you have a first generation Ambient Light Bricklet,
// then uncomment the next line and comment the line after that
//$brickletAmbientLight = new BrickletAmbientLight("apy", $ipcon);
$brickletAmbientLightV2 = new BrickletAmbientLightV2("bhL", $ipcon);
$brickletHumidity = new BrickletHumidity("7bA", $ipcon);
$brickletBarometer = new BrickletBarometer("d99", $ipcon);
$ipcon->connect("localhost", 4223);
// NOTE: if you have a first generation Ambient Light Bricklet,
// then uncomment the next line and comment the line after that
//$illuminance = $brickletAmbientLight->getIlluminance()/10.0;
$illuminance = $brickletAmbientLightV2->getIlluminance() / 100.0;
$humidity = $brickletHumidity->getHumidity() / 10.0;
$air_pressure = $brickletBarometer->getAirPressure() / 1000.0;
$temperature = $brickletBarometer->getChipTemperature() / 100.0;
$response = array("illuminance" => "Illuminance: {$illuminance} Lux", "humidity" => "Humidity: {$humidity} %RH", "air_pressure" => "Air Pressure: {$air_pressure} mbar", "temperature" => "Temperature: {$temperature} &deg;C");
print_r(json_encode($response));