def checkOnline(): global online response = os.system("/bin/ping -c 1 192.168.178.1") if response != 0: print("Raspberry pi seems to be offline") online = False try: endpoint = Endpoint("192.168.178.48", "1234") setPixel(endpoint, Pixel(53, 2, "ffffff")) setPixel(endpoint, Pixel(54, 2, "ffffff")) setPixel(endpoint, Pixel(55, 2, "ffffff")) setPixel(endpoint, Pixel(56, 2, "ffffff")) setPixel(endpoint, Pixel(57, 2, "ff0000")) setPixel(endpoint, Pixel(55, 4, "ff0000")) setPixel(endpoint, Pixel(54, 4, "ffffff")) setPixel(endpoint, Pixel(56, 4, "ffffff")) setPixel(endpoint, Pixel(55, 6, "ffffff")) setPixel(endpoint, Pixel(58, 1, "ff0000")) setPixel(endpoint, Pixel(56, 3, "ff0000")) setPixel(endpoint, Pixel(54, 5, "ff0000")) setPixel(endpoint, Pixel(53, 6, "ff0000")) setPixel(endpoint, Pixel(52, 7, "ff0000")) except: print("Unexpected error: " + str(sys.exc_info())) else: # clear matrix once we're online again if online == False: try: endpoint = Endpoint("192.168.178.48", "1234") clearMatrix(endpoint, offset=Offset(52, 1), width=7, height=7) online = True except: print("Unexpected error: " + str(sys.exc_info()))
def writeTime(self, text): try: drawText(self.endpoint, text, color=self.color, dyecolor=self.dyecolor, offset=Offset(17, 8), horizontalCentered=True) except: print("Unexpected error on setting display: " + str(sys.exc_info()))
def writeDate(self, text): try: drawText(self.endpoint, text, color=self.color, dyecolor=self.dyecolor, offset=Offset(17, 0), fontfile="spleen-5x8.pil", horizontalCentered=True) except: print("Unexpected error on setting display: " + str(sys.exc_info()))
def getValueFromApi(): response = requests.get( 'https://bitcoinapi.de/widget/current-btc-price/rate.json') json = response.json() return json['price_eur'].split(',')[0].encode('ascii', 'ignore') if __name__ == '__main__': try: endpoint = Endpoint("192.168.178.48", "1234") while (True): try: rate = getValueFromApi() drawText(endpoint=endpoint, text=rate, color=(247, 147, 26), offset=Offset(17, 19), horizontalCentered=True, fontfile="spleen-5x8.pil") except: log.error("Unexpected error on setting display: " + str(sys.exc_info())) time.sleep(60 * 15) except KeyboardInterrupt: log.info("Stopping...")
from matrixflut import Endpoint, drawImage, Offset import logging import sys import argparse import urllib.request log = logging.getLogger('sendImage') if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("path") parser.add_argument("-x", "--offsetx", type=int, default=0) parser.add_argument("-y", "--offsety", type=int, default=0) args = parser.parse_args() if args.path.find("http") != -1: with urllib.request.urlopen(args.path) as url: with open('temp.png', 'wb') as f: f.write(url.read()) args.path = 'temp.png' try: endpoint = Endpoint("192.168.178.48", "1234") drawImage(endpoint=endpoint, path=args.path, offset=Offset(args.offsetx, args.offsety)) except: log.info("Stopping...")
from matrixflut import Endpoint, clearMatrix, Offset import argparse if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument("-x", type=int, default=0) parser.add_argument("-y", type=int, default=0) parser.add_argument("-width", type=int, default=0) parser.add_argument("-height", type=int, default=0) args = parser.parse_args() endpoint = Endpoint("192.168.178.48", "1234") if args.x == 0: clearMatrix(endpoint=endpoint) else: offset = Offset(51, 1) clearMatrix(endpoint=endpoint, offset=offset, width=7, height=7)