Skip to content

Commit 1149828

Browse files
author
Rob Griffiths
committed
Merge branch 'release/0.2.0'
2 parents 0ef3507 + e4ef0d7 commit 1149828

File tree

5 files changed

+37
-86
lines changed

5 files changed

+37
-86
lines changed

bin/src/api.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
'use strict'
22

3+
if (typeof(URL) === 'undefined') {
4+
var URL = class URL {
5+
constructor(url) {
6+
return require('url').parse(url)
7+
}
8+
}
9+
}
10+
311
const request = require('request-promise-native')
412

513
const cleanServerUrl = (server) => {

bin/src/meross

Lines changed: 3 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4,72 +4,10 @@
44

55
var program = require('commander');
66
program
7-
.version('0.1.0');
7+
.version('0.2.0');
88

99
program
10-
.command('info <interface> [options]', 'get information about compatable Meross smart device')
11-
.command('setup <interface> [options]', 'setup compatable Meross smart device')
10+
.command('info [options]', 'get information about compatable Meross smart device')
11+
.command('setup [options]', 'setup compatable Meross smart device')
1212

1313
program.parse(process.argv);
14-
15-
// request.post({
16-
// url: `http://${gateway}/config`,
17-
// json: {
18-
// "header": {
19-
// "from": "",
20-
// "messageId": "",
21-
// "method": "SET",
22-
// "namespace": "Appliance.Config.Key",
23-
// "payloadVersion": 1,
24-
// "sign": "",
25-
// "timestamp": 0
26-
// },
27-
// "payload": {
28-
// "key": {
29-
// "gateway": {
30-
// "host": "192.168.0.17",
31-
// "port": 1883,
32-
// "secondHost": "192.168.0.17",
33-
// "secondPort": 1883,
34-
// },
35-
// "key": "1234567890",
36-
// "userId": "rob@bytespider.eu"
37-
// }
38-
// }
39-
// },
40-
// headers: {
41-
// 'Content-Type': 'application/json'
42-
// }
43-
// }, (error, response, body) => {
44-
// console.log(util.inspect(body, {showHidden: false, depth: 6}))
45-
// })
46-
47-
// request.post({
48-
// url: `http://${gateway}/config`,
49-
// json: {
50-
// "header": {
51-
// "from": "",
52-
// "messageId": "",
53-
// "method": "SET",
54-
// "namespace": "Appliance.Config.Wifi",
55-
// "payloadVersion": 0,
56-
// "sign": "",
57-
// "timestamp": 0
58-
// },
59-
// "payload": {
60-
// "wifi": {
61-
// "bssid": "48:d3:43:93:9d::e1",
62-
// "channel": 1,
63-
// "cipher": 3,
64-
// "encryption": 6,
65-
// "password": Buffer.from("qt5fdFgxQhh3").toString('base64'),
66-
// "ssid": Buffer.from("VM7877756").toString('base64')
67-
// }
68-
// }
69-
// },
70-
// headers: {
71-
// 'Content-Type': 'application/json'
72-
// }
73-
// }, (error, response, body) => {
74-
// console.log(util.inspect(body, {showHidden: false, depth: 6}))
75-
// })

bin/src/meross-info

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
'use strict'
44

55
const program = require('commander')
6-
const netroute = require('netroute')
76

87
const API = require('./api')
98

@@ -15,22 +14,21 @@ const collection = (value, store = []) => {
1514
const unique = (array) => [...new Set(array)]
1615

1716
program
18-
.version('0.1.0')
19-
.arguments('<interface> [options]')
17+
.version('0.2.0')
18+
.arguments('<options>')
19+
.option('-g, --gateway <gateway>', 'Set the gateway address')
2020

2121
program.parse(process.argv);
2222

2323

24-
if (!program.args.length) {
25-
console.error('interface must be specified');
24+
if (!program.gateway) {
25+
console.error('Gateway must be specified');
2626
process.exit(1);
2727
}
2828

2929
(async () => {
30-
const iface = program.args[0]
31-
const gateway = netroute.getGateway(iface)
32-
33-
console.log(`Getting info about device with IP ${gateway} on ${iface}`)
30+
const gateway = program.gateway
31+
console.log(`Getting info about device with IP ${gateway}`)
3432

3533

3634
const api = new API(gateway)

bin/src/meross-setup

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
'use strict'
44

55
const program = require('commander')
6-
const netroute = require('netroute')
76

87
const API = require('./api')
98

@@ -15,31 +14,40 @@ const collection = (value, store = []) => {
1514
const unique = (array) => [...new Set(array)]
1615

1716
program
18-
.version('0.1.0')
19-
.arguments('<interface> [options]')
17+
.version('0.2.0')
18+
.arguments('[options]')
19+
.option('-g, --gateway <gateway>', 'Set the gateway address')
2020
.option('--wifi-ssid <wifi-ssid>', 'WIFI AP name')
2121
.option('--wifi-pass <wifi-pass>', 'WIFI AP password')
2222
.option('--mqtt <mqtt-server>', 'MQTT server address', collection)
2323

2424
program.parse(process.argv);
2525

2626

27-
if (!program.args.length) {
28-
console.error('interface must be specified');
27+
if (!program.gateway) {
28+
console.error('Gateway must be specified');
2929
process.exit(1);
3030
}
3131

32-
(async () => {
33-
const iface = program.args[0]
34-
const gateway = netroute.getGateway(iface)
32+
if (!program.wifiSsid) {
33+
console.error('WIFI ssid must be specified');
34+
process.exit(1);
35+
}
3536

36-
console.log(`Setting up device with IP ${gateway} on ${iface}`)
37+
if (!program.wifiPass) {
38+
console.error('WIFI password must be specified');
39+
process.exit(1);
40+
}
41+
42+
(async () => {
43+
const gateway = program.gateway
44+
console.log(`Setting up device with IP ${gateway}`)
3745

3846

3947
const api = new API(gateway)
4048
var response;
4149

42-
if (program.mqtt.length) {
50+
if (program.mqtt && program.mqtt.length) {
4351
response = await api.configureMqttServers(unique(program.mqtt))
4452
}
4553

bin/src/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "meross",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "",
55
"main": "index.js",
66
"scripts": {
@@ -10,7 +10,6 @@
1010
"license": "ISC",
1111
"dependencies": {
1212
"commander": "^2.19.0",
13-
"netroute": "^1.0.2",
1413
"request": "^2.88.0",
1514
"request-promise-native": "^1.0.7"
1615
}

0 commit comments

Comments
 (0)