send and receive data with bluetooth module hc05
Dependencies: atterm hc_05 mbed
main.cpp
- Committer:
- rainerraul
- Date:
- 2018-08-27
- Revision:
- 5:cc0c131a5d39
- Parent:
- 4:f292b8762a27
- Child:
- 6:eb3f0392ebd9
File content as of revision 5:cc0c131a5d39:
#include "mbed.h" #include "at.h" #include "hc05.h" bt_modul_hc05 hc05; DigitalOut led1(LED1); char *receive, *ok; void menu(); void getInfo(); int main() { pc.terminal_init(38400, ON); hc05.initUART(UART6, 38400, OFF); wait(1.0); pc.pc_send("Menu\r\n", ""); while(1) { wait(0.5); menu(); } } void menu() { if(strncmp(pc.buffer, "pin", 3) == 0) { pc.pc_send("set pin: %s", hc05.set_modul_pincode(pc.buffer + 4)); } else if(strncmp(pc.buffer, "name", 4) == 0) { pc.pc_send("set name: %s", hc05.set_modul_name(pc.buffer + 5)); } else if(strncmp(pc.buffer, "mastermode", 10) == 0) { hc05.init_master_fixed("0000", "nucleo", "2015,11,27524"); pc.pc_send("master init OK\r\n", ""); } else if(strncmp(pc.buffer, "role", 4) == 0) { ROLE r; if(strcmp(pc.buffer + 5, "1") == 0) { r = MASTER; } else if(strcmp(pc.buffer + 5, "0") == 0) { r = SLAVE; } pc.pc_send("state role: %s", hc05.set_modul_role(r)); } else if(strncmp(pc.buffer, "uart", 4) == 0) { pc.pc_send("set uart: %s", hc05.set_modul_uart(pc.buffer + 5)); } else if(strcmp(pc.buffer, "info") == 0) { getInfo(); } else if(strcmp(pc.buffer, "search") == 0) { pc.pc_send("%s", "CMD : ADDR0 : ADDR1 : ADDR2, CLASS, RSSI\r\n"); pc.pc_send("%s", hc05.search_device()); } else if(strcmp(pc.buffer, "end search") == 0) { pc.pc_send("end search: %s", hc05.set_modul_inqc()); } else if(strncmp(pc.buffer, "send", 4) == 0) { hc05.data_send(pc.buffer + 5); pc.pc_send("Data send\r\n", ""); } pc.clear(); } void getInfo() { pc.pc_send("state: %s\r\n", hc05.get_modul_state()); pc.pc_send("own address: %s\r\n", hc05.get_modul_address()); pc.pc_send("name is: %s\r\n", hc05.get_modul_name()); pc.pc_send("pin is: %s\r\n", hc05.get_modul_pincode()); pc.pc_send("role is: %s\r\n", hc05.get_modul_role()); pc.pc_send("uart settings are: %s\r\n", hc05.get_modul_uart()); }