rsg98 / homebridge-gpio-wpi2

Homebridge Raspberry Pi GPIO Platform (API 2) Plugin - using WiringPi as a backend
48 stars 16 forks source link

Error crash on load while turning on pin #42

Closed ohadpr closed 6 years ago

ohadpr commented 6 years ago

Initialization works great

[2018-2-13 21:15:49] [Pi GPIO (WiringPi)] Initializing WiringPiPlatform platform...
[2018-2-13 21:15:49] [Pi GPIO (WiringPi)] WORK IN PROGRESS... Report issues on https://github.com/rsg98/homebridge-gpio-wpi2
[2018-2-13 21:15:49] [Pi GPIO (WiringPi)] Exporting GPIO Pins from config file...
[2018-2-13 21:15:49] [Pi GPIO (WiringPi)] Exporting and configuring: bulb
[2018-2-13 21:15:49] [Pi GPIO (WiringPi)] homebridge API version: 2.2

But as loading process unfolds I get a crash:

[2018-2-13 21:15:49] [Pi GPIO (WiringPi)] Loading cached GPIO pins complete
[2018-2-13 21:15:49] [Pi GPIO (WiringPi)] New GPIO from config.json: bulb (9)
[2018-2-13 21:15:49] [Pi GPIO (WiringPi)] bulb Configure GPIO Pin 2680b674-6cf8-4291-b98b-1e23de31855f
[2018-2-13 21:15:49] [Pi GPIO (WiringPi)] Turning off pin #9
/usr/lib/node_modules/homebridge-gpio-wpi2/lib/GPIOAccessory.js:61
    this.wpi.digitalWrite(this.context.pin, action);
             ^

Error: digitalWrite: IsInt32(arguments['pin']) === false
    at GPIOAccessory.pinAction (/usr/lib/node_modules/homebridge-gpio-wpi2/lib/GPIOAccessory.js:61:14)
    at new GPIOAccessory (/usr/lib/node_modules/homebridge-gpio-wpi2/lib/GPIOAccessory.js:27:18)
    at WPiPlatform.configureAccessory (/usr/lib/node_modules/homebridge-gpio-wpi2/index.js:87:23)
    at WPiPlatform.addGPIOPin (/usr/lib/node_modules/homebridge-gpio-wpi2/index.js:159:10)
    at WPiPlatform.<anonymous> (/usr/lib/node_modules/homebridge-gpio-wpi2/index.js:53:47)
    at emitNone (events.js:105:13)
    at API.emit (events.js:207:7)
    at Server.run (/usr/lib/node_modules/homebridge/lib/server.js:98:13)
    at module.exports (/usr/lib/node_modules/homebridge/lib/cli.js:40:10)
    at Object.<anonymous> (/usr/lib/node_modules/homebridge/bin/homebridge:17:22)

Here's my config:

