Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: generalize number of thing picos

...

Code Block
  rule mischief_subscriptions {
    select when mischief subscriptions
    pre {
      mischief = ent:mischief
      thing1 = ent:things[0]
foreach ent:things setting(thing,index)
     thing2 = ent:things[1]
    }
    if mischief && thing1 && thing2 then every {
      event:send(
        { "eci": mischief, "eid": "subscription",
          "domain": "wrangler", "type": "subscription",
          "attrs": { "name": "thing1",
                     "Rx_role": "thing",
                     "Tx_role": "controller",
                     "channel_type": "subscription",
                     "wellKnown_Tx": thing1 } } )// introduce mischief pico to thing[index] pico
      event:send(
        { "eci": ent:mischief, "eid": "subscription",
          "domain": "wrangler", "type": "subscription",
          "attrs": { "name": "thing" + (index.as("thing2Number")+1),
                     "Rx_role": "thing",
                     "Tx_role": "controller",
                     "channel_type": "subscription",
                     "wellKnown_Tx": thing2thing } } )
    }
  }

The ruleset also sets up a button in the owner pico's Testing tab, "mischief/subscriptions" to send the event that causes this rule to evaluate. Navigate to the Testing tab for the Owner Pico to click on this button, which will cause the mischief_subscriptions rule to evaluate and make the subscription requests to all of the thing picos.

The final step is that a rule selecting on wrangler/inbound_pending_subscription_added is in each of the thing picos (the ruleset mischief.thing), and this will complete the subscription process. The rule looks like this:

...