Recent Changes - Search:

edit SideBar

Discovery developer's guide

Ptolemy host instructions

  1. See Ptolemy II (Platforms Wiki) for information about getting started with Ptolemy II.
  2. Open the model at: $PTII/ptolemy/actor/lib/jjs/modules/discovery/demo/Discovery.xml
  3. Run the model. A list of devices, macs and names will be displayed.
  4. The Ptolemy implementation uses threads to execute pings of individual IP addresses concurrently.

Problems

Name prints as ?; IP and MAC are fine

Unfortunately, there are many possible causes of a local name resolution issue. Local name resolution happens through a variety of protocols. The protocol used is machine-dependent.

Under Mavericks (Mac OS X 10.9.x), the following did not work, Command-7 did not bring up the Bonjour Services, nor was it available in the View menu. Wireless Diagnostics (2013/06/08) states that Bonjour Services was removed in Mac OS X 10.8.4 and still not present in Yosemite OS X 10.10 Yosemite Beta 3.

http://www.cnet.com/news/use-wi-fi-diagnostics-to-find-active-bonjour-services-in-os-x/ states:

"For Mac please try the following:"

  • "Check that devices show up in the Bonjour Services browser in the Wi-Fi diagnostic utility (Mountain Lion and up)." Not present in Mavericks (10.9)
    • "Open the utility from the /System/Library/CoreServices/ folder or hold the Option key before clicking the Wi-Fi menu bar icon."
    • "Open the Wi-Fi diagnostics. In this utility, press Command-7 or choose Bonjour Services from the View menu."
    • "The tool will list each service that is available from computers on the local network."

Under Mavericks (Mac OS X 10.9), Safari can be used to browse Bonjour:

Bonjour has stopped working states:

"Note that you can enable a Bonjour browser function in Safari. Open Safari preferences, select Advanced and you will see a Bonjour section where you can add Bonjour to your Favorites bar. With this selected you will see all Bonjour devices on your local network."

  1. In Safari: Preferences -> Advanced. Under Bonjour, select "Include Bonjour in the Favorites Menu"
  2. In Safari: Bookmarks -> Bonjour should list local Bonjour devices like a printer

If devices are missing, it is possible that those devices do not support Bonjour, or that your router does not support Bonjour.

  • Check your router's multicast configuration settings.
    • For Linksys routers, enable "Filter Multicast". See link below. (True for other routers??)
    • For Linksys routers, disable "AP Isolation". See link below.
    • Some Belkin routers seem to not support Bonjour.

https://community.linksys.com/t5/Wireless-Routers/Routers-compatible-with-Airplay-and-Bonjour/td-p/493842
https://discussions.apple.com/thread/2696161?tstart=0

  • Check that your Mac has the correct IP address for your router. There might be a mismatch e.g. if you recently got a new router.

Sys Prefs -> Network -> highlight Interface you use -> Advanced -> DNS tab
https://discussions.apple.com/thread/6471194

  • If Windows machine names are not being resolved, try enabling Windows File Sharing.

"On the Mac turn on Windows file-sharing. That will then activate Samba on the Mac, and lets it query NetBIOS names directly. It seems to configure WINS correctly, automatically, although irritatingly hidden. With the sharing on, most Windows operations seems to work easier."

10.5: Sys Prefs -> Sharing -> File Sharing -> Options
10.4 and lower: Sys Prefs -> Sharing -> Windows File Sharing

http://serverfault.com/questions/13337/os-x-cant-resolve-windows-machine-names

Running fails with ArrayToken(Token[]) called with a an array of length less than 1.

java.lang.RuntimeException: ptolemy.kernel.util.IllegalActionException: ArrayToken(Token[]) called with a an array of length less than 1.  To create an array of length 0, use the ArrayToken(Token) constructor or the "emptyArray(type)" function in the expression language. The reason is that elements in ArrayToken must have a type.

An interim fix for this was checked in to localFunctions.js to set the type of any empty array. The type is currently set to String. In the long term, the correct array type should be determined somehow. Edward writes:

"In localFunctions.js, we could modify convertToToken() to take an optional second argument, the port proxy, which is an instance of JavaScript.PortOrParameterProxy. If the second argument is provided, it could be used to resolve type ambiguities.

