SDK สำหรับ TESAIoT Dev Kit
คู่มืออ้างอิง API และ Tutorial (MTB & µPython)
Toggle main menu visibility
Loading...
Searching...
No Matches
claw_transport.h
Go to the documentation of this file.
1
/*******************************************************************************
2
* File Name: claw_transport.h
3
*
4
* Description: BentoClaw transport abstraction — HTTPS POST to TESAIoT
5
* APISIX gateway. Uses cy_http_client over TLS.
6
*
7
* API:
8
* claw_https_connect(host, port, api_key) -> bool
9
* claw_https_post(path, json, json_len, resp, resp_max) -> int
10
* claw_https_disconnect() -> void
11
* claw_https_connected() -> bool
12
*
13
*******************************************************************************/
14
15
#ifndef CLAW_TRANSPORT_H
16
#define CLAW_TRANSPORT_H
17
18
#include <stdint.h>
19
#include <stddef.h>
20
#include <stdbool.h>
21
22
/* Connection state */
23
bool
claw_https_connected
(
void
);
24
25
/* Connect to TESAIoT APISIX gateway.
26
* host: APISIX hostname (e.g., "api.tesaiot.com")
27
* port: HTTPS port (typically 443)
28
* api_key: device API key for key-auth plugin
29
* Returns true on success. */
30
bool
claw_https_connect
(
const
char
*host, uint16_t port,
const
char
*api_key);
31
32
/* Plaintext HTTP, for keyless public endpoints that carry nothing worth
33
* hiding (the weather services). Never send an API key over this. Separate
34
* from claw_https_connect() on purpose: the port number there is attacker-
35
* reachable, so it must not be able to select plaintext. */
36
bool
claw_http_connect_insecure
(
const
char
*host, uint16_t port);
37
38
/* GET on the open connection. Returns body length, or -1. Used for the
39
* keyless services the watch face reads (weather, IP geolocation). */
40
int
claw_https_get
(
const
char
*path,
char
*resp_buf,
size_t
resp_max);
41
42
/* POST JSON to endpoint.
43
* path: API path (e.g., "/ai/v1/chat")
44
* json: request body (JSON string)
45
* json_len: length of json
46
* resp_buf: output buffer for response body
47
* resp_max: max bytes to write to resp_buf
48
* Returns response body length, or -1 on error. */
49
int
claw_https_post
(
const
char
*path,
const
char
*json,
size_t
json_len,
50
char
*resp_buf,
size_t
resp_max);
51
52
/* Disconnect from server. */
53
void
claw_https_disconnect
(
void
);
54
55
#endif
/* CLAW_TRANSPORT_H */
claw_http_connect_insecure
bool claw_http_connect_insecure(const char *host, uint16_t port)
claw_https_get
int claw_https_get(const char *path, char *resp_buf, size_t resp_max)
claw_https_disconnect
void claw_https_disconnect(void)
ปิดการเชื่อมต่อ; ต้องตามด้วย claw_trust_set(CLAW_TRUST_USB)
claw_https_connect
bool claw_https_connect(const char *host, uint16_t port, const char *api_key)
เปิดการเชื่อมต่อ TLS และเก็บ API key ไว้; ยกระดับ trust ก่อน และตั้งกลับเมื่อล้มเหลว
claw_https_post
int claw_https_post(const char *path, const char *json, size_t json_len, char *resp_buf, size_t resp_max)
POST json ไปยัง path; คืนค่าเป็นจำนวนไบต์ของคำตอบที่เขียนได้ และติดลบเมื่อล้มเหลว
claw_https_connected
bool claw_https_connected(void)
predicate บอกสถานะการเชื่อมต่อ; ตรวจก่อน circuit breaker ต้นทุนต่ำและเรียกได้อย่างปลอดภัยทุกเมื่อ
dist
mpy_secure
include
claw_transport.h
Generated by
1.18.0