提交 5b3a598b authored 作者: blu's avatar blu

init

上级 afefb701
...@@ -71,16 +71,13 @@ class OTAClient: ...@@ -71,16 +71,13 @@ class OTAClient:
return '' return ''
def get_version(self): def get_version(self):
try:
if os.path.exists(VER_FILE): if os.path.exists(VER_FILE):
with open(VER_FILE, 'r') as f: with open(VER_FILE, 'r') as f:
while True: ver = json.load(f)
sn = f.readline() return ver.get('firmware', '')
sn = sn.rstrip() except Exception as e:
sn = sn.strip() logger.error("failed reading verisn file {}: {}", VER_FILE, str(e))
if len(sn) < 1:
continue
else:
return sn
return '' return ''
def get_sn(self): def get_sn(self):
...@@ -99,6 +96,18 @@ class OTAClient: ...@@ -99,6 +96,18 @@ class OTAClient:
topic = '/device/ota/init/' + ud.sn topic = '/device/ota/init/' + ud.sn
client.subscribe(topic, qos=1) client.subscribe(topic, qos=1)
logger.info('subscribed to {} '.format(topic)) logger.info('subscribed to {} '.format(topic))
if ud.version is '':
ud.reply(-1, '', 'fail', 'no local version')
return
# check system status
# 1. is evdaemon ok?
sn = ud._get_sn_from_evdaemon()
if sn == '':
ud.reply(-1, ud.version, 'failed', 'evdaemon is down')
return
ud.reply()
@staticmethod @staticmethod
def on_message(client, ud, msg): def on_message(client, ud, msg):
...@@ -253,7 +262,7 @@ class OTAClient: ...@@ -253,7 +262,7 @@ class OTAClient:
return return
# write version # write version
with open(VER_FILE, 'w') as f: with open(VER_FILE, 'w') as f:
f.writelines(self.version) json.dump(req,f)
# report status # report status
self.reply(batchId, ver, 'complete', 'OK') self.reply(batchId, ver, 'complete', 'OK')
os.system('systemctl restart evdaemon') os.system('systemctl restart evdaemon')
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论