Exemplo n.º 1
0
def add_device_event(event=None):
    valid_auth_code()
    event = event or get_post_json_data()
    device = event.get("device")
    if not device:
        throw(_("Request fields not found. fields: device"))

    if not IOTDevice.check_sn_exists(device):
        throw(_("Device {0} not found.").format(device))
    dev_doc = frappe.get_doc("IOT Device", device)

    event_utc_time = datetime.datetime.strptime(event.get("time"),
                                                DATETIME_FORMAT)
    local_time = str(
        convert_utc_to_user_timezone(event_utc_time).replace(tzinfo=None))

    doc = frappe.get_doc({
        "doctype": "IOT Device Event",
        "device": device,
        "event_level": int(event.get("level") or 0),
        "event_type": event.get("type"),
        "event_info": event.get("info"),
        "event_data": event.get("data"),
        "event_time": local_time,
        "event_device": event.get("device"),
        "event_source": event.get("source"),
        "owner_type": dev_doc.owner_type,
        "owner_id": dev_doc.owner_id,
        "owner_company": dev_doc.company,
        "wechat_notify": 1,
    }).insert().as_dict()

    return doc
Exemplo n.º 2
0
def device_event_count_statistics():
	valid_auth_code()
	companies = list_user_companies(frappe.session.user)
	if len(companies) == 0:
		return
	company = companies[0]

	client = redis.Redis.from_url(IOTHDBSettings.get_redis_server() + "/15", decode_responses=True)

	from iot.hdb_api import list_iot_devices as _list_iot_devices
	devices = _list_iot_devices(frappe.session.user)
	company_devices = devices.get('company_devices')

	try:
		result = []
		if company_devices:
			for group in company_devices:
				devices = group["devices"]
				for dev in devices:
					devdoc = IOTDevice.get_device_doc(dev)
					if devdoc:
						vals = client.hgetall('event_count.' + dev)
						vals['sn'] = dev
						vals['name'] = devdoc.dev_name
						vals['last_updated'] = str(devdoc.last_updated)[:-7]
						vals['position'] = 'N/A'
						vals['device_status'] = devdoc.device_status
						result.append(vals)

		return result
	except Exception as ex:
		return []
Exemplo n.º 3
0
def add_device(device_data=None):
    valid_auth_code()
    device = device_data or get_post_json_data()

    sn = device.get("sn")
    if not sn:
        throw(_("Request fields not found. fields: sn"))

    if IOTDevice.check_sn_exists(sn):
        return IOTDevice.get_device_doc(sn)

    device.update({"doctype": "IOT Device"})

    if not device.get("dev_name"):
        device.update({"dev_name": sn})

    dev = frappe.get_doc(device).insert()

    return __generate_hdb(dev)
Exemplo n.º 4
0
def on_device_owner_update(device, org_owner_type=None, org_owner=None):
    url = None  #IOTHDBSettings.get_redis_url() // TODO: FixMe
    print(device.sn, device.owner_id)
    if url:
        """ Fire callback data """
        cb_data = {
            'cmd': 'add_device',
            'sn': device.sn,
        }
        if org_owner is not None:
            cb_data['cmd'] = 'update_device'
            cb_data['add_users'] = IOTDevice.find_owners(
                device.owner_type, device.owner_id)
            cb_data['del_users'] = IOTDevice.find_owners(
                org_owner_type, org_owner)
        else:
            cb_data['users'] = IOTDevice.find_owners(device.owner_type,
                                                     device.owner_id)
        print('------------------------------------------')
        print(json.dumps(cb_data))
        print('------------------------------------------')
Exemplo n.º 5
0
def update_device_name():
    valid_auth_code()
    data = get_post_json_data()
    name = data.get("name")
    sn = data.get("sn")
    if not (sn and name):
        throw(_("Request fields not found. fields: sn\tname"))

    dev = IOTDevice.get_device_doc(sn)
    if not dev:
        throw(_("Device is not found. SN:{0}").format(sn))

    dev.update_dev_name(name)
    return __generate_hdb(dev)
Exemplo n.º 6
0
def update_device_status(device_data=None):
    valid_auth_code()
    data = device_data or get_post_json_data()
    status = data.get("status")
    sn = data.get("sn")
    if not (sn and status):
        throw(_("Request fields not found. fields: sn\tstatus"))

    dev = IOTDevice.get_device_doc(sn)
    if not dev:
        throw(_("Device is not found. SN:{0}").format(sn))

    dev.update_status(status)
    return __generate_hdb(dev)
Exemplo n.º 7
0
def get_device(sn=None):
    """
	Get device information by device serial number
	:param sn: Device Serial Number
	:return: Device information
	"""
    valid_auth_code()
    sn = sn or frappe.form_dict.get('sn')
    if not sn:
        throw(_("Request fields not found. fields: sn"))

    dev = IOTDevice.get_device_doc(sn)
    if dev:
        return __generate_hdb(dev)
Exemplo n.º 8
0
def update_device_hdb(device_data=None):
    valid_auth_code()
    data = device_data or get_post_json_data()
    hdb = data.get("hdb")
    sn = data.get("sn")
    if not (sn and hdb):
        throw(_("Request fields not found. fields: sn\thdb"))

    dev = IOTDevice.get_device_doc(sn)
    if not dev:
        throw(_("Device is not found. SN:{0}").format(sn))

    if dev.hdb != hdb:
        dev.update_hdb(hdb)
    return __generate_hdb(dev)
Exemplo n.º 9
0
def update_device_position():
    valid_auth_code()
    data = get_post_json_data()
    pos = data.get("position")
    if not isinstance(pos, basestring):
        pos = json.loads(pos)

    sn = data.get("sn")
    if not (sn and pos):
        throw(_("Request fields not found. fields: sn\tposition"))

    dev = IOTDevice.get_device_doc(sn)
    if not dev:
        throw(_("Device is not found. SN:{0}").format(sn))

    dev.update_dev_pos(pos.get("long"), pos.get("lati"))
    return __generate_hdb(dev)
Exemplo n.º 10
0
def batch_add_device():
    valid_auth_code()
    sn_list = get_post_json_data().get('sn_list')
    done_list = []
    failed_list = []
    for sn in sn_list:
        if not IOTDevice.check_sn_exists(sn):
            try:
                dev = frappe.get_doc({
                    "doctype": "IOT Device",
                    "sn": sn,
                    "dev_name": sn
                }).insert()
                done_list.append(dev.sn)
            except Exception as ex:
                failed_list.append(sn)
        else:
            failed_list.append(sn)

    return {"done": done_list, "failed": failed_list}
Exemplo n.º 11
0
def update_device_owner(device_data=None):
    valid_auth_code()
    data = device_data or get_post_json_data()
    owner_id = data.get("owner_id")
    owner_type = data.get("owner_type")
    sn = data.get("sn")
    if sn is None:
        throw(_("Request fields not found. fields: sn"))

    dev = IOTDevice.get_device_doc(sn)
    if not dev:
        throw(_("Device is not found. SN:{0}").format(sn))

    if owner_id == "":
        owner_id = None
    if dev.owner_id == owner_id:
        return __generate_hdb(dev)

    dev.update_owner(owner_type, owner_id)

    return __generate_hdb(dev)
Exemplo n.º 12
0
def add_device_error(err_data=None):
    """
	Add device error
	:param err_data: {"device": device_sn, "error_type": Error Type defined, "error_key": any text, "error_level": int, "error_info": any text}
	:return: iot_device_error
	"""
    valid_auth_code()
    err_data = err_data or get_post_json_data()
    device = err_data.get("device")
    if not device:
        throw(_("Request fields not found. fields: device"))

    if not IOTDevice.check_sn_exists(device):
        throw(_("Device {0} not found.").format(device))

    err_data.update({
        "doctype": "IOT Device Error",
        "error_level": int(err_data.get("error_level") or 0),
        "wechat_notify": int(err_data.get("wechat_notify") or 0),
    })
    doc = frappe.get_doc(err_data).insert().as_dict()

    return doc
Exemplo n.º 13
0
def devices_list_array(filter=None):
	curuser = frappe.session.user
	devices = list_iot_devices(curuser)
	#print(devices)
	userdevices = []
	userdevices_online = []
	userdevices_offline = []
	userdevices_offline_7d = []
	if devices["company_devices"]:
		for devs in devices["company_devices"]:
			for d in devs["devices"]:
				for dsn in d["sn"]:
					devinfo = IOTDevice.get_device_doc(dsn)
					#print(dir(devinfo))
					#print(devinfo.name, devinfo.dev_name, devinfo.description, devinfo.device_status, devinfo.company)
					lasttime = get_datetime(devinfo.last_updated)
					nowtime = now_datetime()
					userdevices.append({"device_name": devinfo.dev_name, "device_sn": devinfo.name, "device_desc": devinfo.description, "device_status": devinfo.device_status,  "last_updated": devinfo.last_updated, "device_company": devinfo.company,  "longitude": devinfo.longitude, "latitude": devinfo.latitude})
					if devinfo.device_status == "ONLINE":
						userdevices_online.append({"device_name": devinfo.dev_name, "device_sn": devinfo.name,
						                           "device_desc": devinfo.description,
						                           "device_status": devinfo.device_status,
						                           "last_updated": devinfo.last_updated,
						                           "device_company": devinfo.company, "longitude": devinfo.longitude,
						                           "latitude": devinfo.latitude})
					elif devinfo.device_status == "OFFLINE" and (nowtime - lasttime).days >= 7:
						userdevices_offline_7d.append({"device_name": devinfo.dev_name, "device_sn": devinfo.name,
						                               "device_desc": devinfo.description,
						                               "device_status": devinfo.device_status,
						                               "last_updated": devinfo.last_updated,
						                               "device_company": devinfo.company,
						                               "longitude": devinfo.longitude, "latitude": devinfo.latitude})
						userdevices_offline.append({"device_name": devinfo.dev_name, "device_sn": devinfo.name,
						                            "device_desc": devinfo.description,
						                            "device_status": devinfo.device_status,
						                            "last_updated": devinfo.last_updated,
						                            "device_company": devinfo.company, "longitude": devinfo.longitude,
						                            "latitude": devinfo.latitude})
					else:
						userdevices_offline.append({"device_name": devinfo.dev_name, "device_sn": devinfo.name,
						                            "device_desc": devinfo.description,
						                            "device_status": devinfo.device_status,
						                            "last_updated": devinfo.last_updated,
						                            "device_company": devinfo.company, "longitude": devinfo.longitude,
						                            "latitude": devinfo.latitude})
				pass
			pass
		pass

	if devices["shared_devices"]:
		for devs in devices["shared_devices"]:
			for d in devs["devices"]:
				for dsn in d["sn"]:
					devinfo = IOTDevice.get_device_doc(dsn)
					#print(dir(devinfo))
					#print(devinfo.name, devinfo.dev_name, devinfo.description, devinfo.device_status, devinfo.company)
					lasttime = get_datetime(devinfo.last_updated)
					nowtime = now_datetime()
					userdevices.append({"device_name": devinfo.dev_name, "device_sn": devinfo.name, "device_desc": devinfo.description, "device_status": devinfo.device_status,  "last_updated": devinfo.last_updated, "device_company": devinfo.company, "longitude": devinfo.longitude, "latitude": devinfo.latitude})
					if devinfo.device_status == "ONLINE":
						userdevices_online.append({"device_name": devinfo.dev_name, "device_sn": devinfo.name,
						                           "device_desc": devinfo.description,
						                           "device_status": devinfo.device_status,
						                           "last_updated": devinfo.last_updated,
						                           "device_company": devinfo.company, "longitude": devinfo.longitude,
						                           "latitude": devinfo.latitude})
					elif devinfo.device_status == "OFFLINE" and (nowtime - lasttime).days >= 7:
						userdevices_offline_7d.append({"device_name": devinfo.dev_name, "device_sn": devinfo.name,
						                               "device_desc": devinfo.description,
						                               "device_status": devinfo.device_status,
						                               "last_updated": devinfo.last_updated,
						                               "device_company": devinfo.company,
						                               "longitude": devinfo.longitude, "latitude": devinfo.latitude})
						userdevices_offline.append({"device_name": devinfo.dev_name, "device_sn": devinfo.name,
						                            "device_desc": devinfo.description,
						                            "device_status": devinfo.device_status,
						                            "last_updated": devinfo.last_updated,
						                            "device_company": devinfo.company, "longitude": devinfo.longitude,
						                            "latitude": devinfo.latitude})
					else:
						userdevices_offline.append({"device_name": devinfo.dev_name, "device_sn": devinfo.name,
						                            "device_desc": devinfo.description,
						                            "device_status": devinfo.device_status,
						                            "last_updated": devinfo.last_updated,
						                            "device_company": devinfo.company, "longitude": devinfo.longitude,
						                            "latitude": devinfo.latitude})

				pass
			pass
		pass

	if devices["private_devices"]:
		for d in devices["private_devices"]:
			for dsn in d["sn"]:
				devinfo = IOTDevice.get_device_doc(dsn)
				#print(dir(devinfo))
				#print(devinfo.name, devinfo.dev_name, devinfo.description, devinfo.device_status, devinfo.company)
				lasttime = get_datetime(devinfo.last_updated)
				nowtime = now_datetime()
				userdevices.append({"device_name": devinfo.dev_name, "device_sn": devinfo.name, "device_desc": devinfo.description, "device_status": devinfo.device_status, "last_updated": devinfo.last_updated,  "device_company": curuser, "longitude": devinfo.longitude, "latitude": devinfo.latitude})
				if devinfo.device_status == "ONLINE":
					userdevices_online.append(
						{"device_name": devinfo.dev_name, "device_sn": devinfo.name, "device_desc": devinfo.description,
						 "device_status": devinfo.device_status, "last_updated": devinfo.last_updated,
						 "device_company": curuser, "longitude": devinfo.longitude,
						 "latitude": devinfo.latitude})
				elif devinfo.device_status == "OFFLINE" and (nowtime - lasttime).days >= 7:
					userdevices_offline_7d.append(
						{"device_name": devinfo.dev_name, "device_sn": devinfo.name, "device_desc": devinfo.description,
						 "device_status": devinfo.device_status, "last_updated": devinfo.last_updated,
						 "device_company": curuser, "longitude": devinfo.longitude,
						 "latitude": devinfo.latitude})
					userdevices_offline.append(
						{"device_name": devinfo.dev_name, "device_sn": devinfo.name, "device_desc": devinfo.description,
						 "device_status": devinfo.device_status, "last_updated": devinfo.last_updated,
						 "device_company": curuser, "longitude": devinfo.longitude,
						 "latitude": devinfo.latitude})
				else:
					userdevices_offline.append(
						{"device_name": devinfo.dev_name, "device_sn": devinfo.name, "device_desc": devinfo.description,
						 "device_status": devinfo.device_status, "last_updated": devinfo.last_updated,
						 "device_company": curuser, "longitude": devinfo.longitude,
						 "latitude": devinfo.latitude})

			pass
		pass

	if filter=="online":
		if userdevices_online:
			return userdevices_online
		else:
			return [{"device_name": "", "device_sn": "", "device_desc": "", "device_status": "",  "last_updated": "", "device_company": "",  "longitude": "", "latitude": ""}]
	elif filter=="offline":
		if userdevices_offline:
			return userdevices_offline
		else:
			return [{"device_name": "", "device_sn": "", "device_desc": "", "device_status": "",  "last_updated": "", "device_company": "",  "longitude": "", "latitude": ""}]
	elif filter=="offline_7d":
		if userdevices_offline_7d:
			return userdevices_offline_7d
		else:
			return [{"device_name": "", "device_sn": "", "device_desc": "", "device_status": "",  "last_updated": "", "device_company": "",  "longitude": "", "latitude": ""}]
	elif filter=="len_all":
		return len(userdevices)
	elif filter=="len_online":
		return len(userdevices_online)
	elif filter=="len_offline":
		return len(userdevices_offline)
	elif filter=="len_offline_7d":
		return len(userdevices_offline_7d)
	elif filter=="devices_amount":
		return {"all":len(userdevices), "online":len(userdevices_online), "offline":len(userdevices_offline), "offline_7d":len(userdevices_offline_7d)}
	else:
		if userdevices:
			return userdevices
		else:
			return [{"device_name": "", "device_sn": "", "device_desc": "", "device_status": "",  "last_updated": "", "device_company": "",  "longitude": "", "latitude": ""}]
Exemplo n.º 14
0
def get_context(context):
    if frappe.session.user == 'Guest':
        frappe.local.flags.redirect_location = "/login"
        raise frappe.Redirect
    context.no_cache = 1
    context.show_sidebar = True
    context.csrf_token = frappe.local.session.data.csrf_token
    if 'Company Admin' in frappe.get_roles(frappe.session.user):
        context.isCompanyAdmin = True
    context.language = frappe.local.lang  #frappe.db.get_value("User",frappe.session.user, ["language"])
    curuser = frappe.session.user
    context.userprofile = get_all(curuser)
    devices = list_iot_devices(curuser)
    userdevices_total = []
    userdevices_online = []
    userdevices_offline = []
    userdevices_offline_7d = []
    if devices["company_devices"]:
        for devs in devices["company_devices"]:
            for d in devs["devices"]:
                for dsn in d["sn"]:
                    devinfo = IOTDevice.get_device_doc(dsn)
                    #print(dir(devinfo))

                    lasttime = get_datetime(devinfo.last_updated)
                    nowtime = now_datetime()

                    userdevices_total.append({
                        "device_name": devinfo.dev_name,
                        "device_sn": devinfo.name,
                        "device_desc": devinfo.description,
                        "device_status": devinfo.device_status,
                        "last_updated": devinfo.last_updated,
                        "device_company": devinfo.company,
                        "longitude": devinfo.longitude,
                        "latitude": devinfo.latitude
                    })
                    if devinfo.device_status == "ONLINE":
                        userdevices_online.append({
                            "device_name": devinfo.dev_name,
                            "device_sn": devinfo.name,
                            "device_desc": devinfo.description,
                            "device_status": devinfo.device_status,
                            "last_updated": devinfo.last_updated,
                            "device_company": devinfo.company,
                            "longitude": devinfo.longitude,
                            "latitude": devinfo.latitude
                        })
                    elif devinfo.device_status == "OFFLINE" and (
                            nowtime - lasttime).days >= 7:
                        userdevices_offline_7d.append({
                            "device_name":
                            devinfo.dev_name,
                            "device_sn":
                            devinfo.name,
                            "device_desc":
                            devinfo.description,
                            "device_status":
                            devinfo.device_status,
                            "last_updated":
                            devinfo.last_updated,
                            "device_company":
                            devinfo.company,
                            "longitude":
                            devinfo.longitude,
                            "latitude":
                            devinfo.latitude
                        })
                        userdevices_offline.append({
                            "device_name": devinfo.dev_name,
                            "device_sn": devinfo.name,
                            "device_desc": devinfo.description,
                            "device_status": devinfo.device_status,
                            "last_updated": devinfo.last_updated,
                            "device_company": devinfo.company,
                            "longitude": devinfo.longitude,
                            "latitude": devinfo.latitude
                        })

                    else:
                        userdevices_offline.append({
                            "device_name": devinfo.dev_name,
                            "device_sn": devinfo.name,
                            "device_desc": devinfo.description,
                            "device_status": devinfo.device_status,
                            "last_updated": devinfo.last_updated,
                            "device_company": devinfo.company,
                            "longitude": devinfo.longitude,
                            "latitude": devinfo.latitude
                        })
                pass
            pass
        pass

    if devices["shared_devices"]:
        for devs in devices["shared_devices"]:
            for d in devs["devices"]:
                for dsn in d["sn"]:
                    devinfo = IOTDevice.get_device_doc(dsn)
                    #print(dir(devinfo))
                    lasttime = get_datetime(devinfo.last_updated)
                    nowtime = now_datetime()
                    userdevices_total.append({
                        "device_name": devinfo.dev_name,
                        "device_sn": devinfo.name,
                        "device_desc": devinfo.description,
                        "device_status": devinfo.device_status,
                        "last_updated": devinfo.last_updated,
                        "device_company": devinfo.company,
                        "longitude": devinfo.longitude,
                        "latitude": devinfo.latitude
                    })
                    if devinfo.device_status == "ONLINE":
                        userdevices_online.append({
                            "device_name": devinfo.dev_name,
                            "device_sn": devinfo.name,
                            "device_desc": devinfo.description,
                            "device_status": devinfo.device_status,
                            "last_updated": devinfo.last_updated,
                            "device_company": devinfo.company,
                            "longitude": devinfo.longitude,
                            "latitude": devinfo.latitude
                        })
                    elif devinfo.device_status == "OFFLINE" and (
                            nowtime - lasttime).days >= 7:
                        userdevices_offline_7d.append({
                            "device_name":
                            devinfo.dev_name,
                            "device_sn":
                            devinfo.name,
                            "device_desc":
                            devinfo.description,
                            "device_status":
                            devinfo.device_status,
                            "last_updated":
                            devinfo.last_updated,
                            "device_company":
                            devinfo.company,
                            "longitude":
                            devinfo.longitude,
                            "latitude":
                            devinfo.latitude
                        })
                        userdevices_offline.append({
                            "device_name": devinfo.dev_name,
                            "device_sn": devinfo.name,
                            "device_desc": devinfo.description,
                            "device_status": devinfo.device_status,
                            "last_updated": devinfo.last_updated,
                            "device_company": devinfo.company,
                            "longitude": devinfo.longitude,
                            "latitude": devinfo.latitude
                        })

                    else:
                        userdevices_offline.append({
                            "device_name": devinfo.dev_name,
                            "device_sn": devinfo.name,
                            "device_desc": devinfo.description,
                            "device_status": devinfo.device_status,
                            "last_updated": devinfo.last_updated,
                            "device_company": devinfo.company,
                            "longitude": devinfo.longitude,
                            "latitude": devinfo.latitude
                        })

                pass
            pass
        pass

    if devices["private_devices"]:
        for d in devices["private_devices"]:
            for dsn in d["sn"]:
                devinfo = IOTDevice.get_device_doc(dsn)
                lasttime = get_datetime(devinfo.last_updated)
                nowtime = now_datetime()

                userdevices_total.append({
                    "device_name": devinfo.dev_name,
                    "device_sn": devinfo.name,
                    "device_desc": devinfo.description,
                    "device_status": devinfo.device_status,
                    "last_updated": devinfo.last_updated,
                    "device_company": curuser,
                    "longitude": devinfo.longitude,
                    "latitude": devinfo.latitude
                })
                try:
                    if devinfo.device_status == "ONLINE":
                        userdevices_online.append({
                            "device_name": devinfo.dev_name,
                            "device_sn": devinfo.name,
                            "device_desc": devinfo.description,
                            "device_status": devinfo.device_status,
                            "last_updated": devinfo.last_updated,
                            "device_company": devinfo.company,
                            "longitude": devinfo.longitude,
                            "latitude": devinfo.latitude
                        })
                    elif devinfo.device_status == "OFFLINE" and (
                            nowtime - lasttime).days >= 7:
                        userdevices_offline_7d.append({
                            "device_name":
                            devinfo.dev_name,
                            "device_sn":
                            devinfo.name,
                            "device_desc":
                            devinfo.description,
                            "device_status":
                            devinfo.device_status,
                            "last_updated":
                            devinfo.last_updated,
                            "device_company":
                            devinfo.company,
                            "longitude":
                            devinfo.longitude,
                            "latitude":
                            devinfo.latitude
                        })
                        userdevices_offline.append({
                            "device_name": devinfo.dev_name,
                            "device_sn": devinfo.name,
                            "device_desc": devinfo.description,
                            "device_status": devinfo.device_status,
                            "last_updated": devinfo.last_updated,
                            "device_company": devinfo.company,
                            "longitude": devinfo.longitude,
                            "latitude": devinfo.latitude
                        })
                    else:
                        userdevices_offline.append({
                            "device_name": devinfo.dev_name,
                            "device_sn": devinfo.name,
                            "device_desc": devinfo.description,
                            "device_status": devinfo.device_status,
                            "last_updated": devinfo.last_updated,
                            "device_company": devinfo.company,
                            "longitude": devinfo.longitude,
                            "latitude": devinfo.latitude
                        })
                except Exception as ex:
                    frappe.logger(__name__).error(str(ex))
            pass
        pass

    context.userdevices = {
        "total": userdevices_total,
        "online": userdevices_online,
        "offline": userdevices_offline,
        "offline_7d": userdevices_offline_7d
    }

    menulist = frappe.get_all("Iot Menu")
    n_list = []
    for m in menulist:
        dd = {}
        dd['url'] = frappe.get_value("Iot Menu", m['name'], "menuurl")
        dd['name'] = frappe.get_value("Iot Menu", m['name'], "menuname")
        dd['ico'] = frappe.get_value("Iot Menu", m['name'], "menuico")
        dd['id'] = frappe.get_value("Iot Menu", m['name'], "ordernum")
        n_list.append(dd)

    n_list.sort(key=lambda k: (k.get('id', 0)))
    print(n_list)
    context.leftnavlist = n_list
    context.title = 'iot_console'