To do this, we would need to augment PortOrParameterProxy with a method like getType(). This would return the type of the port. This could then be used in the JavaScript code to decide what type of ArrayToken to create.

Alternatively, and perhaps easier, would be to create a more specialized method in PortOrParameterProxy, say getArrayElementType() that returns an instance of Type if the type of the port is an array, and return null otherwise. Then the JS code could change to:"

  if (proxy) {
    var type = proxy.getArrayElementType();
    if (type) {
       return new ArrayToken(type);
    }
  }
  // No type information available, so convert to an empty [string] array
  return new ArrayToken(BaseType.STRING);

AccessorJS host instructions

  1. Follow the instructions on the AccessorJS wiki to pull the AccessorJS repository and run the test code.
  2. Discovery requires the rsvp library for Node. (TODO: Should we add non-core libraries to package.json for automatic setup? Or is this clutter?) From the base directory where you have downloaded the AccessorJS repo, run:
    npm install rsvp
  3. On Linux, there's a case-sensitivity problem with the XMLHttpRequest library. In /core/acc-base.js, change line 16 to use a lowercase xmlhttprequest for the package name.:
    var XMLHttpRequest = require('xmlhttprequest').XMLHttpRequest;
  4. Run. A list of devices with names, IP addresses and MAC addresses should be displayed. From the base directory:
    node ./swarmlets/discoverySwarmletTest.js
  5. Alternatively, discovery can be run from the Node REPL command line. From the base directory:
    node
    require('babel/register');
    child_process = require('child_process');
    EventEmitter = require('events').EventEmitter;
    rsvp = require('rsvp');
    E = require('./swarmlets/discoverySwarmlet'); true;
    E.discovery();

AccessorJS currently uses the XML version of the accessor specification.

Node.js host instructions

The Node implementation uses Javascript Promises to ping devices asynchronously, then wait until all pings are finished before performing an arp command, then producing the results on the devices port.

Install Node.js, pull SwarmOS repository, run setup scripts

See: http://www.terraswarm.org/platforms/wiki/Main/NodeJsAccessors

Quick instructions:

  1. Download the swarmos repo
    git clone https://repo.eecs.berkeley.edu/git/projects/terraswarm/swarmos.git
  2. Build in hosts
    cd swarmos/{$HOSTS_NODE}
    ./build.sh
  3. Build in swarmos/hosts/browser
    cd ../browser
    ./build.sh

Roll back accessor.js to get Accessor.makeFromURL()

This accessor uses an old version of swarmos/hosts/browser/public/scripts/accessor.js. Specifically, it requires the Accessor.makeFromURL() method, from version 3a32018 of the SwarmOS repository or earlier.

  1. After running (cd ../browser; ./build.sh) above, which copies swarmos/hosts/browser/public/scripts/accessor.js to swarmos/hosts/node/accessor.js
  2. Copy swarmos/hosts/node/accessor-to-be-copied.js to swarmos/hosts/node/accessor.js
    cd swarmos/{$HOSTS_NODE}
    cp accessor-to-be-copied.js accessor.js

Start fileserver.js

Change to the swarmos/hosts/node directory, and type:

node fileserver.js&

This will start a fileserver to serve the accessor from your local machine.

Problem: Unhandled 'error' event: EACESS

Under Mac OS X, the error here is that port 80 is not open.

bash-3.2$ node fileserver.js&
[2] 16020
bash-3.2$ Listening on port 80
events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: listen EACCES
    at exports._errnoException (util.js:746:11)
    at Server._listen2 (net.js:1112:19)
    at listen (net.js:1155:10)
    at Server.listen (net.js:1240:5)
    at EventEmitter.app.listen (/Users/cxh/src/swarmos-git/{$HOSTS_NODE}/{$ACCESSORS_MODULES}/express/lib/application.js:595:24)
    at Object.<anonymous> (/Users/cxh/src/swarmos-git/{$HOSTS_NODE}/fileserver.js:13:5)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)

If an error like this occurs, try changing the port number. Port 80 seems to work on Windows and port 1337 on Linux and Mac OS X. Change the port in both /hosts/node/discoverhost.js and /hosts/node/fileserver.js.

Run discoverhost.js

In the swarmos/hosts/node directory, type:

node discoverhost.js

Problem: Running discoverhost.js fails to find makeFromURL

