コード例 #1
0
ファイル: main.py プロジェクト: stijnh/pi-monitor
    def run(self):
        while not self.stopped:
            now = time.time()

            if self.refresh_all:
                self.refresh_all = False
                next_update = dict((k, now) for k in self.CHANNELS)

            data = {}

            for k, delay in self.CHANNELS.items():
                if next_update[k] > now:
                    continue

                next_update[k] = now + delay

                try:
                    data[k] = getattr(self, "status_" + k)()
                except Exception as e:
                    logging.info("failed to fetch '%s':\n%s", k, e)

            msg = wspy.TextMessage(json.dumps(data))

            for client in set(self.clients):
                try:
                    client.send(msg)
                except Exception as e:
                    logging.warning("failed to send to '%s':\n%s", client, e)

            time.sleep(min(next_update.values()) - now)
コード例 #2
0
	def onmessage(self, message):
		print 'Received message "%s"' % message.payload
		if message.payload == "ready": # If the webpage is ready, give it data
			global lastOdomMessage
			global lastLaserMessage
			stringToSend = lastOdomMessage + "\n\n" + lastLaserMessage
			self.send(wspy.TextMessage(unicode(stringToSend, "utf-8")))
			if lastOdomMessage != "OLD" and lastLaserMessage != "old":
				lastOdomMessage = "OLD"
				lastLaserMessage = "OLD"
コード例 #3
0
 def onmessage(self, message):
     print 'Received message "%s"' % message.payload
     #self.send(wspy.TextMessage(message.payload))
     for cliente in clientes:
         if self != cliente:
             cliente.send(wspy.TextMessage(message.payload))
コード例 #4
0
 def onmessage(self, message):
     print 'Received message "%s"' % message.payload
     self.send(wspy.TextMessage(message.payload))
コード例 #5
0
 def onmessage(self, message):
     print 'Received message "%s"' % message.payload
     if message.payload == "ready":  # If the webpage is ready, give it data
         global lastMessage
         self.send(wspy.TextMessage(unicode(lastMessage, "utf-8")))
コード例 #6
0
def callback(data):
    if connectionOpened:  # If there's a connection opened, send the data over the connection
        WebSocketServer(client).send(
            wspy.TextMessage(unicode(data.data, "utf-8")))
    else:  # Otherwise, just print it
        print "No connection: %s" % data.data