blob: b21191303baa6e0cf50ca1582f14b0812d95eb33 [file] [log] [blame]
liubin281ac462023-07-19 14:22:54 +08001#include <string.h>
2#include "mbtk_type.h"
liubin281ac462023-07-19 14:22:54 +08003#include "mbtk_coap.h"
4#include "mbtk_coap_api.h"
5
6int coap_get_method(void);
7
8int coap_post_method(void);
9
10
11int main(int argc, char *argv[])
12{
13 char operator[10];
14 int opt;
15 int ret = -1;
16
17 printf("coap_demo star\r\n");
18 coap_get_method();
19
20 sleep(20);
21 coap_post_method();
22
23 return 0;
24}
25
26
27int coap_get_method(void)
28{
29 int ret = -1;
30 ret = mbtk_coap_ecoapnew_exec_cmd("134.102.218.18",5683,0,0); //server ip, port
31 mbtk_coap_ecoapmsgid_exec_cmd(1); //set message id
32 mbtk_coap_ecoaptype_exec_cmd(0); //set message type
33 mbtk_coap_ecoapcode_exec_cmd(1); //set Get request method
34 mbtk_coap_ecoapopt_exec_cmd("b474657374",10); //set option
35
36 mbtk_coap_ecoapsend_exec_cmd(1, 0, NULL); //request Get
37 return 0;
38}
39
40
41int coap_post_method(void)
42{
43 int ret = -1;
44 ret = mbtk_coap_ecoapnew_exec_cmd("134.102.218.18",5683,0,0); //server ip, port
45 mbtk_coap_ecoapmsgid_exec_cmd(3); //set message id
46 mbtk_coap_ecoaptype_exec_cmd(0); //set message type
47 mbtk_coap_ecoapcode_exec_cmd(2); //set Post request method
48 mbtk_coap_ecoapopt_exec_cmd("b474657374",10); //set option
49
50 mbtk_coap_ecoapsend_exec_cmd(3, 7, "1111111"); //request post
51 return 0;
52}