Your SlideShare is downloading. ×
dSS API by example
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

dSS API by example

5,734

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
5,734
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. dS S A PI by example Patrick S tählin, futureLA B A G pstaehlin@futurelab.ch
  • 2. Demo setup dSS Serial dSID dSM 230V MacBook RS485 Device
  • 3. Demo
  • 4. Include model.js [...] <script src="js/model.js" language="JavaScript" type="text/javascript"> </script> [...]
  • 5. S etup js functions [...] function turnOn() { (new Device("3F...")).turnOn(); } [...] function turnOff() { (new Device("3F...")).turnOff(); }
  • 6. Hook it up [...] <a href="javascript:turnOn()">Turn on</a> <a href="javascript:turnOff()">Turn off</a> [...]
  • 7. Recap ● Put .html into webroot of dSS ● Include /js/model.js ● Code! ;-)
  • 8. Avoid code like that [...] function turnOn() { (new Device("3F...1")).turnOn(); (new Device("3F...2")).turnOn(); (new Device("3F...3")).turnOn(); } [...] function turnOff() { (new Device("3F...1")).turnOff(); (new Device("3F...2")).turnOff(); (new Device("3F...3")).turnOff(); }
  • 9. Use sets [...] function turnOn() { (new Set(".addDevices(3F...1, 3F...2, 3F...3)")).turnOn(); } [...] function turnOff() { (new Set(".addDevices(3F...1, 3F...2, 3F...3)")).turnOff(); }
  • 10. S ets ● Arbitrary list of devices ● Optimized bus use ● Possibility to persist (to be implemented)
  • 11. S et syntax ● '.' starts at the root (all Devices) ● .name restricts to a group/zone/device with that name ● Special functions ● .dsid() ● .fd() ● .group() ● .zone()
  • 12. S et syntax cont. ● Set operations ● .add(set) ● .remove(set) ● .empty() ● .addDevices(3f..., 'dev1 ...) ',
  • 13. Examples ● All devices . (< dot) - ● All yellow (light emitting) devices .yellow ● All yellow devices and media devices (magenta) .yellow.add(.magenta) ● All yellow device in zone 3 .zone(3).yellow
  • 14. Events [...] function turnOn() { (new HEvent('arriving', '.addDevices(3F...)')).raise(); } [...] function turnOff() { (new HEvent('leaving', '.addDevices(3F...)')).raise(); } [...]
  • 15. Event ● Name ● Context (Source) ● Location (Target) ● Parameter
  • 16. S ubscriptions ● Filter ● Action ● Loaded from data/subscriptions.xml
  • 17. Subscriptions dS-Bus Subscriptions Subscriptions calls handleEvent() on every matching Subscription Event Queue Interpreter SOAP Web (J SON)
  • 18. Internaly raised events ● „callScene“ translates into: ● „bell“ as in door-bell ● „alarm“ ● „panic“ ● „model_ready“ ● „modulator_ready“ ● More to come, check the wiki
  • 19. subscriptions.xml [...] <subscription event-name="call" handler-name="raise_event"> <parameter> <parameter name="event_name">sendBell</parameter> </parameter> <flter match="all"> <property-flter type="matches" value="0797428986" property="source" /> </flter> </subscription> [...]
  • 20. Default handler ● „raise_event“ raises a new event when ● „bus_handler“ do stuf on the dS bus (like turnOn/turnOf) ● „javascript“ call a script
  • 21. Subscriptions J avaScript J avaScript dS-Bus Subscriptions Subscriptions calls handleEvent() on every matching Subscription Event Queue Interpreter SOAP Web (J SON)
  • 22. S cripting inside the dS S ● SpiderMonkey ● Access to all objects inside the dSS ● Device ● Group ● Zone ● Set ● Event ● Subscription ● Access to the property tree
  • 23. Property tree ● Tree ● Strings, Ints and booleans (extensible) ● Changes can be observed (register listeners) ● Accessible from SOAP, J SON ● Partially persistent
  • 24. Property node changes ● Call code (C+ ) inside the dSS + ● Call script callback inside the dSS
  • 25. How to use properties ● Save the states between diferent runs ● External inputs (e.g. outside temperature from WebService) ● Automatic unit conversion
  • 26. S ave the state between runs var count = getProperty('/test/counter'): if(count === null) { count = 0; } count++; setProperty('/test/counter', count);
  • 27. Count number of visitors initialize.js: var s = subscription('bell', 'javascript', {'flename': 'counter.js'}); s.subscribe();
  • 28. Count number of visitors initialize.js: var s = subscription('bell', 'javascript', {'flename': 'counter.js'}); s.subscribe(); counter.js: var count = getProperty('/test/counter'): if(count === null) { count = 0; } count++; setProperty('/test/counter', count);
  • 29. Converting values setListener('/temperature/outside-celsius', function(prop) { setProperty('/temperature/outside-fahrenheit', (9/5) * getValue(prop) + 32); } );
  • 30. External inputs setListener('/temperature/outside-celsius', function(prop) { setProperty('/heater/histeresis', (50 - (getValue(prop))/10); } );
  • 31. Further uses ● Create a proxy device in J S to integrate your gadgets ● Samples in the wiki
  • 32. Questions? pstaehlin@futurelab.ch
  • 33. Thank you!

×