-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: platform: Add board thing server
More boards to come Change-Id: I9915a765458dc0695ad10a4da40e066d4bac729b Origin: https://github.com/rzr/webthing-iotjs Forwarded: #30 Signed-off-by: Philippe Coval <p.coval@samsung.com>
- Loading branch information
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// -*- mode: js; js-indent-level:2; -*- | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
/** | ||
* | ||
* Copyright 2018-present Samsung Electronics France SAS, and other contributors | ||
* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.* | ||
*/ | ||
|
||
const console = require('console'); | ||
|
||
// TODO: disable logs here by editing to '!console.log' | ||
const log = console.log || function() {}; | ||
|
||
const { | ||
SingleThing, | ||
WebThingServer, | ||
} = require('webthing'); | ||
|
||
// Update with different board here if needed | ||
let board = 'artik530'; | ||
if (process.argv.length > 2) { | ||
board = String(process.argv[2]); | ||
} | ||
|
||
log(`log: board: ${board}: Loading`); | ||
const BoardThing = require(`./board/${board}`); | ||
|
||
function runServer() { | ||
const port = process.argv[3] ? Number(process.argv[3]) : 8888; | ||
const url = `http://localhost:${port}`; | ||
|
||
log(`Usage:\n\ | ||
${process.argv[0]} ${process.argv[1]} [board] [port]\n\ | ||
Try:\ncurl -H "Accept: application/json" ${url}\ | ||
\n`); | ||
const thing = new BoardThing(); | ||
const server = new WebThingServer(new SingleThing(thing), port); | ||
process.on('SIGINT', () => { | ||
server.stop(); | ||
thing && thing.close(); | ||
log(`log: board: ${board}: Stopped`); | ||
process.exit(); | ||
}); | ||
server.start(); | ||
log(`log: board: ${board}: Started`); | ||
} | ||
|
||
runServer(); |