bash-3.2$ node discoverhost.js
Run 'testST1()''
/Users/cxh/src/swarmos-git/{$HOSTS_NODE}/discoverhost.js:38
Accessor.makeFromURL(accessorURL, function(accessor) {
        ^
TypeError: Cannot read property '
makeFromURL' of undefined
    at Object.<anonymous> (/Users/cxh/src/swarmos-git/{$HOSTS_NODE}/discoverhost.js:38:9)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)
    at startup (node.js:129:16)
    at node.js:814:3
bash-3.2$

See Roll back accessor.js to get Accessor.makeFromURL()

Correct operation

Each device will be echoed to the screen as it is found. Then, the output of the accessor will be displayed. The accessor outputs a JSON object containing the IP, name and MAC of each device.

[cxh@terra node]$ node discoverhost.js
Fired
Device available at 128.32.48.1
Device available at 128.32.48.21
Device available at 128.32.48.23
Device available at 128.32.48.26
Device available at 128.32.48.29
Device available at 128.32.48.31
Device available at 128.32.48.34
Device available at 128.32.48.39
Device available at 128.32.48.41
Device available at 128.32.48.42
Device available at 128.32.48.43
Device available at 128.32.48.46
...
Device available at 128.32.48.249
Device available at 128.32.48.250
Device available at 128.32.48.251
Device available at 128.32.48.77
128.32.48.1: {"name":"cory115-1-gw.EECS.Berkeley.EDU","mac":"cc:4e:24:6d:90:80"}
128.32.48.21: {"name":"cronus.CS.Berkeley.EDU","mac":"00:e0:81:5c:85:0a"}
128.32.48.23: {"name":"rhea.CS.Berkeley.EDU","mac":"00:e0:81:58:38:61"}
128.32.48.26: {"name":"dhcp-48-26.EECS.Berkeley.EDU","mac":"ec:a8:6b:f6:32:36"}
128.32.48.29: {"name":"dhcp-48-29.EECS.Berkeley.EDU","mac":"f8:b1:56:a2:22:dd"}
128.32.48.31: {"name":"dhcp-48-31.EECS.Berkeley.EDU","mac":"b8:ca:3a:b1:dc:a2"}
128.32.48.34: {"name":"dhcp-48-34.EECS.Berkeley.EDU","mac":"c8:1f:66:13:f5:fb"}
128.32.48.39: {"name":"dhcp-48-39.EECS.Berkeley.EDU","mac":"f8:b1:56:a2:25:9c"}
128.32.48.41: {"name":"dhcp-48-41.EECS.Berkeley.EDU","mac":"ec:a8:6b:f6:56:3b"}
128.32.48.42: {"name":"dhcp-48-42.EECS.Berkeley.EDU","mac":"f8:bc:12:5d:f2:77"}
...

Browser

This accessor does not run in a browser due to requiring the ping and arp commands from the OS.

Swarmbox Map

A swarmbox may choose to post device info to the swarmbox map hosted on terra.
https://terra.eecs.berkeley.edu:8088/swarmboxes.html

Note that this page is public. Any device info posted will be public.

Usage

A device should POST the (possibly filtered) output of the Discovery accessor to:

http://terra.eecs.berkeley.edu:8088/hosts/{hostname}/devices

where {hostname} is the swarmbox's name. Note this assumes each swarmbox has a unique name, which isn't true for the current set of swarmboxes, since some have "unassigned-hostname". Please assign your swarmbox a name.

A GET request to the above URL will return a JSON array of devices connected to that swarmbox.

Device information is not currently saved in persistent storage.

Examples

In the Ptolemy tree under $PTII/ptolemy/actor/lib/jjs/modules/discovery/demo/Discovery,

  • PostSwarmboxDevices.xml discovers and posts devices for a single swarmbox
  • PopulateSwarmboxMap.xml posts some sample data
  • discoverylistener.js contains server-side code

Issues

  • Ptolemy model
  • Node
    • The node installation takes a number of steps, including copying an older accessor-to-be-copied.js to accessor.js.
    • The port number needs to be entered into two places
    • How often should this run and how should it be reported?

See Also


Back to Optional JavaScript Modules

Edit - History - Print - Recent Changes - Search
Page last modified on May 01, 2017, at 08:34 PM