Commit 6f9acfd5 authored by doebi's avatar doebi
Browse files

added online now

parent d53a0088
......@@ -44,6 +44,8 @@ class WinkeKatze:
if footer:
i +=1
ugfx.string(8,12*i,footer,self.font,ugfx.BLACK)
if self.clients > 0:
ugfx.string(0,12,("%d online now" % (self.clients)),self.font,ugfx.BLACK)
if self.nick:
ugfx.string(110,90,("%s winks" % (str(self.nick))),self.font,ugfx.BLACK)
if self.nick1:
......@@ -54,7 +56,7 @@ class WinkeKatze:
ugfx.string(110,60,("%s winks" % (str(self.nick3))),self.font,ugfx.BLACK)
if self.nick4:
ugfx.string(110,50,("%s winks" % (str(self.nick4))),self.font,ugfx.BLACK)
ugfx.string(110,10,self.owner,"PermanentMarker36",ugfx.BLACK)
ugfx.string(90,10,self.owner,"PermanentMarker36",ugfx.BLACK)
ugfx.string(0,0,str(self.motd),self.font,ugfx.BLACK)
ugfx.flush()
......@@ -87,11 +89,13 @@ class WinkeKatze:
self.wink(colors)
if topic.endswith('/motd'):
self.motd = msg.decode("utf-8")
self.wink(''.join(['\50\0\0\0' for i in range(6)]))
self.wink(''.join(['\0\0\50\0' for i in range(6)]))
if topic.endswith('/version'):
nv = int(msg.decode("utf-8"))
if nv > self.version:
woezel.install("Winkekatze")
if topic.endswith('/num_clients'):
self.clients = int(msg.decode("utf-8"))
def wink(self, colors):
for count in [1,2,3]:
......@@ -137,7 +141,8 @@ class WinkeKatze:
self.clientname = 'SHA2017Badge' + str(ubinascii.hexlify(uos.urandom(5)))
self.server = server
self.topic = topic
self.version = 18
self.clients = 0
self.version = 22
self.nick = ''
self.nick1 = ''
self.nick2 = ''
......@@ -152,6 +157,8 @@ class WinkeKatze:
self.owner = badge.nvs_get_str("owner","name","anonycat")
except:
self.owner ="anonycat"
self.statustopic = ("%s/%s/%s" %(self.topic, 'clientstatus', self.owner))
ugfx.init()
wifi.init()
......@@ -163,8 +170,10 @@ class WinkeKatze:
print ("connecting to mqtt server:%s clientname:%s" %(self.server,self.clientname))
self.c = MQTTClient(self.clientname,self.server)
self.c.set_callback(self.sub_cb)
self.c.set_last_will(self.statustopic, 'OFFLINE')
self.c.connect()
self.c.subscribe("%s/#" % self.topic)
self.c.publish(self.statustopic, str(self.version), retain=True)
ugfx.clear(ugfx.BLACK)
ugfx.flush
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment