fixes to deploy on a Raspberry Pi Zero

parent 3f65cc0d
......@@ -44,16 +44,34 @@ Where `TARGET_HUE_LIGHT_ID` is the ID of one of your lights that you want to alw
## Google Home progressive enhancement
The App also searches for a Google Home to use it a its mouth to say stuff.
The App also searches for a Google Home to use it as its mouth to say stuff.
You can provide a custom language for what it will say using another environment variable: GOOGLE_HOME_LANG.
You can provide a custom language for what it will say using another environment variable: `GOOGLE_HOME_LANG`.
Only two are currently supported: `fr-FR` and `en-US`.
Currently, I include the files and dependencies of the `node-googlehome` repository, but I made a PR and should it be merged, I will be able to remove this.
## Problem encountered running this on a Raspberry Pi Zero
I played around with a RPi0 to run this server without my full computer being on. And also just to find a use for the Raspberry Pi Zero.
You'll have to install Avahi support for Bonjour:
```bash
sudo apt-get install libavahi-compat-libdnssd-dev
```
Also had an error about "getaddrinfo -3008", and found a fix in [this GitHub Issue for node-mdns](https://github.com/agnat/node_mdns/issues/130)
For future reference, I was thus able to run it from a MacOS environment and from a Raspbian on a Raspberry Pi Zero+
## Next
I tried to make a smart use of RxJs to detect change of state, but did not manage to. If someone can help me mix `async-await` with `distinctUntilChanged`, your PR will be welcome!
I could also containerize it to run it within a Docker image.
I could also containerize it to run it within a Docker image. But I have found errors for the Bonjour library which messes up between MacOS and Linux over MacOS through Docker... So I did not complete this part. Instead I put my Raspberry Pi Zero to good use.
Have the program guide you to configure things instead of doing all of this manually (interactive mode).
Also, list all Lights, and make you choose which one you want to turn off.
......@@ -2,6 +2,7 @@ const fetch = require('node-fetch');
const { timer } = require('rxjs');
const { map } = require('rxjs/operators');
const Connecter = require('./connect');
let verbose = false;
const TEXT = {
'fr-FR': {
......@@ -14,6 +15,16 @@ const TEXT = {
}
};
function getVERBOSEFromEnvVarsElseFalse() {
if (!process.env['VERBOSE']) {
console.error('You could specify VERBOSE if you want more logs');
return false;
} else {
console.debug('VERBOSE is ' + process.env['VERBOSE']);
return true;
}
}
function getHUESERFromEnvVarsOrRageQuit() {
if (!process.env['HUESER']) {
console.error('This needs a HUESER, look at the README.md for how to get one.');
......@@ -87,18 +98,20 @@ async function shutDownTheDamnLight({ hueBridgeIPAdress, hueser, targetHueLightI
}
async function loop({ index, hueBridgeIPAdress, hueser, targetHueLightId }) {
//console.log(`this is loop nb ${index}`);
verbose && console.log(`this is loop nb ${index}`);
const state = await fetchLightStatesOrRageQuit({ hueBridgeIPAdress, /*"""*/ hueser /*"""*/ });
//const nbLights = Object.keys(state).length;
//console.log(`you have ${nbLights} lights`);
/*console.log(
Object.keys(state)
.map(k => `light ${k} is ${state[k].state.on ? 'ON' : 'OFF'}`)
.join('\n'),
);
console.log(`----`);*/
if (verbose) {
const nbLights = Object.keys(state).length;
console.log(`you have ${nbLights} lights`);
console.log(
Object.keys(state)
.map(k => `light ${k} is ${state[k].state.on ? 'ON' : 'OFF'}`)
.join('\n'),
);
console.log(`----`);
}
const data = state[targetHueLightId].state;
//console.log(data);
verbose && console.log(data);
return data;
}
......@@ -141,6 +154,7 @@ async function saySomethingThroughGoogleHome(device, msg) {
const targetHueLightId = await getTargetHueLightIdFromEnvVarsOrRageQuit();
const googleHomeLang = await getLangEnvVarsOrDefaultsTo('en-US');
const foundGoogleHome = await searchGoogleHomeIpIfExistElseUndefined();
verbose = getVERBOSEFromEnvVarsElseFalse();
let device = undefined;
if (foundGoogleHome && foundGoogleHome.length>0) {
console.log(`found a Google Home named '${foundGoogleHome[0].fn}' with IP ${foundGoogleHome[0].address}`);
......
......@@ -4,11 +4,170 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"ascli": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/ascli/-/ascli-0.3.0.tgz",
"integrity": "sha1-XmYjDlIZ/j6JUqTvtPIPrllqgTo=",
"requires": {
"colour": "^0.7.1",
"optjs": "^3.2.2"
}
},
"bindings": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/bindings/-/bindings-1.2.1.tgz",
"integrity": "sha1-FK1hE4EtLTfXLme0ystLtyZQXxE="
},
"bufferview": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/bufferview/-/bufferview-1.0.1.tgz",
"integrity": "sha1-ev10pF+Tf6QiodM4wIu/3HbNcl0="
},
"bytebuffer": {
"version": "3.5.5",
"resolved": "https://registry.npmjs.org/bytebuffer/-/bytebuffer-3.5.5.tgz",
"integrity": "sha1-em+vGhNRSwg/H8+VQcTJv75+f9M=",
"requires": {
"bufferview": "~1",
"long": "~2 >=2.2.3"
}
},
"castv2": {
"version": "0.1.9",
"resolved": "https://registry.npmjs.org/castv2/-/castv2-0.1.9.tgz",
"integrity": "sha1-0LD6sf0GsNnMpjaIZxbsEpOlkFo=",
"requires": {
"debug": "^2.2.0",
"protobufjs": "^3.2.2"
}
},
"castv2-client": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/castv2-client/-/castv2-client-1.2.0.tgz",
"integrity": "sha1-qRk7GlRIuMuaBBW9AhyIEe17BUQ=",
"requires": {
"castv2": "~0.1.4",
"debug": "^2.2.0"
}
},
"colour": {
"version": "0.7.1",
"resolved": "https://registry.npmjs.org/colour/-/colour-0.7.1.tgz",
"integrity": "sha1-nLFpkX7F0SwHNtPoaFdG3xyt93g="
},
"debug": {
"version": "2.6.9",
"resolved": "https://registry.npmjs.org/debug/-/debug-2.6.9.tgz",
"integrity": "sha512-bC7ElrdJaJnPbAP+1EotYvqZsb3ecl5wi6Bfi6BJTUcNowp6cvspg0jXznRTKDjm/E7AdgFBVeAPVMNcKGsHMA==",
"requires": {
"ms": "2.0.0"
}
},
"encoding": {
"version": "0.1.12",
"resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz",
"integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=",
"requires": {
"iconv-lite": "~0.4.13"
}
},
"google-tts-api": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/google-tts-api/-/google-tts-api-0.0.4.tgz",
"integrity": "sha512-1fyRK4AxvtRrETxL59SwXgbY7cX3xhgOCbCaYu8BNlRZcjca0YeajA+50G7Jz3d6wpSxhxatz/lzMuomzWoNeQ==",
"requires": {
"isomorphic-fetch": "^2.2.1"
}
},
"iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
"integrity": "sha512-v3MXnZAcvnywkTUEZomIActle7RXXeedOR31wwl7VlyoXO4Qi9arvSenNQWne1TcRwhCL1HwLI21bEqdpj8/rA==",
"requires": {
"safer-buffer": ">= 2.1.2 < 3"
}
},
"is-stream": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz",
"integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ="
},
"isomorphic-fetch": {
"version": "2.2.1",
"resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz",
"integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=",
"requires": {
"node-fetch": "^1.0.1",
"whatwg-fetch": ">=0.10.0"
},
"dependencies": {
"node-fetch": {
"version": "1.7.3",
"resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz",
"integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==",
"requires": {
"encoding": "^0.1.11",
"is-stream": "^1.0.1"
}
}
}
},
"long": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/long/-/long-2.4.0.tgz",
"integrity": "sha1-n6GAux2VAM3CnEFWdmoZleH0Uk8="
},
"mdns": {
"version": "2.4.0",
"resolved": "https://registry.npmjs.org/mdns/-/mdns-2.4.0.tgz",
"integrity": "sha512-t58BWOyagGpATg8LlALpnqjfT7VHBq6/HCLfU/SK0Ox+enx3Cut7voWB9DPwjrdoccql6Z6ZY1rwuBX93t0Vpw==",
"requires": {
"bindings": "~1.2.1",
"nan": "^2.10.0"
}
},
"mime-db": {
"version": "1.37.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.37.0.tgz",
"integrity": "sha512-R3C4db6bgQhlIhPU48fUtdVmKnflq+hRdad7IyKhtFj06VPNVdk2RhiYL3UjQIlso8L+YxAtFkobT0VK+S/ybg=="
},
"mime-types": {
"version": "2.1.21",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.21.tgz",
"integrity": "sha512-3iL6DbwpyLzjR3xHSFNFeb9Nz/M8WDkX33t1GFQnFOllWk8pOrh/LSrB5OXlnlW5P9LH73X6loW/eogc+F5lJg==",
"requires": {
"mime-db": "~1.37.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
},
"nan": {
"version": "2.12.1",
"resolved": "https://registry.npmjs.org/nan/-/nan-2.12.1.tgz",
"integrity": "sha512-JY7V6lRkStKcKTvHO5NVSQRv+RV+FIL5pvDoLiAtSL9pKlC5x9PKQcZDsq7m4FO4d57mkhC6Z+QhAh3Jdk5JFw=="
},
"node-fetch": {
"version": "2.3.0",
"resolved": "http://localhost:4873/node-fetch/-/node-fetch-2.3.0.tgz",
"integrity": "sha512-MOd8pV3fxENbryESLgVIeaGKrdl+uaYhCSSVkjeOb/31/njTpcis5aWfdqgNlHIrKOLRbMnfPINPOML2CIFeXA=="
},
"optjs": {
"version": "3.2.2",
"resolved": "https://registry.npmjs.org/optjs/-/optjs-3.2.2.tgz",
"integrity": "sha1-aabOicRCpEQDFBrS+bNwvVu29O4="
},
"protobufjs": {
"version": "3.8.2",
"resolved": "https://registry.npmjs.org/protobufjs/-/protobufjs-3.8.2.tgz",
"integrity": "sha1-vIJuNMOvRpfo0K96Zp5NYSrtzRc=",
"requires": {
"ascli": "~0.3",
"bytebuffer": "~3 >=3.5"
}
},
"rxjs": {
"version": "6.3.3",
"resolved": "http://localhost:4873/rxjs/-/rxjs-6.3.3.tgz",
......@@ -17,10 +176,20 @@
"tslib": "^1.9.0"
}
},
"safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg=="
},
"tslib": {
"version": "1.9.3",
"resolved": "http://localhost:4873/tslib/-/tslib-1.9.3.tgz",
"integrity": "sha512-4krF8scpejhaOgqzBEcGM7yDIEfi0/8+8zDRZhNZZ2kjmHJ4hv3zCbQWxoJGz1iw5U0Jl0nma13xzHXcncMavQ=="
},
"whatwg-fetch": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-3.0.0.tgz",
"integrity": "sha512-9GSJUgz1D4MfyKU7KRqwOjXCXTqWdFNvEr7eUBYchQiVc744mqK/MzXPNR2WsPkmkOa4ywfg8C2n8h+13Bey1Q=="
}
}
}
const mdns = require('mdns'),
browser = mdns.createBrowser(mdns.tcp('googlecast'))
const mdns = require('mdns');
const sequence = [
mdns.rst.DNSServiceResolve(),
'DNSServiceGetAddrInfo' in mdns.dns_sd ? mdns.rst.DNSServiceGetAddrInfo() : mdns.rst.getaddrinfo({families:[4]}),
mdns.rst.makeAddressesUnique(),
];
const browser = mdns.createBrowser(mdns.tcp('googlecast'), {resolverSequence: sequence});
async function search(waitTime = 1000) {
......@@ -22,4 +29,4 @@ async function search(waitTime = 1000) {
})
}
module.exports = search
\ No newline at end of file
module.exports = search
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment