solettaproject / soletta

Soletta Project is a framework for making IoT devices. With Soletta Project's libraries developers can easily write software for devices that control actuators/sensors and communicate using standard technologies. It enables adding smartness even on the smallest edge devices.
http://solettaproject.org
Apache License 2.0
225 stars 109 forks source link

OIC realistic example #732

Open barbieri opened 9 years ago

barbieri commented 9 years ago

We should provide a realistic OIC sample where devices are discovered and paired to be used together without using node options to specify the other endpoint.

We should have a node type to discover OIC devices implementing a given interface. Once these are discovered, they are sent to a "selector" node type that will pick one. The selected one is persisted and then used by further actions specific to that device interface.

A suggested approach is for the OIC device discoverer to emit a custom information packet with an array of items, each being composed of an identifier, a human readable name and possibly an icon (or a type). Alternatively it may produce packets of a single item that are accumulated by the selector -- in this case the selector would need a RESET or CLEAR port to flush items.

The selectors should be generic and work with the packets specified above (they could live in Soletta's core and not in oic module). Two selectors we could offer by default are:

NOTE: this task doesn't need to implement all of the selectors, only one is enough. In such case please create a task for the other selector.

The result of the selector is to be persisted and feeded back to the selector.

The proposed test FBP is:

# Declare Nodes
oic_discoverer(oic/device-discoverer:interface="core.brightlight")
brightlight_selector(http-server/selector:path="brightlight-selector")
brightlight_selector_trigger(http-server/boolean:path="start-brightlight-selector",value=false)
brightlight_persistence(persistence/string:name="brightlight",storage="efivars")
brightlight(oic/client-brightlight)
light_switch(gpio/reader:pin=123)

# Connect Discovery, Selection and Persistence flows
brightlight_selector_trigger OUT -> ENABLED oic_discoverer
oic_discoverer ITEMS -> ITEMS brightlight_selector
brightlight_selector SELECTED -> IN brightlight_persistence
brightlight_persistence OUT -> SELECTED brightlight_selector
brightlight_persistence OUT -> DEVICE_ID brightlight

light_switch OUT -> POWER brightlight

When the user restart the device, then the oic_discoverer will be inactive (ENABLED=false), since brightlight_selector_trigger is false. Then the brightlight_selector has no items to show or to select. However brightlight_persistence has a value stored and will send an initial packet, that is fed to brightlight. Once the light_switch is pressed the light will turn on.

To select a new OIC device, the user should visit a HTML/JS page. This page will GET /start-bright-light-selector?value=true, this will start oic_discoverer (ENABLED=true), sending packets to brightlight_selector. The JS will keep polling GET /brightlight-selector and update the user interface. Once the user selects an item, the JS will POST /brightlight-selector?selected=XXX. Then the brightlight_selector validates this is a known ID and if so will send XXX on its SELECTED output port. This goes to brightlight_persistence that saves to EFI and then forwards XXX on its OUT port, that ends into brightlight's DEVICE_ID port.

NOTE: I'm not happy with brightlight_selector_trigger, particularly with it being a boolean. If the user closes the browser without setting it to false, then it will keep discovering. We can work-around this with a timeout and resetting it to false once the brightlight_selector sends a SELECTED id, but that's cumbersome. We need to find a better way :-( However the ENABLED port in the oic_discoverer matches nicely with the same-name port in the LCD selector above. It would be started (set to true) after some event (ie: long press) and would be reset to false once SELECTED is sent.

barbieri commented 9 years ago

@glima please consider helping with the String output + Buttons Input selector. You did the grove/lcd-string and this selector output should be something we feed to that node.

bdilly commented 9 years ago

We may use it on foosball demo. I've added an OIC interface so table can talk to scoreboard. No pairing was implemented.