Disconnect after some time
hey.. I am using echoclient (latest release 2.2.78) and it is disconnecting after some random time, it doesn't receive messages anymore (none event is fired onEvent)
I already have a thread to ping whatsapp every 30 seconds in my layer.. here it is:
entity = PingIqProtocolEntity(to = YowConstants.DOMAIN)
self.toLower(entity)
threading.Timer(30.0, self.pingWhats).start()
I also tried to use YowIqProtocolLayer, but it gives org.openwhatsapp.yowsup.event.network.disconnect after some time too. So, what should I do?
Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.
@kwiiby I am getting the same issue too. I have run my script as a background process but it still disconnects - (nohup python -u ./myscript.py > ./mylog.log &)
I am thinking of a work around like this.
Create a thread that keeps on checking a flag in a db of whether the whatsapp connection is still on in intervals of lets say 5 seconds. If the connection is not available, I restart the connection again and update my flag.
@mutindaz @kwiiby A simple workaround is to put the echo client in a bash script. If it disconnects it will be started again. #!/bin/bash while true : do yowsup-cli demos --config config --echo done
@gautammaloo I will try that. The reason as to why I was talking about the db flag is because:
- I am not using the demos
- I have two scripts that both require connection to whatsapp - one script listens to incoming messages while the other one is supposed to broadcast messaging. If I run the broadcast script, the connection in the message listening script is terminated and vice-versa. I needed a way for the listening script to be restarted ONLY IF am done with broadcasting.
Why not everything in the same script? create a layer with a thread for broadcast..
About the issue, the ping wasn't working because YowIqProtocolLayer wasn't in the tuple below EchoLayer.. (in the stack) Now with YowIqProtocolLayer working, Yowsup won't disconnect again.
This is how i handled this issue. I listen for "DISCONNECTED" event state and login again
def onEvent(self, layerEvent):
if layerEvent.getName() == YowNetworkLayer.EVENT_STATE_DISCONNECTED:
self.log("Disconnected: %s" % layerEvent.getArg("reason"))
self.connected = False
reactor.callLater(2,self.login)
elif layerEvent.getName() == self.__class__.EVENT_NETWORK_CONNECTED:
self.connected = True
return False
Well, I don't want to dive into why I chose that approach but having YowIqProtocolLayer in your layers turple works. @gisho do I have to create the EVENT_STATE_DISCONNECTED defined in my stack because I am only getting EVENT_NETWORK_CONNECTED only in onEvent ?
@mutindaz the even is already defined here YowNetworkLayer.EVENT_STATE_DISCONNECTED
@kwiiby could you explaint your solution more. How I can have the ping every 30 seconds in my script? Thanks
Just append YowIqProtocolLayer to layers = () in your stack.py (should be in the first turple..)
I have done it but the script disconnect randomly. Monitoring the network I can see the periodic ping but sometime it miss one and the cliente disconnect. There is a way to send ping every 30 sec instead of 120?
@gisho I also tried it like your method, but it gets disconnected before it could listen to EVENT_STATE_DISCONNECT or EVENT_STATE_DISCONNECTED. I put this in to my layer.py def onEvent(self, layerEvent): print layerEvent.getName()
it prints only these two events: org.openwhatsapp.yowsup.event.network.connect org.openwhatsapp.yowsup.event.auth.authed
try @kwiiby suggestions its working for me.
i figured the the disconnected event is not propergating correctly on detached queue. you can remove ``detached = Falseat line 40 ofnetwork.layer`
self.emitEvent(YowLayerEvent(self.__class__.EVENT_STATE_DISCONNECTED, reason = reason, detached=True))
to
self.emitEvent(YowLayerEvent(self.__class__.EVENT_STATE_DISCONNECTED, reason = reason))
i don't get it. I tried to use the script by #647 EliaComputers. I used the infinite while true loop, after a few minutes my pi receives no longer Messages from WhatsApp.
@kwiiby can u show me your script with the ping call?
What did the trick for me was adding these parameters to the stack.loop call:
stack.loop(timeout = 0.5, discrete = 0.5) #this is the program mainloop
Found these in the CLI demo
Hello,
I'm using the echoclient and I'm not familar with Python. So, I would be very happy if some body can give me a working echoclient with an implemented ping. Thanks a lot.
@jowiemann as @prasselpikachu pointed out, open stack.py in the echoclient demo then edit the following lines. Change
self.stack.loop()
to
self.stack.loop( timeout = 0.5, discrete = 0.5 )
Thank you, works very well.
@jowiemann welcome.
Hmm. I've done the following:
- added YowIqProtocolLayer in the first tuple in stack.py
- added self.stack.loop( timeout = 0.5, discrete = 0.5 ) in stack.py
I am using the demo echoclient.
Still after those changes, the client disconnects. I can reconnect once, and still get it to echo messages properly. But, then it will disconnect again. Then I reconnect again, but this time the message queue is not being processed. :-(
After a reboot, I get two more chances like above then it stops working again....
I can reproduce this behaviour very easily.