def encodeStatJson(self, fileNM, data): rc = -1 try: dict = json.loads('{}') dict['DEV_ID'] = data[0] dict['MODE'] = data[1] dict['ALARM'] = data[2] dict['TEMP'] = data[3] dict['HUMI'] = data[4] dict['MOIST'] = data[5] dict['COND'] = data[6] dict['CDS'] = data[7] dict['BATTERY'] = data[8] dict['REMOTE'] = data[9] dict['LIGHT'] = data[10] dict['PUMP'] = data[11] dict['FAN'] = data[12] dict['HEATER'] = data[13] dict['LASTUPDT'] = data[14] dict['TEAMVIEWER'] = data[15] dict['LOCAL_IP'] = GLOB.get_ip_address() print(json.dumps(dict, ensure_ascii=False, indent="\t")) #os.remove(fileNM) with open(fileNM, 'w', encoding='utf-8') as make_file: json.dump(dict, make_file, ensure_ascii=False, indent="\t") print("out values [%s,%s,%s,%s,%s]" % (data[9], data[10], data[11], data[12], data[13])) rc = 0 except Exception as e: LOG.writeLn("[ERROR]: %s" % e) return rc
def makeJson(): data = {} data['DEV_ID'] = mProduct_id data['VERSION'] = mVersion data['INTERVAL'] = mInterval_sec data['RES_X'] = mResolution_x data['RES_Y'] = mResolution_y data['ROTATION'] = mRotation data['START_TIME'] = mStart_time data['END_TIME'] = mEnd_time data['DAY_COUNT'] = mCount data['LOCAL_IP'] = GLOB.get_ip_address() LOG.writeLn('json file save:%s' % COM.gJsonDir + 'device.json') with open(COM.gJsonDir + 'device.json', 'w', encoding='utf-8') as make_file: json.dump(data, make_file, indent="\t")