Implemented XMPP ping

This commit is contained in:
Torbjörn Axelsson
2017-12-05 14:32:25 -08:00
parent 9ee1012334
commit 84139df7a7
+9
View File
@@ -161,6 +161,8 @@ class VacBot(ClientXMPP):
MatchXPath('{jabber:client}iq/{com:ctl}query/{com:ctl}ctl[@td="BatteryInfo"]'), MatchXPath('{jabber:client}iq/{com:ctl}query/{com:ctl}ctl[@td="BatteryInfo"]'),
self.handle_battery_report)) self.handle_battery_report))
self.schedule('Ping', 30, self.send_ping, repeat=True)
def handle_clean_report(self, iq): def handle_clean_report(self, iq):
self.clean_status = iq.find('{com:ctl}query/{com:ctl}ctl/{com:ctl}clean').get('type') self.clean_status = iq.find('{com:ctl}query/{com:ctl}ctl/{com:ctl}clean').get('type')
logging.debug("*** clean_status =" + self.clean_status) logging.debug("*** clean_status =" + self.clean_status)
@@ -198,6 +200,13 @@ class VacBot(ClientXMPP):
child.append(ctl) child.append(ctl)
return q return q
def send_ping(self):
q = self.make_iq_get(ito=self.vacuum['did'] + '@' + self.vacuum['class'] + '.ecorobot.net/atom',
ifrom=self.user + '@' + self.domain + '/' + self.resource)
logging.debug("*** sending ping ***")
q.xml.append(ET.Element('ping', {'xmlns':'urn:xmpp:ping'}))
q.send()
def connect_and_wait_until_ready(self): def connect_and_wait_until_ready(self):
self.connect(('msg-{}.ecouser.net'.format(self.continent), '5223')) self.connect(('msg-{}.ecouser.net'.format(self.continent), '5223'))
self.process() self.process()