Ejemplo n.º 1
0
def fire_action(id, action, gateway, data):
	try:
		if id is None:
			id = str(uuid.uuid1()).upper()
		return send_action("sys", action=action, id=id, device=gateway, data=data)
	except Exception as ex:
		throw("exception")
Ejemplo n.º 2
0
def command(gateway, name, command, param=None, id=None):
    try:
        valid_auth_code()
        doc = frappe.get_doc('IOT Device', gateway)
        if not doc.has_permission("write"):
            throw("has_no_permission")

        if not id:
            id = str(uuid.uuid1()).upper()

        try:
            ret = send_action("command",
                              id=id,
                              device=gateway,
                              data={
                                  "device": name,
                                  "cmd": command,
                                  "param": param,
                              })

            frappe.response.update({"ok": True, "data": ret})
        except Exception as ex:
            throw("exception")

    except Exception as ex:
        frappe.response.update({"ok": False, "error": str(ex)})
Ejemplo n.º 3
0
def output(gateway, name, output, prop, value, id=None):
    try:
        valid_auth_code()
        doc = frappe.get_doc('IOT Device', gateway)
        if not doc.has_permission("write"):
            throw("has_no_permission")

        if not id:
            id = str(uuid.uuid1()).upper()

        try:
            ret = send_action("output",
                              id=id,
                              device=gateway,
                              data={
                                  "device": name,
                                  "output": output,
                                  "prop": prop,
                                  "value": value
                              })

            frappe.response.update({"ok": True, "data": ret})
        except Exception as ex:
            throw("exception")

    except Exception as ex:
        frappe.response.update({"ok": False, "error": str(ex)})
Ejemplo n.º 4
0
def enable(gateway, beta=1):
    try:
        valid_auth_code()

        device = frappe.get_doc('IOT Device', gateway)
        if not device.has_permission("read"):
            throw("has_no_permission")

        if beta == 1:
            device.set_use_beta()

        ret = send_action("sys",
                          action="enable/beta",
                          device=gateway,
                          data=str(beta))

        frappe.response.update({"ok": True, "data": ret})
    except Exception as ex:
        frappe.response.update({"ok": False, "error": str(ex)})
Ejemplo n.º 5
0
def editor_apply():
	from iot.device_api import send_action
	device = frappe.form_dict.device
	inst = frappe.form_dict.inst
	app = frappe.form_dict.app
	if not app or not inst or not device:
		raise frappe.ValidationError

	version = editor_worksapce_version(app) or frappe.form_dict.version

	app_file = zip_application(app, version, True)
	os.system("md5sum " + app_file + " > " + app_file + ".md5")

	data = {
		"inst": inst,
		"name": app,
		"fork": 1,
		"version": "beta." + frappe.form_dict.version + ".editor"
	}
	return send_action("app", action="upgrade", device=device, data=data)
Ejemplo n.º 6
0
	def run_batch_script(self):
		task = frappe.get_doc("IOT Batch Task", self.parent)
		if self.status != 'New':
			return

		frappe.logger(__name__).info("Run batch script {0} on device {1}".format(task.name, self.device))

		try:
			from iot.device_api import send_action
			id = send_action("sys", action="batch_script", device=self.device, data=task.batch_script)
			if not id:
				throw("Send action failed")
			self.__set_val("status", "Running")
			self.__set_val("action_id", id)
			self.__set_val("action_starttime", now())
		except Exception as ex:
			frappe.logger(__name__).error(_("Run batch script {0} on {1} failed. {2}").format(task.name, self.device, repr(ex)))
			self.__set_val("status", 'Error')
			self.__set_val("info", repr(ex))
		finally:
			frappe.db.commit()
Ejemplo n.º 7
0
def device_enable_beta(sn):
	valid_auth_code()
	doc = frappe.get_doc("IOT Device", sn)
	doc.set_use_beta()
	from iot.device_api import send_action
	return send_action("sys", action="enable/beta", device=sn, data="1")