====== Random Stuff to play around hasp-lvgl ======
Github [[https://github.com/fvanroie/hasp-lvgl/ | hasp-lvgl]]
Since I intend to have most of this running on embedded boards with OpenWRT for the 'smartest ones', most will be written down in micropython to keep things lightweight as possible
Let's be honest, uploading the jsonl file each time is a pain:
Try this:
curl 'http://10.33.64.20/edit' -F "filename=@pages.jsonl" && sleep 1 && curl -s -o /dev/null 'http://10.33.64.20/reboot'
Or, to minimize wear on the flash until you're happy, run this:
import sys,time
from umqttsimple import MQTTClient
import ubinascii
import micropython
# Put your own settings here obviously ;)
mqtt_server = '10.33.64.2'
client_id = 'platejsonloader'
topic_pub_base = b'hasp/plate_joul'
mqttuser = 'MQTTUSER'
mqttpass = 'MQTTPASS'
mqttkeepalive = 0
state_stable = False
counter = 0
def connect_and_subscribe():
global client_id, mqtt_server, mqttuser, mqttpass, mqttkeepalive, state_stable
client = MQTTClient(client_id, mqtt_server, 1883 , mqttuser, mqttpass, mqttkeepalive)
client.connect()
print('Connected to %s MQTT broker' % (mqtt_server))
state_stable = False
return client
def restart_and_reconnect():
print('Failed to connect to MQTT broker. Reconnecting...')
time.sleep_ms(50)
#sys.exit(0)
try:
client = connect_and_subscribe()
except OSError as e:
restart_and_reconnect()
try:
# Using readlines()
for i in range (0, 13):
print("Clearing page %s"%i )
client.publish(b'%s/command/clearpage' % topic_pub_base, b'%s' % i )
time.sleep_ms(5)
file1 = open('pages.jsonl', 'r')
jsonlines = file1.readlines()
count = 0
for jsonl in jsonlines:
print("Line{}: {}".format(count, jsonl.strip()))
if len(jsonl.strip()) >0 :
count+=1
client.publish(b'%s/command/jsonl' % topic_pub_base, b'%s' % jsonl.strip() )
time.sleep_ms(5)
# I use this to trigger actions from other scripts that watch this (reinjecting values to be precise)
client.publish(b'%s/LWT' % topic_pub_base, b'online')
except OSError as e:
restart_and_reconnect()