Skip to content

Commit

Permalink
Autodetect libpython
Browse files Browse the repository at this point in the history
  • Loading branch information
Sunoo committed Jun 25, 2020
1 parent 661d84f commit ec445bc
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ Edit your `config.json` accordingly. Configuration sample:
| name | For logging purposes. | No |
| gpio | The BCM number of the pin your RF transmitter is connected to. (Default: 17) | No |
| repeat | RF code repeat cycles. (Default: 10) | No |
| libpython | **See note below.** | No |
| devices | Array of switch config (multiple switches supported). | Yes |
| \|- name | Name of your device. | Yes |
| \|- on_code | RF code to turn on your device. | Yes |
Expand All @@ -43,11 +42,5 @@ Edit your `config.json` accordingly. Configuration sample:
| \|- protocol | RF code protocol. (Default: 1) | No |
| \|- codelength | RF code length. (Default: 24) | No |

### libpython Setting
If you are running a version of Python other than 3.7, you may need to update this value. You probably won't want to touch this unless you encounter problems. Here is how to find that value.
1. Run `python3-config --libs`.
2. You'll see something like `-lpython3.7m -lcrypt -lpthread -ldl -lutil -lm`.
3. You want the first item listed, excluding the -l. In this example, it would be `python3.7m`.

### Note on Getting RF Codes
I've had the best luck with `RFSniffer` from the [433Utils](https://github.com/ninjablocks/433Utils) project. Your mileage may vary.
6 changes: 0 additions & 6 deletions config.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
"placeholder": 10,
"description": "RF code repeat cycles."
},
"libpython": {
"title": "libpython Version",
"type": "string",
"placeholder": "python3.7m",
"description": "See readme for more information."
},
"devices": {
"title": "Devices",
"type": "array",
Expand Down
17 changes: 13 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const python = require("node-calls-python").interpreter;
const process = require("child_process");
var Accessory, Service, Characteristic, UUIDGen;

module.exports = function(homebridge) {
Expand All @@ -16,15 +17,23 @@ function rfSwitchPlatform(log, config, api) {

this.gpio = config.gpio || 17;
this.repeat = config.repeat || 10;
this.libpython = config.libpython || 'python3.7m';

this.accessories = [];
this.libpython = config.libpython;

this.commandQueue = [];
this.transmitting = false;
if (this.libpython == null) {
var pyconfig = process.execSync('python3-config --libs').toString();
var index = pyconfig.indexOf('-lpython');
pyconfig = pyconfig.substr(index + 2);
index = pyconfig.indexOf(' ');
this.libpython = pyconfig.substr(0, index);
}

python.fixlink('lib' + this.libpython + '.so');

this.accessories = [];
this.commandQueue = [];
this.transmitting = false;

var rpiRf = python.importSync('rpi_rf');
this.rfDevice = python.createSync(rpiRf, 'RFDevice', this.gpio, 1, null, this.repeat, 24);
python.callSync(this.rfDevice, 'enable_tx');
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"displayName": "Homebridge rpi-rf Switch",
"name": "homebridge-rpi-rf-switch",
"version": "2.1.2",
"version": "2.1.3",
"description": "rpi-rf plugin for Homebridge",
"repository": {
"type": "git",
Expand Down

0 comments on commit ec445bc

Please sign in to comment.