├── .gitignore ├── .travis.yml ├── LICENSE ├── Makefile ├── README.md ├── bin └── init.js ├── components ├── configs │ └── io.flowchain.dropbox │ │ ├── access_token.config.json.default │ │ └── app.config.json.default ├── io.flowchain.dropbox.js ├── io.flowchain.fs.js └── io.flowchain.ntp.js ├── examples └── hello-world.js ├── graphs ├── console.json ├── dropbox.json ├── fs.json └── sms.json ├── lib └── main.js ├── package.json ├── screenshots └── usage0.gif └── test ├── run └── test.websocket.send.js /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | 6 | # Runtime data 7 | pids 8 | *.pid 9 | *.seed 10 | *.swp 11 | *.DS_Store 12 | 13 | # Directory for instrumented libs generated by jscoverage/JSCover 14 | lib-cov 15 | 16 | # Coverage directory used by tools like istanbul 17 | coverage 18 | 19 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 20 | .grunt 21 | 22 | # node-waf configuration 23 | .lock-wscript 24 | 25 | # Compiled binary addons (http://nodejs.org/api/addons.html) 26 | build/Release 27 | 28 | # Dependency directory 29 | node_modules 30 | 31 | # Optional npm cache directory 32 | .npm 33 | 34 | # Optional REPL history 35 | .node_repl_history 36 | 37 | # Configurations 38 | *.config.json -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '5' 4 | - '4' 5 | after_success: ./node_modules/.bin/codecov 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Flowchain Open Source Project 4 | 5 | Copyright (c) 2016-present, Jollen. All rights reserved. 6 | 7 | Permission is hereby granted, free of charge, to any person obtaining a copy 8 | of this software and associated documentation files (the "Software"), to deal 9 | in the Software without restriction, including without limitation the rights 10 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 | copies of the Software, and to permit persons to whom the Software is 12 | furnished to do so, subject to the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 | THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TESTS = $(shell find test/test.*.js) 2 | 3 | test: 4 | @./test/run $(TESTS) 5 | 6 | .PHONY: test -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](https://flowchain.io/fb0/images/logo-text%40128.png) 2 | 3 | Flowchain-app is an ultra light-weight runtime for flow-based IoT programming. 4 | 5 | # Flowchain 6 | 7 | You can write IoT server, serverless server or localhost server with Flowchain in flow-based programming. 8 | 9 | 10 | 11 | In the flowchain-app, IoT applications are described by a *Graph* in the JSON format. Flowchain-app can execute the graph as a service process (server) on various hardware, e.g., resource-constrained devices, single-board computers and desktops. 12 | 13 | ## Usage 14 | 15 | A easy way to start using flowchain-app is trying *console.json*. 16 | 17 | ``` 18 | $ git clone https://github.com/flowchain/flowchain.git 19 | $ cd flowchain 20 | $ npm install 21 | $ export HOST=192.168.0.100 22 | $ ./bin/init.js start graphs/console.json 23 | [devify] Starting coapBroker server... 24 | WoT/CoAP server is listening at coap://192.168.0.100:8000 25 | ``` 26 | 27 | Flowchain-app is now listening at the host assigned by ```HOST``` environment variable. You can also export the ```PORT``` variable to specify the listening port. 28 | 29 | ### Programing IoT device 30 | 31 | It is out of scope of flowchain-app. However, there is an example showing a sample in which send sensor data to flowchain-app over CoAP. The following example uses a NodeMCU (aka ESP8266) device with Lua programming language. 32 | 33 | ``` 34 | -- Configure the ESP as a station (client) 35 | wifi.setmode(wifi.STATION) 36 | wifi.sta.config("", "") 37 | wifi.sta.autoconnect(1) 38 | 39 | -- Create a CoAP client 40 | cc = coap.Client() 41 | 42 | -- Make a POST request 43 | uri="coap://192.168.0.100:8000/object/12345678/send" 44 | 45 | -- Setup a timer to send ADC data 46 | tmr.alarm(0, 1000, 1, function() 47 | buf = 48 | "{" .. 49 | "\"quality\":" .. 50 | adc.read(0) .. 51 | "}" 52 | 53 | cc:post(uri, buf) 54 | print(buf) 55 | end) 56 | ``` 57 | 58 | ## Programming Paradigm 59 | 60 | ### Graph 61 | 62 | Flowchain-app will execute the *console.json* file. The *console.json* is a sample graph described in JSON format. 63 | 64 | ``` 65 | { 66 | "author": "jollen", 67 | "type": "coapBroker", 68 | "connections": [ 69 | { 70 | "upproc": "io.flowchain.console", 71 | "upport": "out", 72 | "downproc": "io.flowchain.fs", 73 | "downport": "in" 74 | } 75 | ] 76 | } 77 | ``` 78 | 79 | The visual graph diagram is also shown as following. 80 | 81 | ![](https://cloud.githubusercontent.com/assets/1126021/17215664/409fd6ec-5510-11e6-80fb-371b6c3a724e.png) 82 | 83 | ### Component 84 | 85 | Flowchain-app components could be published as npm modules. One existing component is ```io.flowchain.console``` and accessible at [io.flowchain.console](https://www.npmjs.com/package/io.flowchain.console). 86 | 87 | ## Development Notes 88 | 89 | ### Write Your Graph 90 | 91 | There are several [flowchain graph examples](https://github.com/flowchain/flowchain/tree/master/graphs). 92 | 93 | ### Add a New Component 94 | 95 | 1. To develop custom components, please fork this example [io.flowchain.console](https://github.com/flowchain/io.flowchain.console). 96 | 97 | 2. Publish your component to npm. 98 | 99 | 3. Update package.json by ```npm install --save```. 100 | 101 | 4. Open ```lib/main.js``` file and require (include) your component into flowchain. 102 | 103 | ``` 104 | var components =[ 105 | ... 106 | require('io.flowchain.console') 107 | ]; 108 | ``` 109 | 110 | You could send a PR to [flowchain](https://github.com/flowchain/flowchain). All flowchain-app components will also be listed at the [flowchain.io](http://flowchain.io) website. 111 | 112 | ## Why and What 113 | 114 | * Instead of the classical monolithic application programming model. Flowchain-app is the flow-based programming. 115 | 116 | * Flowchain-app is a flow-based runtime for JavaScript IoT application server. 117 | 118 | * Flowchain-app is a better approach to write IoT application servers. 119 | 120 | * Flowchain-app is based on [devify-server](https://github.com/DevifyPlatform/devify-server). 121 | 122 | * Flowchain-app is one-way data flow design. 123 | 124 | ## Internals 125 | 126 | * Flowchain-app has a ultra-lightweight flow-based runtime called **fb0**. *fb0* is tiny with 300+ lines code. 127 | 128 | * Flowchain-app has CoAP/WebSocket URI-based protocol servers for interoperating with IoT devices. 129 | 130 | ## Credits 131 | 132 | Flowchain-app project is heavily inspired by [J. Paul Morrison](http://www.jpaulmorrison.com/) and FBP-like [NoFlo](https://github.com/noflo/noflo). 133 | 134 | *fb0* is a *FBP-like* system and is a JavaScript system motivated by [J. Paul Morrison](http://www.jpaulmorrison.com/), and which uses a number of the same terms and concepts. 135 | 136 | ## Roadmap 137 | 138 | * [2017] Building flowchain-app on [JerryScript](https://github.com/Samsung/jerryscript), an ultra-lightweight JavaScript engine for the Internet of Things. 139 | 140 | * [2017] React component binding with state stores and Flux pattern. 141 | 142 | * [2017] Serverless IoT in a simpilicy way. 143 | 144 | ## License 145 | 146 | Flowchain-app is released under the [MIT License](http://www.opensource.org/licenses/MIT). 147 | -------------------------------------------------------------------------------- /bin/init.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | require('../lib/main.js'); 4 | -------------------------------------------------------------------------------- /components/configs/io.flowchain.dropbox/access_token.config.json.default: -------------------------------------------------------------------------------- 1 | { "oauth_token_secret": "", 2 | "oauth_token": "", 3 | "uid": "" } 4 | -------------------------------------------------------------------------------- /components/configs/io.flowchain.dropbox/app.config.json.default: -------------------------------------------------------------------------------- 1 | { "app_key": "", 2 | "app_secret": "", 3 | "root": "dropbox" 4 | } 5 | -------------------------------------------------------------------------------- /components/io.flowchain.dropbox.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Flowchain Open Source Project 6 | * 7 | * Copyright (c) 2016-present, Jollen. All rights reserved. 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * 27 | */ 28 | 29 | 'use strict'; 30 | 31 | /** 32 | * WoT.City Framework 33 | */ 34 | var wotcity = require('wotcity.io'); 35 | 36 | /** 37 | * DropBox API 38 | */ 39 | var fs = require("fs"); 40 | var dbox = require("dbox"); 41 | 42 | var root = '/components/io.devify.dropbox/'; 43 | var app_cfg = JSON.parse(fs.readFileSync(__dirname + root + "/app.json")); 44 | var access_token = JSON.parse(fs.readFileSync(__dirname + root +"/access_token.json")); 45 | 46 | var app = dbox.app(app_cfg); 47 | var client = app.client(access_token); 48 | 49 | exports.getComponent = function() { 50 | var component = new wotcity.Component; 51 | 52 | component.name = "io.devify.dropbox"; 53 | component.description = "This component prints the received data on the console."; 54 | 55 | // Register ports and event handlers 56 | component.inPorts.add('in', function(event, payload) { 57 | switch (event) { 58 | case 'data': 59 | // Data received 60 | client.put('message.csv', data, function(status, reply) { 61 | console.log('DBOX Status: ' + status); 62 | }); 63 | return 0; 64 | case 'disconnect': 65 | // Input port disconnects 66 | return 0; 67 | } 68 | }); 69 | 70 | component.outPorts.add('out'); 71 | 72 | // Return process (the instance of component) 73 | return component; 74 | }; -------------------------------------------------------------------------------- /components/io.flowchain.fs.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Flowchain Open Source Project 6 | * 7 | * Copyright (c) 2016-present, Jollen. All rights reserved. 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * 27 | */ 28 | 29 | 'use strict'; 30 | 31 | /** 32 | * WoT.City Framework 33 | */ 34 | var wotcity = require('wotcity.io'); 35 | var fs = require("fs"); 36 | 37 | var appendFile = function(data) { 38 | var line = ''; 39 | 40 | // JSON to CSV 41 | for (var prop in data) { 42 | if (data.hasOwnProperty(prop)) { 43 | line = line 44 | + prop 45 | + ',' 46 | + data[prop] 47 | + ','; 48 | } 49 | } 50 | 51 | line += '\n'; 52 | 53 | fs.appendFile('message.csv', line, function (err) { 54 | if (err) throw err; 55 | }); 56 | }; 57 | 58 | exports.getComponent = function() { 59 | var component = new wotcity.Component; 60 | 61 | component.name = "io.flowchain.fs"; 62 | component.description = "This component save the received data to a local file."; 63 | 64 | // Register ports and event handlers 65 | component.inPorts.add('in', function(event, payload) { 66 | switch (event) { 67 | // Data received 68 | case 'data': 69 | // Parse received data 70 | var data = JSON.parse(payload.data); 71 | 72 | // Append data to file 73 | appendFile(data); 74 | 75 | component.outPorts.out.send(payload); 76 | return 0; 77 | case 'disconnect': 78 | // Input port disconnects 79 | return 0; 80 | } 81 | }); 82 | 83 | component.outPorts.add('out'); 84 | 85 | // Return process (the instance of component) 86 | return component; 87 | }; 88 | -------------------------------------------------------------------------------- /components/io.flowchain.ntp.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Flowchain Open Source Project 6 | * 7 | * Copyright (c) 2016-present, Jollen. All rights reserved. 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * 27 | */ 28 | 29 | 'use strict'; 30 | 31 | /** 32 | * WoT.City Framework 33 | */ 34 | var wotcity = require('wotcity.io'); 35 | 36 | var ntpClient = require('ntp-client'); 37 | 38 | exports.getComponent = function() { 39 | var component = new wotcity.Component; 40 | 41 | component.name = "io.devify.ntp"; 42 | component.description = "This component add the timestamp from NTP server."; 43 | 44 | // Register ports and event handlers 45 | component.inPorts.add('in', function(event, payload) { 46 | switch (event) { 47 | case 'data': 48 | // Data received 49 | ntpClient.getNetworkTime("pool.ntp.org", 123, function(err, timestamp) { 50 | if(err) { 51 | payload.timestamp = timestamp; 52 | component.outPorts.out.send(payload); 53 | } 54 | }); 55 | return 0; 56 | case 'disconnect': 57 | // Input port disconnects 58 | return 0; 59 | } 60 | }); 61 | 62 | component.outPorts.add('out'); 63 | 64 | // Return process (the instance of component) 65 | return component; 66 | }; -------------------------------------------------------------------------------- /examples/hello-world.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Flowchain Open Source Project 6 | * 7 | * Copyright (c) 2016-present, Jollen. All rights reserved. 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * 27 | */ 28 | var server = require('../libs/coap-broker'); 29 | 30 | // Components 31 | var sms = require('../components/io.devify.sms').getComponent(); 32 | var con = require('../components/io.devify.console').getComponent(); 33 | 34 | // Graph 35 | var graph = { 36 | author: 'jollen', 37 | connections: [ 38 | { 39 | upproc: 'io.devify.console', 40 | upport: 'out', 41 | downproc: 'io.devify.sms', 42 | downport: 'in' 43 | }, 44 | { 45 | upproc: 'io.devify.sms', 46 | upport: 'out', 47 | downproc: 'io.devify.console', 48 | downport: 'in' 49 | } 50 | ] 51 | }; 52 | 53 | server.start({ 54 | graph: graph, 55 | components: [sms, con] 56 | }); -------------------------------------------------------------------------------- /graphs/console.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "jollen", 3 | "type": "coapBroker", 4 | "connections": [ 5 | { 6 | "upproc": "io.flowchain.console", 7 | "upport": "out", 8 | "downproc": "io.flowchain.console", 9 | "downport": "in" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /graphs/dropbox.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "jollen", 3 | "type": "coapBroker", 4 | "connections": [ 5 | { 6 | "upproc": "io.flowchain.console", 7 | "upport": "out", 8 | "downproc": "io.flowchain.fs", 9 | "downport": "in" 10 | }, 11 | { 12 | "upproc": "io.flowchain.fs", 13 | "upport": "out", 14 | "downproc": "io.flowchain.dropbox", 15 | "downport": "in" 16 | } 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /graphs/fs.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "jollen", 3 | "type": "coapBroker", 4 | "connections": [ 5 | { 6 | "upproc": "io.flowchain.console", 7 | "upport": "out", 8 | "downproc": "io.flowchain.fs", 9 | "downport": "in" 10 | }, 11 | { 12 | "upproc": "io.flowchain.fs", 13 | "upport": "out", 14 | "downproc": "io.flowchain.sms", 15 | "downport": "in" 16 | } 17 | ] 18 | } -------------------------------------------------------------------------------- /graphs/sms.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "jollen", 3 | "type": "coapBroker", 4 | "connections": [ 5 | { 6 | "upproc": "io.flowchain.sms", 7 | "upport": "out", 8 | "downproc": "io.flowchain.sms", 9 | "downport": "in" 10 | } 11 | ] 12 | } -------------------------------------------------------------------------------- /lib/main.js: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * The MIT License (MIT) 4 | * 5 | * Flowchain Open Source Project 6 | * 7 | * Copyright (c) 2016-present, Jollen. All rights reserved. 8 | * 9 | * Permission is hereby granted, free of charge, to any person obtaining a copy 10 | * of this software and associated documentation files (the "Software"), to deal 11 | * in the Software without restriction, including without limitation the rights 12 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | * copies of the Software, and to permit persons to whom the Software is 14 | * furnished to do so, subject to the following conditions: 15 | * 16 | * The above copyright notice and this permission notice shall be included in 17 | * all copies or substantial portions of the Software. 18 | * 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | * THE SOFTWARE. 26 | * 27 | */ 28 | var program = require('commander'); 29 | var fs = require('fs'); 30 | var config = JSON.parse(fs.readFileSync(__dirname + '/../package.json')); 31 | 32 | var chalk = require('chalk'); 33 | var elegantSpinner = require('elegant-spinner'); 34 | var logUpdate = require('log-update'); 35 | var frame = elegantSpinner(); 36 | require('shelljs/global'); 37 | 38 | var devify = require('devify-server'); 39 | 40 | /** All available components **/ 41 | var components =[ 42 | require('../components/io.flowchain.fs').getComponent(), 43 | require('io.flowchain.sms'), 44 | require('io.flowchain.console') 45 | ]; 46 | 47 | program 48 | .version(config.version); 49 | 50 | program 51 | .command('start ') 52 | .description('Load a graph and start the server') 53 | .action(function(file) { 54 | var graph = JSON.parse(fs.readFileSync(__dirname + '/../' + file)); 55 | var server = devify[graph.type]; 56 | 57 | if (typeof server === 'undefined') { 58 | console.log(chalk.red('[devify] server type not found: ' + server)); 59 | exit(-1); 60 | } 61 | 62 | console.log(chalk.red('[devify] Starting ' + graph.type + ' server...')); 63 | 64 | server.start({ 65 | graph: graph, 66 | components: components 67 | }); 68 | }).on('--help', function() { 69 | console.log(' Examples:'); 70 | console.log(); 71 | console.log(' $ devify-graph start graphs/hello-fs.json'); 72 | console.log(); 73 | }); 74 | 75 | program 76 | .parse(process.argv); -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "flowchain", 3 | "version": "0.1.1", 4 | "description": "Serverless IoT server in a simpilicy way.", 5 | "keywords": [ 6 | "iot" 7 | ], 8 | "author": "jollen (http://jollen.org/)", 9 | "main": "index.js", 10 | "repository": { 11 | "type": "git", 12 | "url": "git+https://github.com/flowchain/flowchain.git" 13 | }, 14 | "homepage": "https://github.com/flowchain/flowchain.git", 15 | "dependencies": { 16 | "chalk": "^1.1.1", 17 | "commander": "^2.9.0", 18 | "devify-server": "*", 19 | "elegant-spinner": "^1.0.1", 20 | "io.flowchain.console": "^0.1.1", 21 | "io.flowchain.sms": "^0.1.0", 22 | "log-update": "^1.0.2", 23 | "shelljs": "^0.6.0", 24 | "wotcity.io": "^0.8.13" 25 | }, 26 | "bin": { 27 | "flowchain": "./bin/init.js" 28 | }, 29 | "scripts": { 30 | "test": "make test", 31 | "start": "NODE_ENV=test node bin/init start graphs/hello-fs.json" 32 | }, 33 | "devDependencies": { 34 | "codecov": "^1.0.1", 35 | "mocha": "^2.4.5", 36 | "twilio": "^2.9.0" 37 | }, 38 | "license": "MIT License" 39 | } 40 | -------------------------------------------------------------------------------- /screenshots/usage0.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/flowchain/flowchain-app/df8148353ff611b3d6c75297880db1eecb6f42e5/screenshots/usage0.gif -------------------------------------------------------------------------------- /test/run: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | export NODE_ENV=test 4 | 5 | echo 6 | for file in $@; do 7 | printf "\033[90m ${file#test/}\033[0m " 8 | node $file 2> /tmp/stderr && echo "\033[36m✓\033[0m" 9 | code=$? 10 | if test $code -ne 0; then 11 | echo "\033[31m✖\033[0m" 12 | cat /tmp/stderr >&2 13 | exit $code 14 | fi 15 | done 16 | echo -------------------------------------------------------------------------------- /test/test.websocket.send.js: -------------------------------------------------------------------------------- 1 | var WebSocketClient = require('websocket').client; 2 | 3 | var client = new WebSocketClient(); 4 | 5 | client.on('connectFailed', function(error) { 6 | console.log('Connect Error: ' + error.toString()); 7 | }); 8 | 9 | client.on('connect', function(connection) { 10 | console.log('WebSocket client connected'); 11 | connection.on('error', function(error) { 12 | console.log("Connection Error: " + error.toString()); 13 | }); 14 | connection.on('close', function() { 15 | console.log('echo-protocol Connection Closed'); 16 | }); 17 | connection.on('message', function(message) { 18 | if (message.type === 'utf8') { 19 | console.log("Received: '" + message.utf8Data + "'"); 20 | } 21 | }); 22 | 23 | function sendNumber() { 24 | if (connection.connected) { 25 | var lucky = Math.round(Math.random() * 100 + 1); 26 | var obj = {temperature: lucky}; 27 | 28 | console.log('Pushing: ' + JSON.stringify(obj)); 29 | 30 | connection.sendUTF(JSON.stringify(obj)); 31 | } 32 | } 33 | sendNumber(); 34 | process.exit(0); 35 | }); 36 | 37 | client.connect('ws://localhost:8000/object/5550937980d51931b3000009/send', ''); 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | --------------------------------------------------------------------------------