def pub_json(self, tpc, obj, **kwarg): gc_collect() with BytesIO() as json: json_dump(obj, json) gc_collect() ok = self.publish(tpc, json.getvalue(), **kwarg) gc_collect() return ok
def pub_json(self, tpc, obj, **kwarg): gc_collect() print(tpc) print(obj) if wifi.is_connected() and self.mqtt: if type(tpc) != type(b''): tpc = tpc.encode(UTF8) with BytesIO() as json: json_dump(obj, json) gc_collect() self.mqtt.publish(tpc, json.getvalue(), **kwarg) sleep(0.5) gc_collect() return True return False
def _httpHandlerIOConfigSet(httpClient, httpResponse): from ujson import dump as json_dump data = httpClient.ReadRequestContentAsJSON() if type(data['value']) is not int: httpResponse.WriteResponse(code=400, headers = None, contentType = "text/plain", contentCharset = "UTF-8", content = "Value is not integer") return from util.io_config import io_conf_file, io_menu_layout, get_from_file as get_io_config_from_file io_conf = get_io_config_from_file() io_conf[data['attr']] = data['value'] with open(io_conf_file, 'w') as f: json_dump(io_conf, f) httpResponse.WriteResponseOk(None)