From 81d819228ae0f2735fe524344a995a43d365bf4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E7=AB=8B=E5=B8=AE?= <3294713004@qq.com> Date: Sun, 28 Sep 2025 17:27:44 +0800 Subject: [PATCH] =?UTF-8?q?chore(boards):=20=E8=B0=83=E6=95=B4micropython?= =?UTF-8?q?=E4=B8=8BTinyWebDB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../micropython/origin/build/lib/mixiot.py | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/boards/default_src/micropython/origin/build/lib/mixiot.py b/boards/default_src/micropython/origin/build/lib/mixiot.py index 36112150..e5e2588b 100644 --- a/boards/default_src/micropython/origin/build/lib/mixiot.py +++ b/boards/default_src/micropython/origin/build/lib/mixiot.py @@ -86,6 +86,7 @@ class MQTTClient: self.lw_retain = False self._on_message_filtered = MQTTMatcher() self._star_time = time.ticks_ms() + self._tiny_web_db = TinyWebDB("", username, password) def _send_str(self, s): self.sock.write(struct.pack("!H", str_len(s))) @@ -342,13 +343,32 @@ class MQTTClient: self.ping() return self.wait_msg() + def tiny_web_db_update(self, url, key, value): + self._tiny_web_db.set_url(url) + return self._tiny_web_db.update(key, value) + + def tiny_web_db_get(self, url, key): + self._tiny_web_db.set_url(url) + return self._tiny_web_db.get(key) + + def tiny_web_db_count(self, url): + self._tiny_web_db.set_url(url) + return self._tiny_web_db.count() + + def tiny_web_db_search(self, url, count): + self._tiny_web_db.set_url(url) + return self._tiny_web_db.search(count) + + def tiny_web_db_delete(self, url, key): + self._tiny_web_db.set_url(url) + return self._tiny_web_db.delete(key) + class TinyWebDB: def __init__(self, url, username, password): - if url[-1] != '/': - url += '/' - self._api_url = url + self._api_url = "" self._username = username self._password = password + self.set_url(url) def update(self, key, value): key = str(key) @@ -383,6 +403,11 @@ class TinyWebDB: if result["status"] == "error": raise RuntimeError(result["message"]) + def set_url(self, url): + if url[-1] != '/': + url += '/' + self._api_url = url + def _request(self, op, param=""): data = "user={}&secret={}&action={}".format(self._username, self._password, op) if param: