guymcswain / pigpio-client Goto Github PK
View Code? Open in Web Editor NEWA nodejs client for pigpio socket interface.
License: MIT License
A nodejs client for pigpio socket interface.
License: MIT License
Hi @guymcswain,
When a host is not available at startup:
if I don't specify pi.timeout, then I get the error event fired.
If I DO specify pi.timeout, then I don't get 'error', 'connected' or 'disconnected', but the pigpio instance stops and releases, and node exits. So there is no way to detect connection failure, and try, for example, an alternative address?
example code (try with and without timeout set....):
let host = '192.168.1.185' || process.env.npm_package_config_host;
let proc = require('process');
// comment out to stop debug
proc.env['DEBUG'] = 'pigpio';
proc.env['PIGPIO'] = '1';
// Connect to the Rpi...
console.log('#### trying to connect to '+host);
let opts = {
host: host, // the host it will try to connect to port 8888 on....
timeout: 3, // retry timer in s?
};
const pigpio = require('../pigpio-client').pigpio(opts);
// a simple wait routine that can be called using await...
function wait(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async function keepNodeAlive(){
while (1){
await wait(2000);
}
}
//keepNodeAlive();
const ready = new Promise((resolve, reject) => {
pigpio.once('connected', resolve);
pigpio.once('error', reject);
});
pigpio.on('error', (e)=>{ console.log('#### pigpio error (on call)',e); });
pigpio.on('disconnected', (e)=>{ console.log('#### pigpio disconnected',e); });
ready.then(async (info) => {
// display information on pigpio and connection status
console.log('#### pigpio connected\n'+JSON.stringify(info,null,2));
pigpio.end(()=>{ console.log('#### pigpio ended - should exit node now'); })
}).catch((e)=>{
console.log('#### pigpio error (once call)', e);
});
console.log('#### Waiting for pigpio connection to '+host);
Hi,
what is the correct way to completely destroy an instance?
At the moment, I'm calling end(), and then de-referencing the object - but not using a callback because I anticipate that the callback would not be called if the socket(s) had not connected (due to error or just not yet...)?
I'm also calling endNotify() on the two GPIs that were being monitored (probably after end...).
Is there anything else I need to do?
br,
Simon
I've written a timing sensitive application (infrared remote emitter); it sends data on a 37KHz (~37 microsecond) carrier wave. My first go at it, I used https://github.com/fivdi/pigpio (hereafter pigpio.js), which wraps the C bindings to pigpio (hereafter pigpio.c). It works very reliably, but has lots of other unpleasant properties (can only be run as root, and doesn't support concurrent runs).
I moved the application over to pigpio-client, and it initially worked. And then stopped working. And then I'd revert back to pigpio.js, and it would work. And, interestingly enough, if I ran the pigpio.js version, then rolled the application forward to the pigpio-client version, it would work until I restarted pigpiod.c or the pi.
This makes me suspect that there's some setting / configuration pigpio.js does that I'm not doing when I start pigpiod.c without any flags.
As for the application code, the strategy is to build an array of waves, and then send them with: await gpio.waveChainTx([{ loop: false }, { waves }, { delay: 0 }, { repeat: 1 }])
. My hope here is to offload all the timing sensitive parts to pigpio.c's internal wave management.
Do you have any advice on how I'd go about debugging this?
Update documentation.
I also noticed, that button.notify
has massive delay. I had to wait like 20-30 seconds to get event change. I ended up checking pin manually, but maybe I am doing something wrong ?
( I used your exact example )
Is it how it works, or I am doing it wrong. Are there any other listeners for edge?
I might just be missing it, but I can't figure out how to set up a notify for only falling or rising edges.
Is this implemented?
It would be great to have I2C support. For example to connect to PCF8574 port expander or I2C sensors.
Hi,
I'm trying to connect the MPC3008, but I need SPI for this. Is there an example or something else? Or documentation so that I can add this to the lib?
Kind regards
after the sudo make install, I get:
Traceback (most recent call last):
File "setup.py", line 3, in
from distutils.core import setup
ModuleNotFoundError: No module named 'distutils.core'
make: *** [Makefile:107: install] Error 1
When connecting more than one client to the same pigpio server, both clients will have the same notification handle (0). If both clients run notifications there will be conflict with unpredictable results.
... when unable to connect and there is no retry timeout specified in the options.
Disregard... I posted issue to the wrong solution... the issue is with the pigpiod solution, not this client. I must have miss-clicked something.
MyError [pigpioClientError]: Unhandled socket error, connect ENETUNREACH 192.168.0.148:8888
I am running pigpiod on a different port to the standard 8888, I am wanting to update my lights using pigs, but cant seem to work out how to get pigs to use the new port?
Thanks
The following code always returns a waveform error on my Raspberry Pi Zero W:
let wc = await this.gpio.waveClear()
let wap = await this.gpio.waveAddPulse(pulses)
var wid = await this.gpio.waveCreate()
let wso = await this.gpio.waveSendOnce(wid)
let wdel = await this.gpio.waveDelete(wid)
Pulses is array of 132 tuples.
MyError [pigpioError]: attempt to create an empty waveform
at responseHandler (C:\Users\louis\AppData\Roaming\npm\node_modules\pigpio-client\pigpio-client.js:293:17)
at Socket. (C:\Users\louis\AppData\Roaming\npm\node_modules\pigpio-client\pigpio-client.js:343:30)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:326:12)
at readableAddChunk (_stream_readable.js:301:11)
at Socket.Readable.push (_stream_readable.js:235:10)
at TCP.onStreamRead (internal/stream_base_commons.js:182:23) {
name: 'pigpioError',
code: 'PI_EMPTY_WAVEFORM',
message: 'attempt to create an empty waveform',
api: 'WVCRE'
}
I am not sure if it's me, or pulldown resistor doesn't always work.
this is how my code looks like for setting up GPIOs,
`const slave = {
LED1: pigpio.gpio(config.slave.led_1),
LED2: pigpio.gpio(config.slave.led_2),
LEDext: pigpio.gpio(config.slave.led_ext),
PIR: pigpio.gpio(config.slave.pir)
}
async function settingUp() {
await slave.LED1.modeSet('output')
await slave.LED2.modeSet('output')
await slave.LEDext.modeSet('output')
await slave.PIR.pullUpDown(1)
await slave.PIR.modeSet('input')
return
}
settingUp().then(() => {
console.log('Slave GPIO Setup done...')
return
})
`
First time I got 0, but then after hours it went to 1 and stayed.
I tried changing order of setting up, then it worked again and today stopped.
Not pulling down. I am guessing it's something to do with me not understanding how it should work
const PigpioClient = require('pigpio-client');
const pi = new PigpioClient.pigpio({host:'192.168.1.231', port:8888,pipelining: false});
Do you have automatic reconnection?
I'd like to use more comprehensive i2c support, e.g. commands to read and write registers.
Use case is PCA9685 for control of servos.
Was there some reason why this is not a good addition?
(I've started coding it, but don't have much low level i2c experience, so it would be good to know if there are glaring gotchas..)
br,
Simon
I have currently an issue using pigpio-client library inside docker.
My docker container is a privileged container and I am trying to issue a write command to two specific pins over the net. The IP I am using is the docker host IP (172.17.0.1)
request= 26 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
response= 26 0 0 0 0 0 0 0 0 0 0 0 64 0 0 0
request= 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
opened notification socket with handle= 0
response= 17 0 0 0 0 0 0 0 0 0 0 0 130 32 160 0
{
"host": "172.17.0.1",
"port": 8888,
"pipelining": false,
"commandSocket": true,
"notificationSocket": true,
"pigpioVersion": 64,
"hwVersion": 10494082,
"hardware_type": 3,
"userGpioMask": 268435452
}
request= 0 0 0 0 11 0 0 0 1 0 0 0 0 0 0 0
wrote false to pin11
wrote true to pin13
response= 0 0 0 0 11 0 0 0 1 0 0 0 0 0 0 0
deferred request= 0 0 0 0 13 0 0 0 1 0 0 0 0 0 0 0
response= 0 0 0 0 13 0 0 0 1 0 0 0 0 0 0 0
deferred request= 4 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0
response= 4 0 0 0 11 0 0 0 0 0 0 0 0 0 0 0
deferred request= 4 0 0 0 13 0 0 0 1 0 0 0 0 0 0 0
response= 4 0 0 0 13 0 0 0 1 0 0 0 0 0 0 0
Apparently I cannot get any handle despite the fact I got a valid object with state connected.
On every notification, the current change is reported plus all past changes!
As I am going along with my project.
Why I am not allowed to use some of the GPIOs ? I do understant power GPIOs and GND GPIOs, but
e.g. 19 or 26 ? Is it because of that mapping might be wrong?
Is there a way to create and run scripts in pigpiod?
My use case is to change multiple GPOs at as close to the same time as possible.
e.g. for motor control, the following script would be useful:
let scriptID = pigpio.storeScript('w p2 0 w p4 0 pwm p0 p1 w p2 p3 w p4 p5');
pigpio.runScript(scriptID, [17, 128, 18, 0, 27, 1]);
so setting GPOs 18 & 27 to 0, then setting the pwm duty on 17 to 128, then setting 18->0 & 27->1
these actions would all occur very quickly with no network latency getting in the way....
as previously mentioned. Is it possible to have lower timeout so connection is monitored as frequent as possible? Currently if it goes below 2, disconnect event and connect event are triggered for no reason every couple of seconds.
Also is it possible to have timeout on, for example led.write() ? Currently, if it looses connection somewhere in between, and tries to do write(), it waits forever until connection is back. So couple of writes can pileup and take processor, as they will be stacking and waiting for connection to be back.
(I could check if connection is lost, and have variable to check before trying to do led.write(), however connection is not checked frequently enough)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.