Coder Social home page Coder Social logo

Comments (21)

guymcswain avatar guymcswain commented on June 11, 2024

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 PIGPIO=1.

from pigpio-client.

Toeedev avatar Toeedev commented on June 11, 2024

I am not getting any response in console from notify, only after 30 seconds maybe
notification received: chunk size = 12

can't see any problems with network, I am on local network, If i check pin manually it all works fine, every second.

from pigpio-client.

guymcswain avatar guymcswain commented on June 11, 2024

This indicates that pigpio-client is not receiving any packets. The problem lies somewhere else. Perhaps in your setup.

from pigpio-client.

 avatar commented on June 11, 2024

Any, idea how I could debug that? I don't have anything additional, just pi with node on WiFi local network.

from pigpio-client.

guymcswain avatar guymcswain commented on June 11, 2024

A volt meter to know that you are getting the proper levels when you think the pin should report 1 or 0.

from pigpio-client.

Toeedev avatar Toeedev commented on June 11, 2024

when I read it manually with button.read() , every second , get's values right.

from pigpio-client.

guymcswain avatar guymcswain commented on June 11, 2024

Please provide a test case that shows the failure.

from pigpio-client.

Toeedev avatar Toeedev commented on June 11, 2024

I do get reaction from notify, but sometimes it takes 30 seconds and more, or it doesn't notify at all

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`)
})

from pigpio-client.

guymcswain avatar guymcswain commented on June 11, 2024

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.

from pigpio-client.

 avatar commented on June 11, 2024

I am doing it by hardware, switching PIR pin between 3v3 and GND, is that not the same?

from pigpio-client.

guymcswain avatar guymcswain commented on June 11, 2024

Ok, so demonstrate there is a problem with the library.

from pigpio-client.

Toeedev avatar Toeedev commented on June 11, 2024

I don't know if it's library, but I don't do anything complicated yet.
so I added that loop

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):

0
0
1
1
1
1
1
1
Button changed to 1 at 193389531 usec
1
1
0
0

I am changing state by hardware ( jump wire from pin to either GND or 3V3 on PI ).

from pigpio-client.

guymcswain avatar guymcswain commented on June 11, 2024

```javascript
slave.PIR.read().then((err, read) => {
if (err) console.log('err: ', err)
else console.log(read)
})

from pigpio-client.

guymcswain avatar guymcswain commented on June 11, 2024

Sorry, you're using the promise. So use try/catch.

from pigpio-client.

guymcswain avatar guymcswain commented on June 11, 2024

Run your script again using: PIGPIO=1 node yourscriptname.js
Maybe slow it down to not generate so much output.

from pigpio-client.

Toeedev avatar Toeedev commented on June 11, 2024

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.
I will have to make hardware pull down resistor, as it triggers loads of event on single state change.
Well I guess it was my fault after all ;)

from pigpio-client.

guymcswain avatar guymcswain commented on June 11, 2024

Well, glad you got it sorted out.

from pigpio-client.

guymcswain avatar guymcswain commented on June 11, 2024

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.

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!

from pigpio-client.

 avatar commented on June 11, 2024

I got to that, when was reconnecting after disconnection. I have to reinit all gpios to make it work after reconnection.
This library has a big potential to create smart houses/devices. With pm2 it can be pretty reliable thing.

from pigpio-client.

guymcswain avatar guymcswain commented on June 11, 2024

pm2 - I'll have to lean more about it. Thanks for the tip.

from pigpio-client.

guymcswain avatar guymcswain commented on June 11, 2024

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.

from pigpio-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.