Jump to content
View in the app

A better way to browse. Learn more.

Tinkerunity

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Geschrieben

Hi!

 

Ich habe ein völlig banales Problem, stehe mir aber wohl gerade selber auf den Füßen ... Habt ihr einen Tipp für mich?

Ich möchte von PHP aus den Sachltzustand eines Relais ermitteln. Das sollte eigentlich ganz einfach mit getState() gehen, aber ich kriegs nicht hin.

 

Der Code schaut eingedampft so aus:

<?php

require_once('Tinkerforge/IPConnection.php');
require_once('Tinkerforge/BrickletDualRelay.php');

use Tinkerforge\IPConnection;
use Tinkerforge\BrickletDualRelay;

$host = "IP-Nr";
$port = 4223;
$drid = ID des Dual-Relay;              // DualRelais-Bricklet

$ipcon = new IPConnection($host, $port);// IP connection zum brickd
$dr = new BrickletDualRelay($drid);     // Device-Object fuer DualRelais

$ipcon->addDevice($dr);                 // Dual Relay-Device zur IP-Connection zufuegen

$dr->setState( TRUE, FALSE );           // schaltet das erste Relais


$relais = $dr->getState();              // hier komme ich ins Schleudern
if ( $relais[0] == true ) {
   $status = "Relais 1 ist geschaltet";
   echo "$status \n";
   }

?>

 

Das Schalten des Relais funktioniert ganz prima, nur andersrum halt nicht.

Ich hätte in der Variablen $relais ein Array mit 2 Werten erwartet, so dass mir $relais[0] den Status des ersten Relais liefern sollte - dachte ich.

Wie muss ich die getState()-Abfrage formulieren, damit ich den Schaltstatus zurück bekomme ... ?

 

Vielen Dank für eure Hilfe!

Geschrieben

<?php
$relais = $dr->getState();
if ( $relais['relay1'] == true ) {
   $status = "Relais 1 ist geschaltet";
   echo "$status \n";
   }

?>

 

Wie der Inhalt der Arrays ist wenn die Funktion mehrere Werte zurück geben steht nicht in der PHP Dokumentation. Habs mir auf die TODO Liste gesetzt, das zu verbessern :)

Geschrieben
  • Autor

Perfekt, danke!

Jetzt kann ich bei meiner Raumsteuerung auch den aktuellen Ventilstatus abfragen  :)

Heute abend packe ich das noch in das Steuerproggi, dann steht das auch im LCD

status.png.abfbd15ea78dd99a95df9e5c0fad3d2d.png

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Gast
Reply to this topic...

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.