Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

·         As per request, OldValue and OldKnown have been added to the subscription messages. They contain previous values of value and known respectively.

 


Code Block
languagexml
firstline0
titleThingFacet Camera Example
<ThingFacet#
ThingFacet(name=: "Esky">):
      <Sid name=Sid(name: "CameraId"/>)
      <String name=String(name: "URL"/>)
      <String name=String(name: "UserName"/>)
      <String name=String(name: "Password"/>)
      <String name=String(name: "State", KnownBy: KnownBy="SyncImage,SyncPreset"/>)
      <String name=String(name: "Image", KnownBy: KnownBy="SyncImage"/>)
      <String name=String(name: "Preset", KnownBy=: "SyncPreset"/>)
      <Unique name=Unique(name: "Camera", value=: "URL"/>)
      
      <!--# Helpers
-->      AA: <AA>[:#o#Event.Argument:]</AA>
      <UP>userUP: user=[%:[:AA:].UserName.Value:%][%:amp:%]pwd=[%:[:AA:].Password.Value:%]</UP>
      POK: <POK>InvokeInvoke/SetPreset/Message/starts-with(Value, 'ok')</POK>
      IOK: <IOK>InvokeInvoke/GetImage/Message/starts-with(Value, 'data')</IOK>

      <!--# Actions --> 
     <Action Action(name=: "SyncPreset", documentation=: "Synchronize camera state and preset">):
        <WorkflowWorkflow Limit=: "1", Live=: "1", Timeout=: "PT20S">):
            <Task name=Task(name: "Main", while=: "true">):
                <Event name=Event(name: "Argument", as=: "ActionArgument"/>)                
               <Invoke Invoke(name=: "SetPreset", 
     waitFor=             waitFor: "Argument", 
                  skip-if=: "[%:[:AA:].Preset/no-value(Value):%]" delayAfter="PT5S", 
                  delayAfter: "PT5S"
                  get=: "[%:[:AA:].URL.Value:%]/cgi-bin/decoder_control.cgi?[:UP:][%:amp:%]command=15[%:amp:%]sit=[%:[:AA:].Preset.Value:%]"/>)                  
               <Output Output(name=: "Result", as=: "ActionResult">):
                    <Value>Value:
                        <State>State: [%:[%:@Output:%]/if([:POK:]) then 'ON' else 'OFF':%]</State>
                        Preset: <Preset>[%:[%:@Output:%]/if([:POK:]) then '[%:[:AA:].Preset.Value:%]' else null():%]</Preset>
                    </Value>    
            </Output>
            </Task>
        </Workflow>
      </Action>
      <Action name=Action(name: "SyncImage", documentation=: "Synchronize camera state and snapshot image">):
        <WorkflowWorkflow Limit=: "1", Live=: "1", Timeout=: "PT10S">
            <Task name=Task(name: "Main", while=: "true">):
                <Event name=Event(name: "Argument", as=: "ActionArgument"/>)
                <Invoke name=Invoke(name: "GetImage", waitFor=: "Argument", delay=: "PT1S"
                        get=: "[%:[:AA:].URL.Value:%]/cgi-bin/video_snapshot.cgi?[:UP:]"/>)
                <Output name=Output(name: "Result", as=: "ActionResult">):
                    <Value>Value:
                        <State>State: [%:[%:@Output:%]/if([:IOK:]) then 'ON' else 'OFF':%]</State>
                        Image: <Image>[%:[%:@Output:%]/if([:IOK:]) then Invoke/GetImage/Message/Value/text() else '/img/no-image.jpg':%]</Image>
                    </Value>
                </Output>
            </Task>
        </Workflow>
      </Action>
    </ThingFacet>