Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
npm-debug.log
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.idea/
node_modules
.vscode/launch.json
84 changes: 84 additions & 0 deletions Docker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
const Orvibo = require('./Orvibo');
const http = require('http');
const url = require('url');

const httpPort = 3000;

const createArray = str => {
// split on each comma
const arr = str.split(',');
// put back elements by pairs
const pairs = [];
for (let i=0; i<arr.length; i+=2) {
let o = {};
o.uid = arr[i].split(':')[1];
o.name = arr[i+1].split(':')[1];
pairs.push(o);
}
return pairs;
}

// Create a settings object to pass PK key and map sockets to names
const settings = {
LOG_PACKET: true, //Show incoming packet data from the socket
ORVIBO_KEY: process.env.orviboPK,
plugInfo :
createArray(process.env.plugArray)
,
};
let orvibo = new Orvibo(settings);
// When a socket first connects and initiates the handshake it will emit the connected event with the uid of the socket;
orvibo.on('plugConnected', ({uid, name}) => {
console.log(`Connected ${uid} name = ${name}`);
});

// If the socket state is updated this event will fire
orvibo.on('plugStateUpdated', ({uid, state , name}) => {
console.log(`Plug ${name} ${uid} updated state ${state}`);
});

// The plug sends a hearbeat to let the server know it's still alive
orvibo.on('gotHeartbeat', ({uid, name}) => {
console.log(`Plug ${name} ${uid} sent heartbeat`);
});

// Called when the plug disconnects
orvibo.on('plugDisconnected', ({uid, name }) => {
console.log(`Plug ${uid} - ${name} disconnected`);
});

// Called when the plug disconnects with an error ie it's been unplugged
orvibo.on('plugDisconnectedWithError', ({uid, name }) => {
console.log(`Plug ${uid} - ${name} disconnected with error`);
});



// Start the Orvibo socket server
orvibo.startServer();

// Create a basic example HTTP server
// If there are no parameters it will return the uid, state, modelId and name of the socket
// You can then use the uid to toggle the state of the switch like
// http://localhost:3000?uid=5dcf7ff76e7a

const requestHandler = (request, response) => {
response.writeHead(200, {'Content-Type': 'application/json'});
let q = url.parse(request.url, true).query;
if (q.uid != null) {
orvibo.toggleSocket(q.uid);
}

// Get all currently connected sockets, their names and states
let sockets = orvibo.getConnectedSocket();
response.end(JSON.stringify(sockets));
};

const httpServer = http.createServer(requestHandler);

httpServer.listen(httpPort, (err) => {
if (err) {
return console.log('something bad happened', err)
}
console.log(`http server is listening on ${httpPort}`)
});
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:alpine

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 3000 10001

CMD [ "node", "Docker.js" ]
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Orvibo B25 Smart Socket Server

A server to control the B25 range of wifi Smart Sockets
Expand Down Expand Up @@ -92,6 +93,37 @@ You can then use the uid to toggle the state of the switch like http://localhost

One thing to note is the Orvibo uses 1 as off and 0 as on for the socket state.

## Docker
I have extened this project to also run in a docker container.

PK and PlugArray can be passed in via enviroment variables.

- orviboPK = 'xxxxx'
- plugArray = 'uid:MACADDRESS,name:PRINTERNAME'

Example run command -

docker run --env orviboPK='OrviboPKkey' --env plugArray='uid:MACADDRESS1,name:PLUGNAME1,uid:MACADDRESS2,name:PLUGNAME2' -p 3000:3000 -p 10001:10001 karl0ss/orvibo-b25-server:original

Docker-Compose example -

orvibo-b25-server:
container_name: orvibo-b25-server
environment:
- PGID=${PGID}
- PUID=${PUID}
- TZ=${TZ}
image: karl0ss/orvibo-b25-server:original
ports:
- "3000:3000"
- "10001:10001"
restart: unless-stopped
environment:
- orviboPK=OrviboPKkey
- plugArray=uid:MACADDRESS1,name:PLUGNAME1,uid:MACADDRESS2,name:PLUGNAME2
volumes:
- /etc/localtime:/etc/localtime:ro

## Configuration

Once you've got a socket connecting to the official app you can add it to the plugInfo array in the OrviboSettings.js or to your settings object you pass in.
Expand Down Expand Up @@ -128,4 +160,4 @@ This project is licensed under the Apache 2.0 License - see the [LICENSE.md](LIC

## Acknowledgments

Big thanks to [Grayda](https://github.com/Grayda/) and [insertjokehere](https://github.com/insertjokehere) for all their research and hard work into how these sockets work
Big thanks to [Grayda](https://github.com/Grayda/) and [insertjokehere](https://github.com/insertjokehere) for all their research and hard work into how these sockets work
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "orvibo-b25-server",
"version": "1.1.0",
"version": "1.2.0",
"description": "A server to control the Orvibo B25 range of smart sockets",
"main": "index.js",
"scripts": {
Expand Down