Unterschiede
Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
manuals:symcon:mqtt-integration [2018/09/22 18:42] – admin | manuals:symcon:mqtt-integration [2018/09/23 19:15] (aktuell) – paulg4h | ||
---|---|---|---|
Zeile 12: | Zeile 12: | ||
**Auch müssen alle Werte in < | **Auch müssen alle Werte in < | ||
- | </ | ||
- | |||
- | <WRAP center round info 90%> | ||
- | Nachdem Symcon ja Debian auf x86 Hardware nicht Unterstütz (werd ich nie verstehen) sondern nur Ubuntu und da die jetzt schon sehr alte 14.04er habe ich soeben ein paar Ergänzungen in der Anleitung gemacht und die MQTT integration nun auch auf Ubuntu Installiert (Stand Jänner 2017) | ||
</ | </ | ||
Zeile 45: | Zeile 41: | ||
===== Pakete Installieren ===== | ===== Pakete Installieren ===== | ||
+ | Einen MQTT Broker z.B. das Paket mosquitto Installieren | ||
+ | aptitude install mosquitto mosquitto_pub mosquitto_sub | ||
+ | | ||
===== Symcon Vorbereiten ===== | ===== Symcon Vorbereiten ===== | ||
- | Nach der Installation von IPS dort in die Kategorie anlegen | + | |
+ | ==== MQTT Client zum Senden | ||
+ | Zum Senden von Daten per MQTT_Publish aus jedem script: | ||
+ | https:// | ||
+ | |||
+ | |||
+ | ==== Mosquitto an Symcon Anbinden ==== | ||
+ | |||
+ | Eine Kategorie anlegen | ||
Datenpunkte/ | Datenpunkte/ | ||
- | hier das switch | + | |
+ | In diesem Knoten werden dann alle Geräte und Datenpunkte Automatisch erstellt / Aktualisiert, | ||
+ | Datenpunkte/ | ||
+ | und erstellen | ||
- | Ich lege es nach: | + | Die Datei: |
Datenpunkte/ | Datenpunkte/ | ||
+ | mit folgendem Inhalt: | ||
<code php><? | <code php><? | ||
- | $d = false; $msg = ""; | + | include_once(IPS_GetScript(42011 )[" |
+ | |||
+ | $d = true; $msg = ""; | ||
$value = ""; | $value = ""; | ||
- | if ($d){ $msg .= " | + | |
- | //if (($_IPS[' | + | if ($d){ |
- | if ($_IPS[' | + | $msg .= " |
- | | + | $msg .= print_r($_IPS, true); |
- | if ($value == $_IPS[' | + | |
- | $msg .= " | + | |
- | $run = false; | + | |
- | } | + | |
} | } | ||
- | if (($_IPS[' | + | |
- | $value = $_IPS[' | + | if ($_IPS[' |
+ | //On Manual Execute check child events and set Event Trigger to "On Change" | ||
+ | foreach (IPS_GetChildrenIDs($_IPS[' | ||
+ | if (IPS_GetObject($value)[' | ||
+ | IPS_SetEventTrigger($value, | ||
+ | } | ||
+ | } | ||
+ | } else { | ||
+ | if (($_IPS[' | ||
+ | if ($_IPS[' | ||
+ | //$value = (GetValueBoolean($_IPS[' | ||
+ | $value = ($_IPS[' | ||
+ | } | ||
+ | if (($_IPS[' | ||
+ | $value = ($_IPS[' | ||
+ | } | ||
+ | |||
+ | if (($value == (GetValueBoolean($_IPS[' | ||
+ | if($d){ $msg .= " | ||
+ | $run = false; | ||
+ | } | ||
+ | |||
+ | if ($d){ | ||
+ | $msg .= " | ||
+ | } | ||
+ | |||
+ | $topic = explode(";", | ||
+ | |||
+ | if((strlen($topic) > 3) and ($run)){ | ||
+ | if ($d){ | ||
+ | $msg .= " | ||
+ | $msg .= " | ||
+ | $msg .= " | ||
+ | $msg .= " | ||
+ | } | ||
+ | MQTT_Publish($idMQTTBroker , $topic ,$value ,1 , true); | ||
+ | } | ||
+ | } | ||
} | } | ||
- | if ($d){ $msg .= " | ||
- | $id = $_IPS[' | ||
- | $topic = explode(";", | ||
- | if((strlen($topic) > 3) and ($run)){ | ||
- | switch(IPS_GetVariable($id)[' | ||
- | case 0: //boolean | ||
- | if($value == 1){ $value = " | ||
- | break; | ||
- | case 1: //Integer | ||
- | |||
- | | ||
- | case 2: //float | ||
- | |||
- | | ||
- | case 3: //string | ||
- | |||
- | | ||
- | } | ||
- | if($d){ $msg .= " | ||
- | MQTT_Publish(50729 / | ||
- | } | ||
- | |||
- | if ($d){ $msg .= " | ||
- | |||
| | ||
| | ||
} | } | ||
- | ?> | + | ?></ |
- | </ | + | |
Das Eigentliche Script welces die Daten per RPC vom mqttwarn Daemon entgegennimmt und ablegt, in dem nicht Vergessen die ID's in den ersten Zeilen durch die Eigenen ersetzen: | Das Eigentliche Script welces die Daten per RPC vom mqttwarn Daemon entgegennimmt und ablegt, in dem nicht Vergessen die ID's in den ersten Zeilen durch die Eigenen ersetzen: | ||
Zeile 107: | Zeile 128: | ||
// mqtt topic to symcon variable id mapping | // mqtt topic to symcon variable id mapping | ||
$idParent = IPS_GetParent($_IPS[' | $idParent = IPS_GetParent($_IPS[' | ||
- | $archiveId = 32289 / | + | $archiveId = 32289; |
- | $relaisScriptId = 17676 / | + | $relaisScriptId = 17676; //Relais Script ID |
// get value from mqtt variable | // get value from mqtt variable | ||
if( array_key_exists(" | if( array_key_exists(" | ||
- | $var = $_IPS[' | + | $topic = $_IPS[' |
- | $varsplit = explode(";", | + | |
- | + | | |
- | $topic = $_IPS[' | + | |
- | $topics = explode("/", | + | |
- | $payload = $_IPS[' | + | |
- | + | if ($d){ $msg .= " | |
- | // | + | |
- | //$topics = explode("/", | + | // Datentyp der payload herausfinden und ins Format für IPS Übersetzen |
- | // | + | |
- | // | + | if (is_float($payload+0)){ |
- | $payload = str_replace(array(" | + | |
- | + | | |
- | if ($d){ $msg .= " | + | } |
- | + | if (($contType == 99) and (is_numeric($payload))){ | |
- | // Datentyp der payload herausfinden und ins Format für IPS Übersetzen | + | |
- | $contType = 99; | + | |
- | if (is_float($payload+0)){ | + | } |
- | //Float | + | if (($contType == 99) and (is_string($payload))){ |
- | $contType = 2; | + | if ((strtolower($payload) == " |
- | } | + | //Boolean |
- | if (($contType == 99) and (is_numeric($payload))){ | + | $contType = 0; |
- | //Integer | + | } else { |
- | $contType = 1; | + | //String |
- | } | + | $contType = 3; |
- | if (($contType == 99) and (is_string($payload))){ | + | } |
- | if ((strtolower($payload) == " | + | } |
- | //Boolean | + | $idf = $idParent; |
- | $contType = 0; | + | // |
- | } else { | + | |
- | //String | + | if ($i == (count($topics) -1)){ |
- | $contType = 3; | + | $type = 2; |
- | } | + | } else { |
- | } | + | $type = 0; |
- | $idf = $idParent; | + | } |
- | //Pfad durchlaufen und Prüfen ob die Kategorien / Variablen vorhanden sind und bei bedarf Anlegen | + | $idf = checkIfElementExists($idf, |
- | for($i = 0; $i < count($topics); | + | } |
- | if ($i == (count($topics) -1)){ | + | |
- | $type = 2; | + | |
- | } else { | + | |
- | $type = 0; | + | |
- | } | + | } |
- | $idf = checkIfElementExists($idf, | + | |
- | } | + | |
- | + | ||
- | if($d){ | + | //mqset($idf, $payload); |
- | $msg .= " | + | SetValue($idf, $payload); |
- | $msg .= "Set Itend to: " | + | |
- | } | + | |
- | + | ||
- | // | + | |
- | IPS_SetIdent($idf, | + | |
- | + | ||
- | //if (GetValue($idf) != $payload){ | + | |
- | //Wert Setzen | + | |
- | mqset($idf, $payload); | + | |
} | } | ||
if ((strlen($msg) > 0) and ($d)){ | if ((strlen($msg) > 0) and ($d)){ | ||
Zeile 183: | Zeile 195: | ||
function mqset($id, $value){ | function mqset($id, $value){ | ||
+ | Global $msg, $d; | ||
if(GetValue($id) != $value){ | if(GetValue($id) != $value){ | ||
switch(IPS_GetVariable($id)[" | switch(IPS_GetVariable($id)[" | ||
case 0: // boolean | case 0: // boolean | ||
- | $val = filter_var($value, | + | $val = filter_var($value, |
+ | if($d){ $msg .= "val: " | ||
SetValue($id, | SetValue($id, | ||
break; | break; | ||
Zeile 230: | Zeile 244: | ||
} | } | ||
IPS_SetName($id, | IPS_SetName($id, | ||
- | IPS_SetParent($id, | + | |
- | if($type == 2){ // Variable | + | if($type == 2){ // Variable |
- | | + | |
- | if (strpos(" | + | if (strpos(" |
- | | + | |
- | | + | |
- | | + | |
- | } elseif(strpos(" | + | } elseif(strpos(" |
- | IPS_SetVariableCustomProfile($id, | + | |
- | } elseif ($name == " | + | } elseif ($name == " |
- | IPS_SetVariableCustomProfile($id, | + | |
- | } else { | + | } else { |
- | //Wenn es eine Boolean Variable ist das Profile ~Switch zuweisen | + | |
- | IPS_SetVariableCustomProfile($id, | + | |
- | IPS_SetVariableCustomAction($id, | + | |
- | checkCreateEvent($id, | + | |
- | } | + | } |
- | } | + | |
- | if (strpos(" | + | |
- | | + | IPS_SetVariableCustomProfile($id, |
- | } | + | |
- | if (strpos(" | + | |
- | | + | IPS_SetVariableCustomProfile($id, |
- | } | + | |
- | if (strpos(" | + | |
- | | + | IPS_SetVariableCustomProfile($id, |
- | } | + | |
IPS_SetInfo($id, | IPS_SetInfo($id, | ||
// | // | ||
- | | + | AC_SetLoggingStatus($archiveId, |
- | IPS_ApplyChanges($archiveId); | + | |
} | } | ||
} | } | ||
Zeile 285: | Zeile 299: | ||
} | } | ||
if ($create){ | if ($create){ | ||
- | //Event Anlegen | + | |
- | $eid = IPS_CreateEvent(0); | + | $eid = IPS_CreateEvent(0); |
- | IPS_SetEventTrigger($eid, | + | IPS_SetEventTrigger($eid, |
- | IPS_SetParent($eid, | + | IPS_SetParent($eid, |
IPS_SetEventActive($eid, | IPS_SetEventActive($eid, | ||
} | } | ||
} | } | ||
?></ | ?></ | ||
- | ==== Mosquitto (MQTT Broker) ==== | + | |
+ | ==== MQTT Broker | ||
aptitude install mosquitto mosquitto-clients python-pip git -y | aptitude install mosquitto mosquitto-clients python-pip git -y | ||
| |