"platforms": [
        {
                "platform": "WiringPiPlatform",
                "name": "Pi GPIO (WiringPi)",
                "overrideCache": "true",
                "autoExport": "true",
                "gpiopins": [{
                        "name": "bulb",
                        "pin": "9",
                        "_COMMENT": "the pin above is the BCM pin that corresponds with physical pin #21 on the gpio board",
                        "enabled": "true",
                        "mode": "out",
                        "pull": "down",
                        "inverted": "false",
                        "duration": 6000
                }]
        },

And here are the versions I have of all the packages:

├── epoll@0.1.22
├── homebridge@0.4.38
├── homebridge-gpio-wpi2@0.2.0
├── homebridge-http-simple-switch@0.0.2
├── homebridge-radiora@2.1.2
├── mdns@2.3.4
└── npm@5.6.0
rsg98 commented 6 years ago

Hmmm... not one I’ve seen before! 9 should be an integer!

Can you try stopping Homebridge, deleting the cachedAccessories file and restarting?

(Other closed issues describe how to do this in more detail)

ohadpr commented 6 years ago

Thanks, the pin should indeed have been an integer, homebridge now runs and doesn't complain.

My challenge now I suppose is pin mapping or perhaps I'm doing something else incorrectly.

I previously used the onoff GPIO library and utilized pin 21 (also pin 21 physically on the board).

Here's the readout from gpio readall:

 +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 |     |     |    3.3v |      |   |  1 || 2  |   |      | 5v      |     |     |
 |   2 |   8 |   SDA.1 |   IN | 1 |  3 || 4  |   |      | 5v      |     |     |
 |   3 |   9 |   SCL.1 |   IN | 1 |  5 || 6  |   |      | 0v      |     |     |
 |   4 |   7 | GPIO. 7 |   IN | 1 |  7 || 8  | 0 | IN   | TxD     | 15  | 14  |
 |     |     |      0v |      |   |  9 || 10 | 1 | IN   | RxD     | 16  | 15  |
 |  17 |   0 | GPIO. 0 |   IN | 0 | 11 || 12 | 0 | IN   | GPIO. 1 | 1   | 18  |
 |  27 |   2 | GPIO. 2 |   IN | 0 | 13 || 14 |   |      | 0v      |     |     |
 |  22 |   3 | GPIO. 3 |   IN | 0 | 15 || 16 | 0 | IN   | GPIO. 4 | 4   | 23  |
 |     |     |    3.3v |      |   | 17 || 18 | 0 | IN   | GPIO. 5 | 5   | 24  |
 |  10 |  12 |    MOSI |   IN | 0 | 19 || 20 |   |      | 0v      |     |     |
 |   9 |  13 |    MISO |  OUT | 0 | 21 || 22 | 0 | IN   | GPIO. 6 | 6   | 25  |
 |  11 |  14 |    SCLK |   IN | 0 | 23 || 24 | 1 | IN   | CE0     | 10  | 8   |
 |     |     |      0v |      |   | 25 || 26 | 1 | IN   | CE1     | 11  | 7   |
 |   0 |  30 |   SDA.0 |   IN | 1 | 27 || 28 | 1 | IN   | SCL.0   | 31  | 1   |
 |   5 |  21 | GPIO.21 |   IN | 1 | 29 || 30 |   |      | 0v      |     |     |
 |   6 |  22 | GPIO.22 |   IN | 1 | 31 || 32 | 0 | IN   | GPIO.26 | 26  | 12  |
 |  13 |  23 | GPIO.23 |  OUT | 0 | 33 || 34 |   |      | 0v      |     |     |
 |  19 |  24 | GPIO.24 |   IN | 0 | 35 || 36 | 0 | IN   | GPIO.27 | 27  | 16  |
 |  26 |  25 | GPIO.25 |   IN | 0 | 37 || 38 | 0 | IN   | GPIO.28 | 28  | 20  |
 |     |     |      0v |      |   | 39 || 40 | 0 | OUT  | GPIO.29 | 29  | 21  |
 +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
 | BCM | wPi |   Name  | Mode | V | Physical | V | Mode | Name    | wPi | BCM |
 +-----+-----+---------+------+---+---Pi 3---+---+------+---------+-----+-----+

From what I understand I need to specify the BCM pin which in my case corresponds to pin #9 (I also tried #13 to no avail).

Here's how I used to trigger this with onoff:

var gpio = require('onoff').Gpio;
var sig = new gpio(21, 'out');
...
sig.writeSync(1);
  setTimeout(function(){
    sig.writeSync(0);
  }, 5000);

Any hunch on what I may be doing incorrectly? tnx

rsg98 commented 6 years ago

AFAIK, onoff uses the same pin notation as this module - so try setting 21 in your config

You can also try with the wiringPi gpio tool, which can be easier than restarting homebridge each time. (And clearing cachedAccessories if you’ve changed the pin). The -g option let’s you specify BCM numbers:

gpio -g mode 21 out
gpio -g write 21 1
ohadpr commented 6 years ago

Couldn't have been easier, thanks.

It is surprising though that the documentation for this module mentions multiple time that the pin specification should be BCM and informed by running gpio readall while it ends up accepting the physical pin notation.

At any rate thanks for the help and I'm glad this is documented for other people.