Mysql data on Scroll PhatHD


#1

Following on from my previous thread, I’m trying another idea to achieve the same result.
Pi 1 hosts Enviro Phat and writes its readings to a database also on Pi 1
Pi 2 hosts Scroll PhatHD, reads data from the database on Pi 1, and displays it on Scroll Phat HD on Pi 2

I’ve established all the necessary Mysql connection requirements, they’re all good.

How to I get the readings from the database on Pi1 to scroll on the Scroll PhatHD on Pi 2?

import signal
import time
import scrollphathd
from scrollphathd.fonts import font5x7
import mysql.connector
from mysql.connector import Error
con = mysql.connector.connect(host='192.168.X.X',database='test',user='anon',password='####')
cur = con.cursor() 
cur.execute('SELECT Temp FROM readings ORDER BY ID DESC LIMIT 1')
rows = cur.fetchall()
for row in rows:
    print row
    temperature = rows
    scrollphathd.set_brightness(0.1)
    scrollphathd.clear()
    str_len = scrollphathd.write_string("Temperature:  %.1lC "%(temperature), x=0, y=0, font=font5x7)
(7.1,)

Above result proves the SELECT query is working across Pi-to-Pi, OK.

Traceback (most recent call last):
  File "dotty2.py", line 27, in <module>
    str_len = scrollphathd.write_string("Temperature:  %.1lC "%(temperature), x=0, y=0, font=font5x7)
ValueError: unsupported format character 'C' (0x43) at index 18
------------------
(program exited with code: 1)
Press return to continue

I don’t know how to get that query result to scroll.

Thank you.


#2

Making progress, but now stuck with:

import signal
import time
import scrollphathd
from scrollphathd.fonts import font5x7
import mysql.connector
from mysql.connector import Error
con = mysql.connector.connect(host='192.168.X.X',database='test',user='######',password='######')

str_len = 0
scroll_x = 0

cur = con.cursor() 
cur.execute('SELECT Yaxis FROM readings ORDER BY Added DESC LIMIT 1')

result_list = [row[0] for row in cur.fetchall()]
print result_list
temperature = result_list

scrollphathd.set_brightness(0.1)
scrollphathd.clear()

str_len = scrollphathd.write_string("Temperature:%.1fC"[temperature], x=0, y=0, font=font5x7)
scrollphathd.scroll_to(scroll_x, 0)
scrollphathd.show()

time.sleep(0.01)
scroll_x += 1
if scroll_x >= str_len:
    scroll_x = 0    

Error reads:

str_len = scrollphathd.write_string("Temperature:%.1fC"[temperature], x=0, y=0, font=font5x7)
TypeError: string indices must be integers, not list