Skip to content

Commit

Permalink
example: platform: Add board thing server
Browse files Browse the repository at this point in the history
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
rzr committed Aug 28, 2018
1 parent 5cf82a0 commit 9f1ce57
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions example/platform/index.js
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();

0 comments on commit 9f1ce57

Please sign in to comment.