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