parent
bfa6c9e5ed
commit
d815226046
@ -0,0 +1,10 @@
|
|||||||
|
NAME=
|
||||||
|
|
||||||
|
DEBUG=false
|
||||||
|
IP=
|
||||||
|
PORT=3000
|
||||||
|
|
||||||
|
JWT_SECRET=
|
||||||
|
|
||||||
|
USER_TOKEN=
|
||||||
|
USER_PASSWORD=
|
@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"/public/index.js": "/public/index.js"
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@ -0,0 +1,48 @@
|
|||||||
|
const schemas = require('../schemas/state.js')
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Björn Hase, Tentakelfabrik
|
||||||
|
* @license http://opensource.org/licenses/MIT The MIT License
|
||||||
|
* @link https://github.com/tentakelfabrik/fastify-lowdb-riotjs-lessons-learned
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
module.exports = async function (fastify, opts) {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* getting current status of switch
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @param {object} request
|
||||||
|
* @param {object} reply
|
||||||
|
* @return {object}
|
||||||
|
*/
|
||||||
|
fastify.post('/login', function(request, reply) {
|
||||||
|
reply
|
||||||
|
.code(200)
|
||||||
|
.header('Content-Type', 'application/json; charset=utf-8')
|
||||||
|
.send({
|
||||||
|
'name': process.env.NAME
|
||||||
|
'power': power
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* turn on
|
||||||
|
*
|
||||||
|
* @param {object} request
|
||||||
|
* @param {object} reply
|
||||||
|
* @return {object}
|
||||||
|
*/
|
||||||
|
fastify.post('/logout', schemas.putSchema, function(request, reply) {
|
||||||
|
reply
|
||||||
|
.code(200)
|
||||||
|
.header('Content-Type', 'application/json; charset=utf-8')
|
||||||
|
.send({
|
||||||
|
'name': process.env.NAME
|
||||||
|
'power': power
|
||||||
|
})
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
import * as riot from 'riot'
|
||||||
|
import TinkerforgePowerButton from './tinkerforge-power-button.riot'
|
||||||
|
|
||||||
|
// register components
|
||||||
|
riot.register('tinkerforge-power-button', TinkerforgePowerButton)
|
||||||
|
riot.mount('tinkerforge-power-button')
|
@ -0,0 +1,40 @@
|
|||||||
|
<tinkerforge-power-button>
|
||||||
|
<div class="tinkerforge-power-button">
|
||||||
|
<button type="button" onclick={ handleClick }>
|
||||||
|
<span if={ state.power }>On</span>
|
||||||
|
<span if={ !state.power }>Off</span>
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<script>
|
||||||
|
|
||||||
|
import axios from 'axios'
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
* @author Björn Hase
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
export default {
|
||||||
|
state: {
|
||||||
|
power: true
|
||||||
|
},
|
||||||
|
|
||||||
|
handleClick(event) {
|
||||||
|
if (this.state.power) {
|
||||||
|
this.state.power = false
|
||||||
|
} else {
|
||||||
|
this.state.power = true
|
||||||
|
}
|
||||||
|
|
||||||
|
axios.put('/api/state', {
|
||||||
|
'power': this.state.power
|
||||||
|
}).then((response) => {
|
||||||
|
this.update()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</script>
|
||||||
|
</tinkerforge-power-button>
|
@ -0,0 +1,26 @@
|
|||||||
|
/**
|
||||||
|
* schemas for state routes
|
||||||
|
*
|
||||||
|
* @author Björn Hase, Tentakelfabrik
|
||||||
|
* @license http://opensource.org/licenses/MIT The MIT License
|
||||||
|
* @link https://github.com/tentakelfabrik/fastify-lowdb-riotjs-lessons-learned
|
||||||
|
*/
|
||||||
|
|
||||||
|
const putSchema = {
|
||||||
|
schema: {
|
||||||
|
params: {
|
||||||
|
type: 'object',
|
||||||
|
required: ['user_token', 'user_secret'],
|
||||||
|
properties: {
|
||||||
|
'user_token': {
|
||||||
|
type: 'boolean'
|
||||||
|
}
|
||||||
|
},
|
||||||
|
additionalProperties: false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
putSchema: putSchema
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
const Tinkerforge = require('tinkerforge')
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
class TinkerforgePower {
|
||||||
|
|
||||||
|
constructor(power) {
|
||||||
|
this.host = 'localhost'
|
||||||
|
this.port = 4223
|
||||||
|
this.UID = 'xxx'
|
||||||
|
|
||||||
|
this.power = power
|
||||||
|
|
||||||
|
this.ipcon = new Tinkerforge.IPConnection()
|
||||||
|
this.idr = new Tinkerforge.BrickletIndustrialDualRelay(this.UID, this.ipcon);
|
||||||
|
|
||||||
|
this.ipcon.connect(this.host, this.port, (error) => {
|
||||||
|
this._handleError(error)
|
||||||
|
})
|
||||||
|
|
||||||
|
this.ipcon.on(Tinkerforge.IPConnection.CALLBACK_CONNECTED, (connectReason) => {
|
||||||
|
this._handlePower(this.power)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
_handleError(error) {
|
||||||
|
console.log('Error: ' + error)
|
||||||
|
}
|
||||||
|
|
||||||
|
_handlePower(connectReason) {
|
||||||
|
this.idr.setValue(this.power, this.power)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = TinkerforgePower
|
@ -0,0 +1,32 @@
|
|||||||
|
const mix = require('laravel-mix')
|
||||||
|
|
||||||
|
/*
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
| Mix Asset Management
|
||||||
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
| Mix provides a clean, fluent API for defining some Webpack build steps
|
||||||
|
| for your Laravel applications. By default, we are compiling the CSS
|
||||||
|
| file for the application as well as bundling up all the JS files.
|
||||||
|
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
mix.webpackConfig({
|
||||||
|
module: {
|
||||||
|
rules: [{
|
||||||
|
test: /\.riot$/,
|
||||||
|
use: [{
|
||||||
|
loader: '@riotjs/webpack-loader'
|
||||||
|
}]
|
||||||
|
}
|
||||||
|
]}
|
||||||
|
})
|
||||||
|
|
||||||
|
mix
|
||||||
|
.js('src/client/index.js', 'public')
|
||||||
|
.options({
|
||||||
|
terser: {
|
||||||
|
extractComments: false,
|
||||||
|
}
|
||||||
|
})
|
Loading…
Reference in new issue