From a95806456dd77c51f85d193f4644d0dcc79518f9 Mon Sep 17 00:00:00 2001 From: ft-Demo <fischertechnik-team@fischer.de> Date: Tue, 8 Nov 2022 09:57:40 +0000 Subject: [PATCH] commit by robo pro coding --- lib/NodeRED.blockly | 523 ++++++++++++++++++++++++++++---------------- lib/NodeRED.py | 39 +++- 2 files changed, 360 insertions(+), 202 deletions(-) diff --git a/lib/NodeRED.blockly b/lib/NodeRED.blockly index 3ae2cda..502da58 100644 --- a/lib/NodeRED.blockly +++ b/lib/NodeRED.blockly @@ -29,7 +29,153 @@ <block type="util_python_imports" id="l-w#:2(*$u(EYdsy=A93" x="0" y="0"> <field name="value">#TXT FW 3.1.0: https://pypi.org/project/paho-mqtt/1.3.1/&#10;&#10;import paho.mqtt.client as mqtt&#10;import json&#10;from datetime import datetime&#10;import logging</field> </block> - <block type="procedures_defnoreturn" id=")uU.pE+gxp-xV{l06;]^" x="0" y="206"> + <block type="procedures_defnoreturn" id="qn*eC1u~xJda3N0eHbi7" x="0" y="206"> + <field name="NAME">thread_updateColorValue</field> + <statement name="STACK"> + <block type="loop_endless" id="n7hjG.$:dLO^J{Rt!}hz"> + <statement name="DO"> + <block type="controls_if" id="zvwz]C4l`AIHCZ#GSzqG"> + <mutation elseif="1"/> + <value name="IF0"> + <block type="logic_compare" id="YfeRjy%bVB+Ta7=H]04E"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get" id="YqHWKituo($6AUepV.9T"> + <field name="VAR" id=")XfA{xXx7sN)MA=qSY=H">gtyp_Setup_i_Color_Sensor_Selection</field> + </block> + </value> + <value name="B"> + <block type="math_number" id="UxRn.,h]cyfEp(3=]3Bn"> + <field name="NUM">1</field> + </block> + </value> + </block> + </value> + <statement name="DO0"> + <block type="util_python" id="8{Ak;0^Xd-6UI={%VIRZ" inline="true"> + <field name="value">logging.debug('1')</field> + <next> + <block type="variables_set" id="@]9Nx4f|FaKRqmvoAi7w"> + <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field> + <value name="VALUE"> + <block type="import_function_return" id=")M#DicoI*=@O^jZnE;oS"> + <mutation parentId="![`j=,+%Mnlx`Drv~HID"/> + <field name="name">readDPSColorValue</field> + <data>![`j=,+%Mnlx`Drv~HID</data> + </block> + </value> + <next> + <block type="mqtt_publish" id="9l^L4yPf$IRk.ep*nKQg"> + <value name="name"> + <block type="variables_get" id="(B(o!H:Fo=/V+93j1_t%"> + <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field> + </block> + </value> + <value name="topic"> + <shadow type="text" id="Eu+?@98L*qi!dOs?:y1{"> + <field name="TEXT">gtyp_Setup/w_Actual_ColorValue</field> + </shadow> + </value> + <value name="value"> + <shadow type="logic_null"/> + <block type="variables_get" id="7`~oM[V`d#?Yi5k@vI6A"> + <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field> + </block> + </value> + <value name="qos"> + <shadow type="math_number" id="jGD,g*hg~`:Q4%2~AU5@"> + <field name="NUM">2</field> + </shadow> + </value> + <value name="retain"> + <shadow type="logic_boolean" id="v}(DXul.N3_CQJ_fRj,O"> + <field name="BOOL">FALSE</field> + </shadow> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + <value name="IF1"> + <block type="logic_compare" id="`MC=d;7=`;TO#d8cS0,n"> + <field name="OP">EQ</field> + <value name="A"> + <block type="variables_get" id=":Bo/{JYI0%n|:B!GRp_P"> + <field name="VAR" id=")XfA{xXx7sN)MA=qSY=H">gtyp_Setup_i_Color_Sensor_Selection</field> + </block> + </value> + <value name="B"> + <block type="math_number" id="Jpe~!Jf0@,:NTGcd_~Jt"> + <field name="NUM">2</field> + </block> + </value> + </block> + </value> + <statement name="DO1"> + <block type="util_python" id="jw=$ozm$vmR+/ZrbsgxW" inline="true"> + <field name="value">logging.debug('2')</field> + <next> + <block type="variables_set" id=";b,Xj$#gxX+raC)3wD6k"> + <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field> + <value name="VALUE"> + <block type="import_function_return" id="%TX;`Di-?u.+9)/@Nv{#"> + <mutation parentId="$]uSxm9]*Qu3iZl~w~MW"/> + <field name="name">readColorValue</field> + <data>$]uSxm9]*Qu3iZl~w~MW</data> + </block> + </value> + <next> + <block type="mqtt_publish" id="uXStLM:3x0VmB$7,z]qO"> + <value name="name"> + <block type="variables_get" id="VpTg?J$0v@CQGvi?6biA"> + <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field> + </block> + </value> + <value name="topic"> + <shadow type="text" id="I_U7+;@]ay];]@J;GO[C"> + <field name="TEXT">gtyp_Setup/w_Actual_ColorValue</field> + </shadow> + </value> + <value name="value"> + <shadow type="logic_null"/> + <block type="variables_get" id="h%gJS#zVEu@NM}r=~Aep"> + <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field> + </block> + </value> + <value name="qos"> + <shadow type="math_number" id="naG*$w|A4peeTcF{PDS+"> + <field name="NUM">2</field> + </shadow> + </value> + <value name="retain"> + <shadow type="logic_boolean" id="%%PD}fIRB^[mb`1d}}/T"> + <field name="BOOL">FALSE</field> + </shadow> + </value> + </block> + </next> + </block> + </next> + </block> + </statement> + <next> + <block type="util_wait_for" id="CX68oVxSvTujYpdu.eWs"> + <field name="format">s</field> + <value name="value"> + <shadow type="math_number" id="uv.b,zxC/N=(v6AOUKuG"> + <field name="NUM">1</field> + </shadow> + </value> + </block> + </next> + </block> + </statement> + </block> + </statement> + </block> + <block type="procedures_defnoreturn" id=")uU.pE+gxp-xV{l06;]^" x="0" y="651"> <mutation> <arg name="topic" varid="J0n.(S2c_J^ul.Ya```o" argid="o[hL6u/X-Hh$Q2+P#$+Z"/> <arg name="m_decode" varid="tfig7HBYbEq22iBgastC" argid="Hbe2WDx-@,*Wg@:(`|^."/> @@ -1280,129 +1426,125 @@ <block type="util_python" id="soiv=1GYGk1x%q@maBVQ" inline="true"> <field name="value">logging.debug('1')</field> <next> - <block type="import_function_noreturn" id="mYNNZg)WPJlr:~$ufsec" inline="true"> - <mutation parentId=":J%zX-c=Y4mZAR)aLyUn"/> - <field name="name">set_calib_data_DPS</field> - <data>:J%zX-c=Y4mZAR)aLyUn</data> - <value name="_data"> - <block type="import_function_return" id="@;JC1=}]#34K48sx$z:f"> - <mutation parentId="Q9p7dhe-|x*[t`L^}||B"/> - <field name="name">get_calib_data_DPS</field> - <data>Q9p7dhe-|x*[t`L^}||B</data> + <block type="variables_set" id="#qTi4fJvDN/gHpGR,QZL"> + <field name="VAR" id="TZ7zEdrg=Q,vG9XutiCF">gtyp_SSC_w_Threshold_Red_Blue</field> + <value name="VALUE"> + <block type="lists_getIndex" id="XHjGd8WI?lk^D`I(D#b="> + <mutation statement="false" at="true"/> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="import_function_return" id="sY?[vd+tT0Nu7cz+s-nI"> + <mutation parentId="Q9p7dhe-|x*[t`L^}||B"/> + <field name="name">get_calib_data_DPS</field> + <data>Q9p7dhe-|x*[t`L^}||B</data> + </block> + </value> + <value name="AT"> + <block type="math_number" id="0*d]I4B_:$fDgz,^vuWz"> + <field name="NUM">1</field> + </block> + </value> </block> </value> <next> - <block type="variables_set" id="]U{J=*zkyz1_tdI~ahab"> - <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field> + <block type="variables_set" id="D:=f2wh[w8ZBWyd[g(7}"> + <field name="VAR" id="-XOZ;@M!{qgTA%xgUef-">gtyp_SSC_w_Threshold_White_Red</field> <value name="VALUE"> - <block type="import_function_return" id="@L.Vk]qUp2Qx=/=#/mf;"> - <mutation parentId="![`j=,+%Mnlx`Drv~HID"/> - <field name="name">readDPSColorValue</field> - <data>![`j=,+%Mnlx`Drv~HID</data> + <block type="lists_getIndex" id="wdG`|Kmg=qcF]7y]s%/Y"> + <mutation statement="false" at="true"/> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="import_function_return" id="nkoTt5*j.7AKXq.ht:mP"> + <mutation parentId="Q9p7dhe-|x*[t`L^}||B"/> + <field name="name">get_calib_data_DPS</field> + <data>Q9p7dhe-|x*[t`L^}||B</data> + </block> + </value> + <value name="AT"> + <block type="math_number" id="{2;D6h`S7C3wQ-4YG}9K"> + <field name="NUM">2</field> + </block> + </value> </block> </value> <next> - <block type="variables_set" id="#qTi4fJvDN/gHpGR,QZL"> - <field name="VAR" id="TZ7zEdrg=Q,vG9XutiCF">gtyp_SSC_w_Threshold_Red_Blue</field> - <value name="VALUE"> - <block type="lists_getIndex" id="XHjGd8WI?lk^D`I(D#b="> - <mutation statement="false" at="true"/> - <field name="MODE">GET</field> - <field name="WHERE">FROM_START</field> - <value name="VALUE"> - <block type="import_function_return" id="sY?[vd+tT0Nu7cz+s-nI"> - <mutation parentId="Q9p7dhe-|x*[t`L^}||B"/> - <field name="name">get_calib_data_DPS</field> - <data>Q9p7dhe-|x*[t`L^}||B</data> + <block type="import_function_noreturn" id="Gk9cR?Lk;JuWjdFN6g21" inline="true"> + <mutation parentId=":J%zX-c=Y4mZAR)aLyUn"/> + <field name="name">set_calib_data_DPS</field> + <data>:J%zX-c=Y4mZAR)aLyUn</data> + <value name="_data"> + <block type="lists_create_with" id="Xocv8$Q*^`iZ8_evooz$"> + <mutation items="2"/> + <value name="ADD0"> + <block type="variables_get" id="B~w0/Kt$OccNl)@ly!xg"> + <field name="VAR" id="-XOZ;@M!{qgTA%xgUef-">gtyp_SSC_w_Threshold_White_Red</field> </block> </value> - <value name="AT"> - <block type="math_number" id="0*d]I4B_:$fDgz,^vuWz"> - <field name="NUM">1</field> + <value name="ADD1"> + <block type="variables_get" id="0r9m2Pv0tVeq~+`ES0JB"> + <field name="VAR" id="TZ7zEdrg=Q,vG9XutiCF">gtyp_SSC_w_Threshold_Red_Blue</field> </block> </value> </block> </value> <next> - <block type="variables_set" id="D:=f2wh[w8ZBWyd[g(7}"> - <field name="VAR" id="-XOZ;@M!{qgTA%xgUef-">gtyp_SSC_w_Threshold_White_Red</field> - <value name="VALUE"> - <block type="lists_getIndex" id="wdG`|Kmg=qcF]7y]s%/Y"> - <mutation statement="false" at="true"/> - <field name="MODE">GET</field> - <field name="WHERE">FROM_START</field> - <value name="VALUE"> - <block type="import_function_return" id="nkoTt5*j.7AKXq.ht:mP"> - <mutation parentId="Q9p7dhe-|x*[t`L^}||B"/> - <field name="name">get_calib_data_DPS</field> - <data>Q9p7dhe-|x*[t`L^}||B</data> - </block> - </value> - <value name="AT"> - <block type="math_number" id="{2;D6h`S7C3wQ-4YG}9K"> - <field name="NUM">2</field> - </block> - </value> + <block type="mqtt_publish" id="q*l)lLvQ+gq071=B?@^C"> + <value name="name"> + <block type="variables_get" id="F,Y)cUZYs0lOI-L0=p.l"> + <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field> </block> </value> + <value name="topic"> + <shadow type="text" id=")`awz#27RX.sH,6*)B6)"> + <field name="TEXT">gtyp_SSC/w_Threshold_White_Red</field> + </shadow> + </value> + <value name="value"> + <shadow type="logic_null"/> + <block type="variables_get" id="SGGyieKA!!R@(D$b/RSW"> + <field name="VAR" id="-XOZ;@M!{qgTA%xgUef-">gtyp_SSC_w_Threshold_White_Red</field> + </block> + </value> + <value name="qos"> + <shadow type="math_number" id="8{srU/E?AVvW$Dd[(}l]"> + <field name="NUM">2</field> + </shadow> + </value> + <value name="retain"> + <shadow type="logic_boolean" id="vXK,eAojF*2ouQ1Jd#tp"> + <field name="BOOL">FALSE</field> + </shadow> + </value> <next> - <block type="mqtt_publish" id="q*l)lLvQ+gq071=B?@^C"> + <block type="mqtt_publish" id="E#Pgwk-H%6WI!+Zg@xS)"> <value name="name"> - <block type="variables_get" id="F,Y)cUZYs0lOI-L0=p.l"> + <block type="variables_get" id="R3n.;F-Yx`_%3T(IqW~h"> <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field> </block> </value> <value name="topic"> - <shadow type="text" id=")`awz#27RX.sH,6*)B6)"> - <field name="TEXT">gtyp_SSC/w_Threshold_White_Red</field> + <shadow type="text" id="E`^{fo{,)eHSu{:O/6.V"> + <field name="TEXT">gtyp_SSC/w_Threshold_Red_Blue</field> </shadow> </value> <value name="value"> <shadow type="logic_null"/> - <block type="variables_get" id="SGGyieKA!!R@(D$b/RSW"> - <field name="VAR" id="-XOZ;@M!{qgTA%xgUef-">gtyp_SSC_w_Threshold_White_Red</field> + <block type="variables_get" id="jQ}sKf~Op2Pr:-kx:TM#"> + <field name="VAR" id="TZ7zEdrg=Q,vG9XutiCF">gtyp_SSC_w_Threshold_Red_Blue</field> </block> </value> <value name="qos"> - <shadow type="math_number" id="8{srU/E?AVvW$Dd[(}l]"> + <shadow type="math_number" id="J#pZ^?|%;:t7Amwb9W(W"> <field name="NUM">2</field> </shadow> </value> <value name="retain"> - <shadow type="logic_boolean" id="vXK,eAojF*2ouQ1Jd#tp"> + <shadow type="logic_boolean" id="_dEw,Az-T1[gzI?|=7f*"> <field name="BOOL">FALSE</field> </shadow> </value> - <next> - <block type="mqtt_publish" id="E#Pgwk-H%6WI!+Zg@xS)"> - <value name="name"> - <block type="variables_get" id="R3n.;F-Yx`_%3T(IqW~h"> - <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field> - </block> - </value> - <value name="topic"> - <shadow type="text" id="E`^{fo{,)eHSu{:O/6.V"> - <field name="TEXT">gtyp_SSC/w_Threshold_Red_Blue</field> - </shadow> - </value> - <value name="value"> - <shadow type="logic_null"/> - <block type="variables_get" id="jQ}sKf~Op2Pr:-kx:TM#"> - <field name="VAR" id="TZ7zEdrg=Q,vG9XutiCF">gtyp_SSC_w_Threshold_Red_Blue</field> - </block> - </value> - <value name="qos"> - <shadow type="math_number" id="J#pZ^?|%;:t7Amwb9W(W"> - <field name="NUM">2</field> - </shadow> - </value> - <value name="retain"> - <shadow type="logic_boolean" id="_dEw,Az-T1[gzI?|=7f*"> - <field name="BOOL">FALSE</field> - </shadow> - </value> - </block> - </next> </block> </next> </block> @@ -1434,136 +1576,125 @@ <block type="util_python" id="x0s]$+:+=z@PJ!naMKFJ" inline="true"> <field name="value">logging.debug('2')</field> <next> - <block type="import_function_noreturn" id="M[HH9m7FQXc%HGGy.8WI" inline="true"> - <mutation parentId="3Qf0~|~$oG8z5tP{6Km;"/> - <field name="name">set_calib_data_SLD</field> - <data>3Qf0~|~$oG8z5tP{6Km;</data> - <value name="_data"> - <block type="import_function_return" id="(5oQM![;])v/u0pcD6MD"> - <mutation parentId="b|1;0mU=wNNO2Ry{f6,Z"/> - <field name="name">get_calib_data_SLD</field> - <data>b|1;0mU=wNNO2Ry{f6,Z</data> + <block type="variables_set" id="A;mMGOnf}=G4)(mUTBXB"> + <field name="VAR" id="z}xxgCaN^$Fn.vEFUV}F">gtyp_SLD_w_Threshold_Red_Blue</field> + <value name="VALUE"> + <block type="lists_getIndex" id="l8(^@0LFn@VRt!9bbB@y"> + <mutation statement="false" at="true"/> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="import_function_return" id="[.lX-%{ZA`0XE/8@wh;6"> + <mutation parentId="b|1;0mU=wNNO2Ry{f6,Z"/> + <field name="name">get_calib_data_SLD</field> + <data>b|1;0mU=wNNO2Ry{f6,Z</data> + </block> + </value> + <value name="AT"> + <block type="math_number" id="#RosQS*Pqqky0x=BGHqe"> + <field name="NUM">1</field> + </block> + </value> </block> </value> <next> - <block type="variables_set" id="WAf,+!7J@v2-:Q$D}WRy"> - <field name="VAR" id=")(=M[8QEW5[mGL@9Axsu">gtyp_Setup_w_Actual_ColorValue</field> + <block type="variables_set" id="V$q[G}}_EqKbXxUdXZ?y"> + <field name="VAR" id="x43W3)orCB:l1qw2dLN`">gtyp_SLD_w_Threshold_White_Red</field> <value name="VALUE"> - <block type="import_function_return" id="lBF}3ws,,6TpfF}C;_a%"> - <mutation parentId="$]uSxm9]*Qu3iZl~w~MW"/> - <field name="name">readColorValue</field> - <data>$]uSxm9]*Qu3iZl~w~MW</data> + <block type="lists_getIndex" id="-dw.:I!+I-1Z}iqg+9wq"> + <mutation statement="false" at="true"/> + <field name="MODE">GET</field> + <field name="WHERE">FROM_START</field> + <value name="VALUE"> + <block type="import_function_return" id="BynbVL(FDhK[^6E+Y]|%"> + <mutation parentId="b|1;0mU=wNNO2Ry{f6,Z"/> + <field name="name">get_calib_data_SLD</field> + <data>b|1;0mU=wNNO2Ry{f6,Z</data> + </block> + </value> + <value name="AT"> + <block type="math_number" id="xKD0g;L20Gs#1K{x-1;t"> + <field name="NUM">2</field> + </block> + </value> </block> </value> <next> - <block type="variables_set" id="A;mMGOnf}=G4)(mUTBXB"> - <field name="VAR" id="z}xxgCaN^$Fn.vEFUV}F">gtyp_SLD_w_Threshold_Red_Blue</field> - <value name="VALUE"> - <block type="lists_getIndex" id="l8(^@0LFn@VRt!9bbB@y"> - <mutation statement="false" at="true"/> - <field name="MODE">GET</field> - <field name="WHERE">FROM_START</field> - <value name="VALUE"> - <block type="import_function_return" id="[.lX-%{ZA`0XE/8@wh;6"> - <mutation parentId="b|1;0mU=wNNO2Ry{f6,Z"/> - <field name="name">get_calib_data_SLD</field> - <data>b|1;0mU=wNNO2Ry{f6,Z</data> + <block type="import_function_noreturn" id="Twr{}nGXl9MjW6,@,f^6" inline="true"> + <mutation parentId="3Qf0~|~$oG8z5tP{6Km;"/> + <field name="name">set_calib_data_SLD</field> + <data>3Qf0~|~$oG8z5tP{6Km;</data> + <value name="_data"> + <block type="lists_create_with" id="Ar*9SF:w!Zi*LJb+vR$a"> + <mutation items="2"/> + <value name="ADD0"> + <block type="variables_get" id="5LE(f|rMXJdX?@qBB}g|"> + <field name="VAR" id="x43W3)orCB:l1qw2dLN`">gtyp_SLD_w_Threshold_White_Red</field> </block> </value> - <value name="AT"> - <block type="math_number" id="#RosQS*Pqqky0x=BGHqe"> - <field name="NUM">1</field> + <value name="ADD1"> + <block type="variables_get" id="ne!!9tj/;#5{p)T|dNmP"> + <field name="VAR" id="z}xxgCaN^$Fn.vEFUV}F">gtyp_SLD_w_Threshold_Red_Blue</field> </block> </value> </block> </value> <next> - <block type="variables_set" id="V$q[G}}_EqKbXxUdXZ?y"> - <field name="VAR" id="x43W3)orCB:l1qw2dLN`">gtyp_SLD_w_Threshold_White_Red</field> - <value name="VALUE"> - <block type="lists_getIndex" id="-dw.:I!+I-1Z}iqg+9wq"> - <mutation statement="false" at="true"/> - <field name="MODE">GET</field> - <field name="WHERE">FROM_START</field> - <value name="VALUE"> - <block type="import_function_return" id="BynbVL(FDhK[^6E+Y]|%"> - <mutation parentId="b|1;0mU=wNNO2Ry{f6,Z"/> - <field name="name">get_calib_data_SLD</field> - <data>b|1;0mU=wNNO2Ry{f6,Z</data> - </block> - </value> - <value name="AT"> - <block type="math_number" id="xKD0g;L20Gs#1K{x-1;t"> - <field name="NUM">2</field> - </block> - </value> + <block type="mqtt_publish" id="6fC(-bBrwzAL(!f*ENq9"> + <value name="name"> + <block type="variables_get" id="!8D6PQ)C0:iovvEj~?6f"> + <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field> + </block> + </value> + <value name="topic"> + <shadow type="text" id="h2D6M*w}QakoV=9S]vcz"> + <field name="TEXT">gtyp_SLD/w_Threshold_White_Red</field> + </shadow> + </value> + <value name="value"> + <shadow type="logic_null"/> + <block type="variables_get" id="10DmxbPw;Kh6~X?xC^@="> + <field name="VAR" id="x43W3)orCB:l1qw2dLN`">gtyp_SLD_w_Threshold_White_Red</field> </block> </value> + <value name="qos"> + <shadow type="math_number" id="f=LX{[z|sxhgBKhzMc7@"> + <field name="NUM">2</field> + </shadow> + </value> + <value name="retain"> + <shadow type="logic_boolean" id="CZ4g*FL?4Mk=lj62[*yr"> + <field name="BOOL">FALSE</field> + </shadow> + </value> <next> - <block type="mqtt_publish" id="6fC(-bBrwzAL(!f*ENq9"> + <block type="mqtt_publish" id="StL0d;=/[ck2._O_Id.("> <value name="name"> - <block type="variables_get" id="!8D6PQ)C0:iovvEj~?6f"> + <block type="variables_get" id="N]59T`b2jIc;_qGW2?hE"> <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field> </block> </value> <value name="topic"> - <shadow type="text" id="h2D6M*w}QakoV=9S]vcz"> - <field name="TEXT">gtyp_SLD/w_Threshold_White_Red</field> + <shadow type="text" id="9W@f;@ZG8JRhbU#pQb%V"> + <field name="TEXT">gtyp_SLD/w_Threshold_Red_Blue</field> </shadow> </value> <value name="value"> <shadow type="logic_null"/> - <block type="variables_get" id="10DmxbPw;Kh6~X?xC^@="> - <field name="VAR" id="x43W3)orCB:l1qw2dLN`">gtyp_SLD_w_Threshold_White_Red</field> + <block type="variables_get" id=".$OApgnU$;Ks5QCN7=.?"> + <field name="VAR" id="z}xxgCaN^$Fn.vEFUV}F">gtyp_SLD_w_Threshold_Red_Blue</field> </block> </value> <value name="qos"> - <shadow type="math_number" id="f=LX{[z|sxhgBKhzMc7@"> + <shadow type="math_number" id="P@?U|z5SZY6k/NQSSaLr"> <field name="NUM">2</field> </shadow> </value> <value name="retain"> - <shadow type="logic_boolean" id="CZ4g*FL?4Mk=lj62[*yr"> + <shadow type="logic_boolean" id=",B[1dxL!]ME%M)JCM)@^"> <field name="BOOL">FALSE</field> </shadow> </value> - <next> - <block type="mqtt_publish" id="StL0d;=/[ck2._O_Id.("> - <value name="name"> - <block type="variables_get" id="N]59T`b2jIc;_qGW2?hE"> - <field name="VAR" id="d2.J:01W*;j`8R0B1!GX">client</field> - </block> - </value> - <value name="topic"> - <shadow type="text" id="9W@f;@ZG8JRhbU#pQb%V"> - <field name="TEXT">gtyp_SLD/w_Threshold_Red_Blue</field> - </shadow> - </value> - <value name="value"> - <shadow type="logic_null"/> - <block type="variables_get" id=".$OApgnU$;Ks5QCN7=.?"> - <field name="VAR" id="z}xxgCaN^$Fn.vEFUV}F">gtyp_SLD_w_Threshold_Red_Blue</field> - </block> - </value> - <value name="qos"> - <shadow type="math_number" id="P@?U|z5SZY6k/NQSSaLr"> - <field name="NUM">2</field> - </shadow> - </value> - <value name="retain"> - <shadow type="logic_boolean" id=",B[1dxL!]ME%M)JCM)@^"> - <field name="BOOL">FALSE</field> - </shadow> - </value> - <next> - <block type="import_function_noreturn" id="c{=w9)lmtKb$uKpfh|f1"> - <mutation parentId="g=6%Ka9Y1qYH|_c:bu9]"/> - <field name="name">startSLD</field> - <data>g=6%Ka9Y1qYH|_c:bu9]</data> - </block> - </next> - </block> - </next> </block> </next> </block> @@ -1652,6 +1783,11 @@ <field name="BOOL">TRUE</field> </shadow> </value> + <next> + <block type="util_thread" id=")SPIj;?BLx$B!m^#*GxD"> + <field name="dropdown_event">qn*eC1u~xJda3N0eHbi7</field> + </block> + </next> </block> </next> </block> @@ -1882,6 +2018,13 @@ </value> </block> </value> + <next> + <block type="import_function_noreturn" id="c{=w9)lmtKb$uKpfh|f1"> + <mutation parentId="g=6%Ka9Y1qYH|_c:bu9]"/> + <field name="name">startSLD</field> + <data>g=6%Ka9Y1qYH|_c:bu9]</data> + </block> + </next> </block> </next> </block> @@ -1922,10 +2065,10 @@ </block> </value> <next> - <block type="import_function_noreturn" id="hUp?s=y@zf/dV9Kdg3fJ" inline="true"> - <mutation parentId="VSmATTY?.L[C{f,=c#1:"/> - <field name="name">set_calibvalue_white</field> - <data>VSmATTY?.L[C{f,=c#1:</data> + <block type="import_function_noreturn" id="whAV8d/04#02f*fp7z8d" inline="true"> + <mutation parentId="L]1+4A^?Yt^]vOcR=Sf5"/> + <field name="name">set_calibvalue_blue</field> + <data>L]1+4A^?Yt^]vOcR=Sf5</data> <value name="v"> <block type="math_number" id="D]m:m}L4P~4,ZKK%6,4b"> <field name="NUM">0</field> @@ -2455,7 +2598,7 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="$jNNx1Oeez9#x~eQYP}z" x="0" y="7078"> + <block type="procedures_defnoreturn" id="$jNNx1Oeez9#x~eQYP}z" x="0" y="7551"> <field name="NAME">initMQTTLocal</field> <statement name="STACK"> <block type="variables_set" id="_C*fQdBXqrGb1uUWi?_1"> @@ -2551,7 +2694,7 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="R4vMowGJ0I?IYs_!-IwU" x="0" y="7590"> + <block type="procedures_defnoreturn" id="R4vMowGJ0I?IYs_!-IwU" x="0" y="8063"> <field name="NAME">thread_MQTTLocal</field> <statement name="STACK"> <block type="util_python" id="IiRVsU4_~OPjE]@(VC;/" inline="true"> @@ -2567,7 +2710,7 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="8u`{W^33E#gAnZ}n#.-h" x="0" y="7850"> + <block type="procedures_defnoreturn" id="8u`{W^33E#gAnZ}n#.-h" x="0" y="8323"> <mutation> <arg name="client" varid="d2.J:01W*;j`8R0B1!GX" argid="_4Lef8L=}Do}$CNf.$X3"/> <arg name="userdata" varid="3^jP4hL~~1UKs+hYG]M=" argid=".~Cx#%[dpU*oKQFZ*1}G"/> @@ -2805,7 +2948,7 @@ </block> </statement> </block> - <block type="procedures_defnoreturn" id="a]0!I}Zd7AawL:mU%,P1" x="0" y="8644"> + <block type="procedures_defnoreturn" id="a]0!I}Zd7AawL:mU%,P1" x="0" y="9117"> <mutation> <arg name="client" varid="d2.J:01W*;j`8R0B1!GX" argid="`n4M@;+Y^Ab44Gi.YYy-"/> <arg name="userdata" varid="3^jP4hL~~1UKs+hYG]M=" argid="]gLOm[vhCT0;N+Cp[1?5"/> diff --git a/lib/NodeRED.py b/lib/NodeRED.py index 452dafd..97f2c17 100644 --- a/lib/NodeRED.py +++ b/lib/NodeRED.py @@ -1,6 +1,8 @@ import json import logging import paho.mqtt.client as mqtt +import threading +import time from datetime import datetime from fischertechnik.mqtt.MqttClient import MqttClient @@ -29,9 +31,9 @@ gtyp_Setup_x_Set_Pos_Activ = None gtyp_Setup_i_Pos_Selection = None payload = None gtyp_Setup_x_Color_Sensor_Calibration = None -state_positioning = None gtyp_Setup_i_Color_Sensor_Selection = None gtyp_Setup_w_Actual_ColorValue = None +state_positioning = None gtyp_Setup_w_Threshold_White_Red = None gtyp_Setup_w_Threshold_Red_Blue = None gtyp_Setup_di_Pos_Rotate = None @@ -45,8 +47,22 @@ controller_name = None gtyp_Setup_di_Pos_Horizontal = None +def thread_updateColorValue(): + global topic, m_decode, client, userdata, flags, rc, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, state_positioning, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SSC_w_Threshold_Red_Blue, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal + while True: + if gtyp_Setup_i_Color_Sensor_Selection == 1: + logging.debug('1') + gtyp_Setup_w_Actual_ColorValue = readDPSColorValue() + client.publish(topic='gtyp_Setup/w_Actual_ColorValue', payload=gtyp_Setup_w_Actual_ColorValue, qos=2, retain=False) + elif gtyp_Setup_i_Color_Sensor_Selection == 2: + logging.debug('2') + gtyp_Setup_w_Actual_ColorValue = readColorValue() + client.publish(topic='gtyp_Setup/w_Actual_ColorValue', payload=gtyp_Setup_w_Actual_ColorValue, qos=2, retain=False) + time.sleep(1) + + def processReceivedMessage(topic, m_decode): - global client, userdata, flags, rc, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SSC_w_Threshold_Red_Blue, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal + global client, userdata, flags, rc, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, state_positioning, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SSC_w_Threshold_Red_Blue, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal logging.log(logging.TRACE0, '%s %s', topic, m_decode) if topic == 'gtyp_Setup/x_Set_Pos_Activ': logging.debug('activate') @@ -148,21 +164,18 @@ def processReceivedMessage(topic, m_decode): client.publish(topic='gtyp_Setup/w_Threshold_Red_Blue', payload=gtyp_Setup_w_Threshold_Red_Blue, qos=2, retain=False) if gtyp_Setup_i_Color_Sensor_Selection == 1: logging.debug('1') - set_calib_data_DPS(get_calib_data_DPS()) - gtyp_Setup_w_Actual_ColorValue = readDPSColorValue() gtyp_SSC_w_Threshold_Red_Blue = (get_calib_data_DPS())[0] gtyp_SSC_w_Threshold_White_Red = (get_calib_data_DPS())[1] + set_calib_data_DPS([gtyp_SSC_w_Threshold_White_Red, gtyp_SSC_w_Threshold_Red_Blue]) client.publish(topic='gtyp_SSC/w_Threshold_White_Red', payload=gtyp_SSC_w_Threshold_White_Red, qos=2, retain=False) client.publish(topic='gtyp_SSC/w_Threshold_Red_Blue', payload=gtyp_SSC_w_Threshold_Red_Blue, qos=2, retain=False) elif gtyp_Setup_i_Color_Sensor_Selection == 2: logging.debug('2') - set_calib_data_SLD(get_calib_data_SLD()) - gtyp_Setup_w_Actual_ColorValue = readColorValue() gtyp_SLD_w_Threshold_Red_Blue = (get_calib_data_SLD())[0] gtyp_SLD_w_Threshold_White_Red = (get_calib_data_SLD())[1] + set_calib_data_SLD([gtyp_SLD_w_Threshold_White_Red, gtyp_SLD_w_Threshold_Red_Blue]) client.publish(topic='gtyp_SLD/w_Threshold_White_Red', payload=gtyp_SLD_w_Threshold_White_Red, qos=2, retain=False) client.publish(topic='gtyp_SLD/w_Threshold_Red_Blue', payload=gtyp_SLD_w_Threshold_Red_Blue, qos=2, retain=False) - startSLD() else: pass elif topic == 'gtyp_Setup/x_Color_Sensor_Calibration': @@ -171,6 +184,7 @@ def processReceivedMessage(topic, m_decode): if gtyp_Setup_x_Color_Sensor_Calibration == 'true': set_lights_mode(7) display.set_attr("txt_status_indicator.active", str(True).lower()) + threading.Thread(target=thread_updateColorValue, daemon=True).start() else: set_lights_mode(0) display.set_attr("txt_status_indicator.active", str(False).lower()) @@ -188,12 +202,13 @@ def processReceivedMessage(topic, m_decode): gtyp_Setup_w_Actual_ColorValue = readColorValue() gtyp_SLD_w_Threshold_Red_Blue = (get_calib_data_SLD())[0] gtyp_SLD_w_Threshold_White_Red = (get_calib_data_SLD())[1] + startSLD() else: logging.debug('none') gtyp_Setup_w_Actual_ColorValue = 0 set_calibvalue_white(0) set_calibvalue_red(0) - set_calibvalue_white(0) + set_calibvalue_blue(0) gtyp_SSC_w_Threshold_Red_Blue = 0 gtyp_SSC_w_Threshold_White_Red = 0 gtyp_SLD_w_Threshold_Red_Blue = 0 @@ -226,7 +241,7 @@ def processReceivedMessage(topic, m_decode): def initMQTTLocal(): - global topic, m_decode, client, userdata, flags, rc, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SSC_w_Threshold_Red_Blue, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal + global topic, m_decode, client, userdata, flags, rc, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, state_positioning, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SSC_w_Threshold_Red_Blue, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal gtyp_Setup_x_Set_Pos_Activ = 0 gtyp_Setup_i_Pos_Selection = 0 gtyp_Setup_x_Color_Sensor_Calibration = 0 @@ -244,7 +259,7 @@ def initMQTTLocal(): def thread_MQTTLocal(): - global topic, m_decode, client, userdata, flags, rc, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SSC_w_Threshold_Red_Blue, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal + global topic, m_decode, client, userdata, flags, rc, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, state_positioning, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SSC_w_Threshold_Red_Blue, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal logging.debug('-') #client.loop_forever() client.loop_start() @@ -253,7 +268,7 @@ def thread_MQTTLocal(): def on_connect(client, userdata, flags, rc): - global topic, m_decode, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SSC_w_Threshold_Red_Blue, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal + global topic, m_decode, msg, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, state_positioning, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SSC_w_Threshold_Red_Blue, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal print("Connection returned result: "+mqtt.connack_string(rc)) client.subscribe("#") #client.subscribe("$SYS/#") @@ -270,7 +285,7 @@ def on_connect(client, userdata, flags, rc): def on_message(client, userdata, msg): - global topic, m_decode, flags, rc, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, state_positioning, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SSC_w_Threshold_Red_Blue, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal + global topic, m_decode, flags, rc, gtyp_Setup_x_Set_Pos_Activ, gtyp_Setup_i_Pos_Selection, payload, gtyp_Setup_x_Color_Sensor_Calibration, gtyp_Setup_i_Color_Sensor_Selection, gtyp_Setup_w_Actual_ColorValue, state_positioning, gtyp_Setup_w_Threshold_White_Red, gtyp_Setup_w_Threshold_Red_Blue, gtyp_Setup_di_Pos_Rotate, gtyp_SSC_w_Threshold_Red_Blue, gtyp_SLD_w_Threshold_Red_Blue, gtyp_SSC_w_Threshold_White_Red, gtyp_SLD_w_Threshold_White_Red, gtyp_Setup_di_Pos_Vertical, ts, controller_name, gtyp_Setup_di_Pos_Horizontal #print("Received message '" + str(msg.payload) + "' on topic '" + msg.topic + "' with QoS " + str(msg.qos)) topic = msg.topic -- GitLab