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