Skip to content
This repository has been archived by the owner on Feb 7, 2022. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremias Volker committed Aug 4, 2020
0 parents commit c0ee643
Show file tree
Hide file tree
Showing 7 changed files with 653 additions and 0 deletions.
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Exhibition remote control

This is a very simple prototype-like software to control the power states of all devices in the [CityLAB Berlin](http://citylab-berlin.org/) exhibition. It's running on a Raspberry Pi and exposes a web interface to be controlled from the intranet.

We're using TP-Link HS100 smart power plugs to hard-switch on/off all devices. There is no clean shutdown implemented yet. The power switches are not password protected and should therefore operate inside a separate network just for the exhibition.

## User-Interface

The UI consists of one single button with instructions/warnings. After switching on the button, switching back off is disabled for a while to ensure PCs properly boot first. There is a warning to shut down projectors manually first.

![image](https://user-images.githubusercontent.com/546852/89296357-8386a580-d662-11ea-9b28-9cb36cd5a0fb.png)


## Todo:
- Properly shut down PCs (using this: [Windows PCs](https://www.howtogeek.com/109655/how-to-remotely-shut-down-or-restart-windows-pcs/), [Windows PCs](https://lifehacker.com/shut-down-your-windows-pc-remotely-from-linux-5275652), [Linux PCs](https://www.cyberciti.biz/faq/remote-shutdown-linux-computer-from-the-cli/)) and ensure PCs have shut down (using ping) before turning off smart switches.
- Turn off projectors before shutdown
62 changes: 62 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
const express = require('express');
const app = express();
const http = require('http');
const WebSocket = require('ws');
const basicAuth = require('express-basic-auth');

const TpLinkClient = require('tplink-smarthome-api').Client

const tplink = new TpLinkClient();

const plug = tplink.getPlug({ host: '192.168.230.253' });



//initialize a simple http server
const server = http.createServer(app);

//initialize the WebSocket server instance
const wss = new WebSocket.Server({ server });


function parseMessage(str) {
try {
return JSON.parse(str);
} catch (e) {
return str;
}
}

wss.on('connection', (ws) => {

// console.log('websocket connected')

//connection is up, let's add a simple simple event
ws.on('message', (message) => {
message = parseMessage(message)
// console.log('received: %s', message);
// ws.send(`Hello, you sent -> ${message}`);

// console.log(message.exhibition)

if (message.exhibitionState) {
plug.setPowerState(true);
} else {
plug.setPowerState(false);
}
});

//send immediatly a feedback to the incoming connection
// ws.send('Hi there, I am a WebSocket server');
});

//start our server
server.listen(process.env.PORT || 80, () => {
console.log(`Server started on port ${server.address().port} :)`);
});

app.use(basicAuth({
users: { 'admin': 'supersecret' },
challenge: true
}))
app.use(express.static('public'))
Loading

0 comments on commit c0ee643

Please sign in to comment.