Closed georg90 closed 5 years ago
Can you show us how you created your methods that try to reestablish the connection?
I have a callback method with @EventCallback (YowNetworkLayer.EVENT_STATE_DISCONNECTED)
That works perfectly.
Thanks for replying @BRNALX What do you mean by establishing the connection? I copy pasted the relevant parts of layer.py below. Hope this helps?
layer.py
import os, subprocess, time, hvv, sys, math, pimatic
import pandas as pd
from random import randint
from yowsup.layers.interface import YowInterfaceLayer #Reply to the message
from yowsup.layers.interface import ProtocolEntityCallback #Reply to the message
from yowsup.layers.protocol_messages.protocolentities import TextMessageProtocolEntity #Body message
from yowsup.layers.protocol_presence.protocolentities import AvailablePresenceProtocolEntity #Online
from yowsup.layers.protocol_presence.protocolentities import UnavailablePresenceProtocolEntity #Offline
from yowsup.layers.protocol_presence.protocolentities import PresenceProtocolEntity #Name presence
from yowsup.layers.protocol_chatstate.protocolentities import OutgoingChatstateProtocolEntity #is writing, writing pause
from yowsup.common.tools import Jid #is writing, writing pause
from yowsup.env import YowsupEnv
from yowsup.layers.network import YowNetworkLayer
from yowsup.common import YowConstants
from yowsup.layers.protocol_iq.protocolentities import *
from yowsup.layers.protocol_iq import *
from yowsup.layers import YowProtocolLayer, YowLayerEvent, EventCallback
from yowsup.layers.auth import YowAuthenticationProtocolLayer
class EchoLayer(YowInterfaceLayer):
@ProtocolEntityCallback("message")
def onMessage(self, messageProtocolEntity):
if messageProtocolEntity.getType() == 'text':
time.sleep(0.5)
self.toLower(messageProtocolEntity.ack()) #Set received (double v)
time.sleep(0.5)
self.toLower(PresenceProtocolEntity(name = name)) #Set name Presence
time.sleep(0.5)
self.toLower(AvailablePresenceProtocolEntity()) #Set online
time.sleep(0.5)
self.toLower(messageProtocolEntity.ack(True)) #Set read (double v blue)
time.sleep(0.5)
self.toLower(OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_TYPING, Jid.normalize(messageProtocolEntity.getFrom(False)) )$
time.sleep(2)
self.toLower(OutgoingChatstateProtocolEntity(OutgoingChatstateProtocolEntity.STATE_PAUSED, Jid.normalize(messageProtocolEntity.getFrom(False)) )$
time.sleep(1)
self.onTextMessage(messageProtocolEntity) #Send the answer
time.sleep(3)
self.toLower(UnavailablePresenceProtocolEntity()) #Set offline
@EventCallback(YowNetworkLayer.EVENT_STATE_DISCONNECTED)
def onStateDisconnected(self,layerEvent):
print("Event: %s" % layerEvent.getArg("reason"))
msg = "WhatsApp-Plugin : Disconnect reason: %s" % layerEvent.getArg("reason")
print("WhatsApp-Plugin : Message " + msg)
#print(msg)
if layerEvent.getArg("reason") == 'Ping Timeout' or layerEvent.getArg("reason") == 'Connection Closed' or layerEvent.getArg("reason").find('Temporar$
# time.sleep(randint(5,15))
# print("WhatsApp-Plugin : Issueing EVENT_STATE_CONNECT")
# self.getStack().broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
#elif layerEvent.getArg("reason") == 'Ping Timeout':
time.sleep(randint(5,15))
print("WhatsApp-Plugin : Issueing EVENT_STATE_DISCONNECT")
self.getStack().broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_DISCONNECT))
time.sleep(randint(5,15))
print("WhatsApp-Plugin : Issueing EVENT_STATE_CONNECT")
self.getStack().broadcastEvent(YowLayerEvent(YowNetworkLayer.EVENT_STATE_CONNECT))
elif layerEvent.getName() == YowNetworkLayer.EVENT_STATE_CONNECTED:
print("WhatsApp-Plugin : Connected")
I have a problem where yowsup will disconnect each night (24h disconnect?) and won't reconnect..
I implemented a logic which will fire with the
EVENT_STATE_DISCONNECTED
andEVENT_STATE_DISCONNECT
:But the event is not triggered.. It simply disconnects and won't run the actions in the
onStateDisconneted
. I also triedonEvent
andonDisconnect
both won't work ether.Log file only returns this:
Any ideas? Any help is appreciated! :)