-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notifications not working after network disconnect then reconnect. #22
Comments
The example should work. Something else must be going on - perhaps the network? To see all socket transactions, including notifications, you can monitor them on a console by setting the node process environment variable |
I am not getting any response in console from notify, only after 30 seconds maybe can't see any problems with network, I am on local network, If i check pin manually it all works fine, every second. |
This indicates that pigpio-client is not receiving any packets. The problem lies somewhere else. Perhaps in your setup. |
Any, idea how I could debug that? I don't have anything additional, just pi with node on WiFi local network. |
A volt meter to know that you are getting the proper levels when you think the pin should report 1 or 0. |
when I read it manually with button.read() , every second , get's values right. |
Please provide a test case that shows the failure. |
I do get reaction from const connectOptions = { host: config.slave.host, timeout: 0 } // timeout!
logger.info('Connecting to slave...')
const pigpio = client.pigpio(connectOptions) // start connecting
slave.PIR = pigpio.gpio(config.slave.pir)
slave.PIR.pullUpDown(1)
slave.PIR.modeSet('input')
slave.PIR.notify((level, tick) => {
console.log(`Button changed to ${level} at ${tick} usec`)
}) |
You need to first connect the PIR input to something you know is providing transitions between valid pin levels, in other words, pulses. You can create a pulses by writing to the same pin for which you want to receive notifications. Disconnect any external circuitry to the input pin first! For example, create a mock "PIR pulse": await slave.PIR.write(1);
await sleep(1000); // wait one second
await slave.PIR.write(0); Run this within an interval timer to get a repeating pulse train. |
I am doing it by hardware, switching PIR pin between 3v3 and GND, is that not the same? |
Ok, so demonstrate there is a problem with the library. |
I don't know if it's library, but I don't do anything complicated yet. slave.PIR.notify((level, tick) => {
console.log(`Button changed to ${level} at ${tick} usec`)
})
while (true) {
slave.PIR.read().then((read) => {
console.log(read)
})
await wait(2000)
} and my console output is ( waiting for notify is actually longer than that, just didn't want to paste it all here):
I am changing state by hardware ( jump wire from pin to either GND or 3V3 on PI ). |
|
Sorry, you're using the promise. So use try/catch. |
Run your script again using: |
ok I found the issue. I think I was setting up notify at wrong time. When I've done it on event connect. It works fine. |
Well, glad you got it sorted out. |
Makes sense. The notify would be associated with either no socket or a socket that got closed somehow. So if you do get a socket disconnect, you will need to re-init your notifications! |
I got to that, when was reconnecting after disconnection. I have to reinit all gpios to make it work after reconnection. |
pm2 - I'll have to lean more about it. Thanks for the tip. |
I'm re-opening this issue because notifications should be self re-initialized to keep consistent with gpio objects which re-connect without requiring the application to re-initialize them. I'm also going to change the title to make it clear this issue deals with socket disconnection and later reconnection. I have a few other items to clean up before I release a fix in 1.5.2 in a few days. |
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?
The text was updated successfully, but these errors were encountered: