def get_context(context): if frappe.session.user == 'Guest': frappe.local.flags.redirect_location = "/login" raise frappe.Redirect name = frappe.form_dict.name context.no_cache = 1 context.show_sidebar = False context.title = _("Cell Station") doc = frappe.get_doc("Cell Station", name) symlink_type = frappe.db.get_single_value('Cell Station Settings', 'symlink_device_type') sn = None for dev in doc.devices: if dev.device_type == symlink_type: sn = dev.device_id if sn: context.vsn = iot_device_tree(sn) context.sn = sn ''' context.sn = '2-26003-161220-00002' context.vsn = ['2-26003-161220-00002_C2_B2'] ''' context.doc = doc
def get_context(context): name = frappe.form_dict.device or frappe.form_dict.name if not name: frappe.local.flags.redirect_location = "/" raise frappe.Redirect user_roles = frappe.get_roles(frappe.session.user) context.language = frappe.db.get_value("User", frappe.session.user, ["language"]) if 'IOT User' not in user_roles or frappe.session.user == 'Guest': raise frappe.PermissionError context.no_cache = 1 context.show_sidebar = True if 'Company Admin' in frappe.get_roles(frappe.session.user): context.isCompanyAdmin = True 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))) context.leftnavlist = n_list context.title = _('Devices_List') context.csrf_token = frappe.local.session.data.csrf_token device = frappe.get_doc('IOT Device', name) device.has_permission('read') context.doc = device client = redis.Redis.from_url(IOTHDBSettings.get_redis_server() + "/1") context.devices = [] for d in client.lrange(name, 0, -1): dev = {'sn': d} if d[0:len(name)] == name: dev['name'] = d[len(name):] context.devices.append(dev) print(device) print(context.devices) if device.sn: context.vsn = iot_device_tree(device.sn) else: context.vsn = []
def iot_device_data_weui(sn=None, vsn=None): sn = sn or frappe.form_dict.get('sn') vsn = vsn or sn doc = frappe.get_doc('IOT Device', sn) doc.has_permission("read") if vsn != sn: if vsn not in iot_device_tree(sn): return "" cfg = iot_device_cfg(sn, vsn) if not cfg: return "" client = redis.Redis.from_url(IOTHDBSettings.get_redis_server() + "/2") hs = client.hgetall(vsn) data = [] if cfg.has_key("nodes"): nodes = cfg.get("nodes") for node in nodes: tags = node.get("tags") for tag in tags: name = tag.get('name') tt = hs.get(name + ".TM") timestr = '' if tt: timestr = str( convert_utc_to_user_timezone(datetime.datetime.utcfromtimestamp(int(int(tt) / 1000))).replace( tzinfo=None))[5:] data.append({"NAME": name, "PV": hs.get(name + ".PV"), # "TM": hs.get(name + ".TM"), "TM": timestr, "Q": hs.get(name + ".Q"), "DESC": tag.get("desc").strip(), }) if cfg.has_key("tags"): tags = cfg.get("tags") for tag in tags: name = tag.get('name') tt = hs.get(name + ".TM") timestr = '' if tt: timestr = str( convert_utc_to_user_timezone(datetime.datetime.utcfromtimestamp(int(int(tt) / 1000))).replace( tzinfo=None))[5:] data.append({"NAME": name, "PV": hs.get(name + ".PV"), # "TM": hs.get(name + ".TM"), "TM": timestr, "Q": hs.get(name + ".Q"), "DESC": tag.get("desc").strip(), }) return data
def device_app_dev_tree(sn): valid_auth_code() device_tree = iot_device_tree(sn) app_dev_tree = _dict({}) for dev_sn in device_tree: cfg = iot_device_cfg(sn, dev_sn) dev_meta = cfg['meta'] if not dev_meta: continue app = dev_meta['app'] if not app: continue dev_meta['sn']=dev_sn if not app_dev_tree.get(app): app_dev_tree[app] = [] app_dev_tree[app].append(dev_meta) return app_dev_tree
def get_context(context): name = frappe.form_dict.device or frappe.form_dict.name if not name: frappe.local.flags.redirect_location = "/me" raise frappe.Redirect user_roles = frappe.get_roles(frappe.session.user) if 'IOT User' not in user_roles or frappe.session.user == 'Guest': raise frappe.PermissionError context.no_cache = 1 context.show_sidebar = False device = frappe.get_doc('IOT Device', name) device.has_permission('read') context.parents = [{"title": _("IOT Devices"), "route": "/iot_devices"}] context.doc = device context.parents = [ {"title": _("Back"), "route": frappe.get_request_header("referer")}, {"title": _("IOT Devices"), "route": "/iot_devices"} ] client = redis.Redis.from_url(IOTHDBSettings.get_redis_server() + "/1") context.devices = [] for d in client.lrange(name, 0, -1): dev = { 'sn': d } if d[0:len(name)] == name: dev['name']= d[len(name):] context.devices.append(dev) if device.sn: context.vsn = iot_device_tree(device.sn) else: context.vsn = []
def get_context(context): context.no_cache = 1 context.show_sidebar = True if frappe.session.user == 'Guest': frappe.local.flags.redirect_location = "/login" raise frappe.Redirect try: name = frappe.form_dict.device or frappe.form_dict.name app = frappe.form_dict.app or frappe.form_dict.app_id if not name or not app: frappe.local.flags.redirect_location = "/" raise frappe.Redirect context.language = frappe.db.get_value("User", frappe.session.user, ["language"]) context.csrf_token = frappe.local.session.data.csrf_token if 'Company Admin' in frappe.get_roles(frappe.session.user): context.isCompanyAdmin = True # print(name) context.devsn = name doc = frappe.get_doc('IOT Device', name) doc.has_permission('read') context.doc = doc context.dev_desc = doc.description or doc.dev_name or "UNKNOWN" context.devices = iot_device_tree(name) context.app_id = app context.title = _('Wechat Device Data') except Exception as ex: frappe.logger(__name__).exception(ex) raise ex
def device_tree(sn=None): valid_auth_code() return iot_device_tree(sn)
def get_context(context): if frappe.session.user == 'Guest': frappe.local.flags.redirect_location = "/login" raise frappe.Redirect name = frappe.form_dict.device or frappe.form_dict.name if not name: frappe.local.flags.redirect_location = "/" raise frappe.Redirect context.no_cache = 1 context.show_sidebar = True context.language = frappe.db.get_value("User", frappe.session.user, ["language"]) context.csrf_token = frappe.local.session.data.csrf_token if 'Company Admin' in frappe.get_roles(frappe.session.user): context.isCompanyAdmin = True # print(name) context.devsn = name device = frappe.get_doc('IOT Device', name) device.has_permission('read') context.doc = device client1 = redis.Redis.from_url(IOTHDBSettings.get_redis_server() + "/0") cfg = None if client1.get(name): cfg = json.loads(client1.get(name)) context.dev_desc = device.description or device.dev_name if cfg: context.dev_desc = cfg['desc'] # client2 = redis.Redis.from_url(IOTHDBSettings.get_redis_server() + "/2") # hs = client2.hgetall(name) # datas = [] # if cfg.has_key("tags"): # tags = cfg.get("tags") # for tag in tags: # name = tag.get('name') # tt = hs.get(name + ".TM") # timestr = '' # if tt: # timestr = str( # convert_utc_to_user_timezone(datetime.datetime.utcfromtimestamp(int(int(tt) / 1000))).replace( # tzinfo=None))[5:] # datas.append({"NAME": name, "PV": hs.get(name + ".PV"), # "TM": timestr, "Q": hs.get(name + ".Q"), "DESC": tag.get("desc"), }) # # context.datas = datas # context.dev_desc = "" # if cfg['desc']: # context.dev_desc = cfg['desc'] # print("dev_name:", cfg['name']) # print("dev_desc:", cfg['desc']) # for data in datas: # print("tagname:", data['NAME'], "tagdesc:", data['DESC'], "value:", data['PV'], "time:", data['TM'], "quality:", data['Q']) client = redis.Redis.from_url(IOTHDBSettings.get_redis_server() + "/1") context.devices = [] for d in client.lrange(name, 0, -1): dev = {'sn': d} if d[0:len(name)] == name: dev['name'] = d[len(name):] context.devices.append(dev) # print(context.devices) if device.sn: context.vsn = iot_device_tree(device.sn) else: context.vsn = [] context.title = _('weui_rtdata')