{"id":20885464,"url":"https://github.com/lab11/accessor-files","last_synced_at":"2026-04-21T12:33:33.711Z","repository":{"id":31745344,"uuid":"35311416","full_name":"lab11/accessor-files","owner":"lab11","description":"Accessor JavaScript files","archived":false,"fork":false,"pushed_at":"2015-07-10T04:11:14.000Z","size":560,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-01-19T10:43:38.262Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lab11.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-05-09T02:17:41.000Z","updated_at":"2015-05-09T02:18:20.000Z","dependencies_parsed_at":"2022-08-29T15:52:31.478Z","dependency_job_id":null,"html_url":"https://github.com/lab11/accessor-files","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab11%2Faccessor-files","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab11%2Faccessor-files/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab11%2Faccessor-files/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lab11%2Faccessor-files/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lab11","download_url":"https://codeload.github.com/lab11/accessor-files/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243267322,"owners_count":20263799,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-18T08:13:34.947Z","updated_at":"2025-12-25T12:29:43.853Z","avatar_url":"https://github.com/lab11.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"Accessor Files Repository\n=========================\n\nThis is the global file repository for the [accessors project](https://github.com/lab11/accessors).\n\nIn general, we encourage any and all contributions for accessors.\nRequests to change or add interfaces will generally require some\ndiscussion as interfaces are global in impact and live forever.\n\nFor more information on what this project is,\nplease [visit the project homepage](https://github.com/lab11/accessors).\n\n\nWhat Makes an Accessor an Accessor?\n-----------------------------------\n\nAccessors are wrappers around devices that channel all interactions with\ndevices through ports. The accessor starts by defining what the ports should\nbe, what the data types of those ports should be, and if they are inputs\nto the device, outputs, or both. Then the accessor is simply responsible\nfor handling input data and sending output data.\n\nThe key to accessors is they are flexible enough to support a very wide\nrange of devices (or other services) while still providing a reasonably\nstandard interface that makes using them intuitive. Accessors are designed\nto be used to create applications, both in accessor-specific environments\nand embedded into other and existing projects.\n\n\n\nHow to Write an Accessor\n------------------------\n\nThe first step to creating an accessor is to define what ports it should\nhave. What are the common interaction patterns with the device? What is\nwritten to the device, and what is read from it? Does the device output\ndata on its own? These data flows should be captured with ports.\n\nThe ports of the accessor are defined in the `setup()` function. New ports\ncan be created with the `createPort()` function. However, it may be more\nuseful to first start with a defined _interface_. Interfaces are groupings\nof common ports that similar devices may all want to implement. This allows\naccessors and devices to be conveniently grouped based on which interfaces\nthey provide. Interfaces are found in the `interfaces` folder.\n\n```javascript\nfunction setup () {\n\t// This device can be turned on and off, so we use the /onoff interface.\n\t// Now this can be grouped with all devices that can be turned on and off.\n\tprovideInterface('/onoff');\n\n\t// Our device also has a neat feature where it can beep when turned off.\n\t// We must specify how the user can interact with this port. In this case,\n\t// we can read the status of the setting and write it to change it.\n\tcreatePort('BeepOnOff', ['read', 'write']);\n}\n```\n\nWhen an accessor is loaded, the first thing it must do is initialize.\nEach accessor typically provides an `init()` function that sets it up.\nTwo main things happen in `init`: 1) Functions are mapped to handle data\nthat comes in from ports, and 2) A connection to the device is established\n(if necessary).\n\n```javascript\nfunction* init () {\n\t// When data is written to the \"Power\" port, call the power_input\n\t// function.\n\taddInputHandler('/onoff.Power', power_input);\n\n\t// We also want to handle when users read from ports.\n\taddOutputHandler('BeepOnOff', beep_output);\n}\n\n// This function will be called when the device is turned on and off.\nfunction power_input (state) {\n\t// `state` is the data that was passed to the port\n}\n\n// This function will be called when the user wants to know if the beep\n// is enabled or not.\nfunction beep_output () {\n}\n```\n\nThe main operation of the accessor after it is initialized is to _get_\ndata from input ports and to _send_ data to output ports. The accessor\ncan call `get(\u003cport_name\u003e)` to get the most recent data that was written\nto an input port, and `send(\u003cport_name\u003e, data)` to output data.\n\n```javascript\nfunction beep_out () {\n\tvar beep_status = yield* http.get('192.168.7.2/beep');\n\tsend('BeepOnOff', beep_status.body == 'true');\n}\n```\n\nAccessors can also setup ports that spontaneously output data.\n\n```javascript\nvar coap = require('coapClient');\n\nfunction setup () {\n\t// Setup a motion port that will output `true` any time there is\n\t// motion in front of our hypothetical PIR sensor.\n\t// We cannot set or query the sensor, but it will generate events\n\t// anytime there is motion.\n\tcreatePort('Motion', ['event']);\n}\n\nfunction* init () {\n\t// Setup a CoAP observe call that will tell the sensor to notify\n\t// us whenever motion occurs.\n\tcoap.observe('[aaaa::0123:abcd]/motion', function (val) {\n\t\t// Whenever the observe sends us data, this function will get called.\n\t\t// From here, we send to the output port so anything listening\n\t\t// will be notified that motion occurred.\n\t\tsend('Motion', true);\n\t});\n}\n```\n\nTo see more of what accessors can do, browse the existing accessors. Accessors\nsupport many communication and discovery protocols, including HTTP, CoAP, web\nsockets, AMQP, SSDP, MDNS, and others.\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flab11%2Faccessor-files","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flab11%2Faccessor-files","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flab11%2Faccessor-files/lists"}