Open George1120901 opened 9 months ago
import redis
import time
from time import strftime
redis_conn = redis.Redis.from_url('rediss://red-xxxxxxxxxxxxxxxxx@singapore-redis.render.com:6379')
time_timeticks = []
lights = []
distances = []
lux = 1000
for i in range(0, n): #n->int 次數
time_timeticks.append(strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
lights.append(round(lux/(i+1)))
distances.append(round((i+1)*100))
redis_conn.rpush('pico:timeticks', time_timeticks[i])
redis_conn.hset('pico:lights', mapping={time_timeticks[i]: lights[i]})
redis_conn.hset('pico:distances', mapping={
time_timeticks[i]: distances[i]})
time.sleep(sec)
id_list = [item.decode()
for item in redis_conn.lrange('pico:timeticks', 0, -1)]
for id in id_list:
light = redis_conn.hget('pico:lights', id).decode()
distance = redis_conn.hget('pico:distances', id).decode()
print(f'Time:{id}\n亮度(lux):{light}\n距離(m):{distance}')
print('--+++++++++++++++++++++++++--')
redis_conn.close()
![Uploading result.JPG…]()
![Uploading 練習.png…]()