Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
hm11.h
00001 /* 00002 @file hm11.h 00003 00004 @brief Bluetooth Low Energy v4.0 HM-11 Breakout Library 00005 00006 @Author lukasz uszko(luszko@op.pl) 00007 00008 Tested on FRDM-KL25Z and STM32NUCLEO 00009 00010 Copyright (c) 2014 lukasz uszko 00011 Released under the MIT License (see http://mbed.org/license/mit) 00012 00013 Documentation regarding the HM-11 Bluetooth Low energy module can be found here: 00014 https://www.microduino.cc/wiki/images/f/fc/Bluetooth40_en.pdf 00015 http://txyz.info/b10n1c/datasheets/hm-11_bluetooth40_en.pdf 00016 */ 00017 00018 //HM-11 Device Pinout: 00019 // Pin Name Description 00020 // 1 UART_RTS UART interface 00021 // 2 UART_TX UART interface 00022 // 3 UART_CTS UART interface 00023 // 4 UART_RX UART interface 00024 // 5 NC NC 00025 // 6 NC NC 00026 // 7 NC NC 00027 // 8 NC NC 00028 // 9 CC V3.3 00029 // 10 NC NC or VCC 00030 // 11 RESETB Reset if low <100ms 00031 // 12 GND Ground 00032 // 13 PIO3 Programmable input/output line 00033 // 14 PIO2 Programmable input/output line 00034 // 15 PIO1 System LED 00035 // 16 PIO0 System KEY 00036 00037 // AT Commands 00038 // Factory default setting: 00039 // Name: HMSoft; Baud: 9600, N, 8, 1; Pin code: 000000; transmit 00040 00041 00042 //DEMO - HOW TO USE: 00043 //compiled and built under mbed 00044 /* 00045 ---------------------------------------- DEMO: 1st version -simple polling ---------------------------------------- 00046 #include "mbed.h" 00047 #include "hm11.h" 00048 00049 00050 #define HM11_PIN_TX PTE22 //FRDM-KL25Z UART2 00051 #define HM11_PIN_RX PTE23 00052 00053 int main() { 00054 Serial usbDebug(USBTX, USBRX); 00055 usbDebug.printf("HELLO WORLD !"); 00056 00057 00058 HM11* hm11 = new HM11( HM11_PIN_TX, HM11_PIN_RX); 00059 int counter =0; 00060 while(1) { 00061 //myled = 1; 00062 wait(0.5); 00063 usbDebug.printf("alive "); 00064 wait(0.5); 00065 char buf[2]; 00066 snprintf(buf,2,"%d",counter++); 00067 if(counter>9) 00068 counter=0; 00069 hm11->sendDataToDevice(buf); 00070 wait(0.2); 00071 00072 while(hm11->isRxDataAvailable()) 00073 usbDebug.printf("data: %c\r\n",hm11->getDataFromRx()); 00074 00075 } 00076 } 00077 */ 00078 00079 00080 00081 #ifndef HM11_H 00082 #define HM11_H 00083 00084 00085 #include "mbed.h" 00086 #include "BufferedSerial.h" 00087 00088 #define HM11_SERIAL_DEFAULT_BAUD 9600 00089 #define HM11_SERIAL_TIMEOUT 10000 00090 #define HM11_SERIAL_EOL "\r\n" 00091 00092 static const char* hm11TestCommands[]={"AT","AT+","CONNL","RENEW","RESET","START","SLEEP","?"}; 00093 00094 static const char* hm11SendCommands[]={"ADDR","BAUD","CLEAR","CON", 00095 "FILT","HELP","IMME","MODE", 00096 "NOTI","NAME","PARI","PIO1", 00097 "PIO","PASS","PIN","POWE", 00098 "PWRM","ROLE", 00099 "RSSI","RADD","STOP", 00100 "SAVE","TCON","TYPE","VERR","VERS" 00101 }; 00102 00103 static const char* HM11ReceiveMsgs[]={"OK","OK+","Get:","Set:","LOST","ADDR:","CLEAR","CONN", 00104 "NAME","Set","PIO:","RENEW","RESET","RSSI:","RADD:", 00105 "START","SLEEP","TCON","RSSI:","RADD:","CONNF" 00106 }; 00107 00108 typedef enum hm11CommandsType_t{ 00109 HM11_TEST_COMMAND=0, 00110 HM11_SEND_COMMAND, 00111 HM11_NUM_OF_COMMAND_TYPE 00112 }HM11CommandType; 00113 00114 typedef enum hm11TestCommands_t{ 00115 HM11_AT_TEST =0, 00116 HM11_START_CMD, 00117 HM11_CONNECT_TO_LAST_SUCCEEDED_DEVICE , // 00118 HM11_RESTORE_ALL, // 00119 HM11_RESET_MODULE, // 00120 HM11_WORK_IMMEDIATELY, // 00121 HM11_SLEEP_MODE, // 00122 HM11_QUERY_SIGN, 00123 HM11_NUM_OF_TEST_COMMANDS 00124 }HM11TestCommands; 00125 00126 00127 typedef enum hm11Commands_t{ 00128 HM11_ADDRESS, 00129 HM11_BAUDRATE, 00130 HM11_CLEAR_LAST_CONNECTED_DEVICE_ADDRESS , 00131 HM11_CONNECT_TO_ADDRESS, 00132 HM11_FILTER_AT_COMMAND_PARAMETER, 00133 HM11_HELP_INFORMATION, 00134 HM11_MODULE_WORK_TYPE, 00135 HM11_MODULE_WORK_MODE, 00136 HM11_NOTIFY_INFORMATION, 00137 HM11_MODULE_NAME, 00138 HM11_PARITY_BIT, 00139 HM11_PIO1_OUTPT_STATUS, 00140 HM11_PIO_PINS_HIGH_OR_LOW, 00141 HM11_GET_PIN_CODE, 00142 HM11_PIN_CODE, 00143 HM11_MODULE_POWER, 00144 HM11_MODULE_SLEEP_TYPE, 00145 HM11_MASTER_SLAVE_ROLL, 00146 HM11_RSSI_VALUE, 00147 HM11_LAST_CONNECTED_DEVICE_ADDRESS, 00148 HM11_STOP_BIT, 00149 HM11_MODULE_SAVE_CONNECTED_ADDR_PARAMETER, 00150 HM11_MODULE_CONNECT_REMOTE_DEVICE_TIMEOUT_VALUE, 00151 HM11_MODULE_BOND_MODE, 00152 HM11_SOFTWARE_VERSION, 00153 HM11_NUM_OF_COMMANDS 00154 }HM11Commands; 00155 00156 /** 00157 AT Commands parameters 00158 */ 00159 typedef enum AdvertisingInterval{ 00160 _100ms=0, 00161 _152_5ms, 00162 _211_25ms, 00163 _318_75ms, 00164 _417_5ms, 00165 _546_25ms, 00166 _760ms, 00167 _852_5ms, 00168 _1022_5ms, 00169 _1285ms, 00170 _2000ms, 00171 _3000ms, 00172 _4000ms, 00173 _5000ms, 00174 _6000ms, 00175 _7000ms, 00176 _INVALID_ADV_INTERVAL 00177 }AdvertisingInterval_t; 00178 00179 00180 typedef enum AdvertisingType{ 00181 _AdvertisingScanResponseConnectable=0, 00182 _LastDeviceConnectsIn1_28Seconds, 00183 _AdvertisingScanResponse, 00184 _Advertising, 00185 _INVALID_ADV_TYPE 00186 }AdvertisingType_t; 00187 00188 typedef enum BaudRate{ 00189 _9600=0, 00190 _19200, 00191 _38400, 00192 _57600, 00193 _115200, 00194 _4800, 00195 _2400, 00196 _1200, 00197 _230400, 00198 _INVALID_BAUDRATE 00199 }BaudRate_t; 00200 00201 typedef enum ConnectionStatus{ 00202 _A, // Connecting to an address 00203 _L, // Connecting 00204 _E, // Connect error 00205 _F, // Connect Fail 00206 _N, // No Address 00207 _INVALID_CONECTIONSTATUS 00208 }ConnectionStatus_t; 00209 static const char ConnectionStatusArr[]={'A','L','E','F','N'}; 00210 00211 00212 typedef struct ScanResult{ 00213 char* addr; 00214 char*name; 00215 uint8_t nr; //0-5 00216 }ScanResult_t; 00217 00218 00219 typedef enum DeployMode{ 00220 _BROAD_AND_SCAN=1, //Allowed to broadcast and scanning 00221 _ONLY_BROAD, //Only allow broadcast 00222 _INVALID_DEPLOY_MODE 00223 }DeployMode_t; 00224 00225 00226 typedef enum FilterOfHmModules{ 00227 _ALL_BLE_MODULES=0, //Will find all BLE modules 00228 _ONLY_HM_MODULES, //Only find HM Modules 00229 _INVALID_FILTER 00230 }FilterOfHmModules_t; 00231 00232 00233 typedef enum ModuleWorkType{ 00234 _WAIT_UNTIL_AT_START_RECEIVED=0, //Will find all BLE modules 00235 _WORK_IMMEDIATELY, //Only find HM Modules 00236 _INVALID_MODULE_WORK_TYPE 00237 }ModuleWorkType_t; 00238 00239 00240 typedef enum ModuleWorkMode{ 00241 _TRANSM_MODE=0, 00242 _PIO_COLLECTION_MODE, 00243 _REMOTE_CONTROL_MODE 00244 }ModuleWorkMode_t; 00245 00246 00247 00248 00249 typedef enum ParityBit{ 00250 _NONE=0, 00251 _EVEN, 00252 _ODD 00253 }ParityBit_t; 00254 00255 00256 typedef enum ModulePower{ 00257 _23dbm=0, //-23dbm 00258 __6dbm, //-6dbm 00259 _0dbm, //0dbm 00260 _6dbm, //6dbm 00261 _INVALID_MOD_POWER 00262 }ModulePower_t; 00263 00264 00265 00266 typedef enum SensorType{ 00267 _NONE_SENSOR=0, //None 00268 _DHT11, //dht11 00269 _DS18B20, //ds18b20 00270 _INVALID_SENSOR_TYPE 00271 }SensorType_t; 00272 00273 00274 typedef enum BondMode{ 00275 _NOT_NEED_PIN_CODE=0, 00276 _AUTH_NOT_NEED_PIN, 00277 _AUTH_WITH_PIN, 00278 _AUTH_AND_BOND, 00279 _INVALID_BOND_MODE 00280 }BondMode_t; 00281 00282 00283 class HM11{ 00284 00285 public: 00286 HM11(PinName uartTx , PinName uartRx); 00287 00288 HM11(const BufferedSerial & serial); 00289 00290 bool sendGetCommand(const char* command); 00291 bool sendSetCommand(const char* command,int param); 00292 00293 bool isCorrectCommand(const char* command, HM11CommandType cmdType); 00294 00295 int sendDataToDevice(const char* data); 00296 int sendDataToDevice(const uint8_t * byteData,uint8_t dataLength); 00297 00298 int isRxDataAvailable(); 00299 00300 int copyAvailableDataToBuf(uint8_t *buf, uint8_t bufLength); 00301 00302 inline uint8_t getDataFromRx() 00303 { 00304 return mSerial.getc(); 00305 } 00306 00307 inline void flushBuffers() 00308 { 00309 mSerial.clearRxBuf(); 00310 mSerial.clearTxBuf(); 00311 } 00312 //commandMethods 00313 /** query module address 00314 * @param enable out: module addr (buf size at least 12 bytes +'\0' eg. response: 20C38FF3B987) 00315 * @return 00316 * 1 on success, 00317 * 0 on error. 00318 */ 00319 bool queryModuleAddress(char* addrBuf); 00320 00321 00322 /** Set AdvertisingInterval 00323 * @param AdvertisingInterval_t , default: 100ms 00324 * @return 00325 * 1 on success, 00326 * 0 on error. 00327 * Note1: The maximum 1285ms recommendations form the IOS system. That is to 00328 * say, 1285ms is apple allowed, but in response to scan and connected all the 00329 * time will be long. 00330 * Note2: This command is added since V517 version.V522 allow max value 7000ms 00331 */ 00332 bool setAdvertisingInterval(AdvertisingInterval_t advInt); 00333 00334 00335 /** query AdvertisingInterval 00336 * @return 00337 * AdvertisingInterval_t current set adv_interval 00338 */ 00339 AdvertisingInterval_t queryAdvertisingInterval(void); 00340 00341 00342 /** Set AdvertisingType 00343 * @param AdvertisingType_t, default: Adevertising,ScanResponse,Connectable 00344 * @return 00345 * 1 on success, 00346 * 0 on error. 00347 * Note1: Added since V519 00348 */ 00349 bool setAdvertisingType(AdvertisingType_t advType); 00350 00351 00352 /** query AdvertisingType 00353 * @return 00354 * AdvertisingType_t - current set advertising type 00355 */ 00356 AdvertisingType_t queryAdvertisingType(void); 00357 00358 00359 /** Set ANCS switch 00360 * @param enable |0: Off |1: On |Default: 0 00361 * @return 00362 * 1 on success, 00363 * 0 on error. 00364 * Note1: This command added in V524. 00365 * Note2: Please send AT+RESET to restart module if you set value 1. 00366 * Note3: Must execute AT+TYPE3 first. 00367 */ 00368 bool setAncsSwitch(uint8_t enable); 00369 00370 00371 /** query ANCS switch 00372 * @return 00373 * 1 -On, 00374 * 0 -Off 00375 * 0xFF -error 00376 * Note1: This command added in V524. 00377 * Note2: Please send AT+RESET to restart module if you set value 1. 00378 * Note3: Must execute AT+TYPE3 first. 00379 */ 00380 uint8_t queryAncsSwitch(void); 00381 00382 00383 /** Set Whitelist switch 00384 * @param enable |0: Off |1: On |Default: 0 00385 * @return 00386 * 1 on success, 00387 * 0 on error. 00388 * Note1: This command added in V523 00389 * Note2: Whitelist allow three mac address link to module. Please use AT+AD command set whitelist mac address. 00390 */ 00391 bool setWhitelistSwitch(uint8_t enable); 00392 00393 00394 /** query Whitelist Switch 00395 * @return 00396 * 1 - On, 00397 * 0 - Off, 00398 * 0xFF -error. 00399 * Note1: This command added in V523 00400 * Note2: Whitelist allow three mac address link to module. Please use AT+AD command set whitelist mac address. 00401 */ 00402 uint8_t queryWhitelistSwitch(void); 00403 00404 00405 /** Set whitelist mac address 00406 * @param nrOfMacAddrLinkedToModule |1,2,3 00407 * @param macAddress |eg. 001122334455 00408 * @return 00409 * 1 on success, 00410 * 0 on error. 00411 */ 00412 bool setWhitelistMacAddress(uint8_t nrOfMacAddrLinkedToModule, const char* const macAddress); 00413 00414 00415 /** query whitelist mac address 00416 * @param: 00417 * [in]: nrOfMacAddrLinkedToModule |1,2,3 00418 * [in]: len of mac addr buf 00419 * [out]:macAddrBuf 00420 * @return 00421 * true - ok 00422 * false - error 00423 */ 00424 bool queryWhitelistMacAddress(uint8_t nrOfMacAddrLinkedToModule, char* const macAddrBuf, uint8_t macAddrBufLen); 00425 00426 00427 /** Set battery monitor switch 00428 * @param uint8_t battSwitchEnable: |0: Off |1: On |Default: 0 00429 * @return 00430 * 1 on success, 00431 * 0 on error. 00432 * Note1: This command added in V520 00433 */ 00434 bool setBatteryMonitorSwitch(uint8_t battSwitchEnable); 00435 00436 00437 /** query BatteryMonitorSwitch 00438 * @return 00439 * batt switch state: |0: Off |1: On 00440 * 0xFF -error 00441 * Note1: This command added in V520. 00442 */ 00443 uint8_t queryBatteryMonitorSwitch(void); 00444 00445 00446 00447 /**Query battery information 00448 * @return 00449 * batt information: 000~100 00450 * 0xFF -error 00451 * 00452 * There has three ways to get battery information: 00453 a. Before establishing a connection, Send “AT+BATT?” through UART. 00454 b. After established a connection, In Mode 1 or 2, remote side send“AT+BATT?” 00455 Battery information has included in scan response data package, one hour update once 00456 */ 00457 uint8_t queryBatteryInformation(void); 00458 00459 00460 00461 /** Set iBeacon into service mode(*) 00462 * @return 00463 * 1 on success, 00464 * 0 on error. 00465 * This command is added in V520, Removed in V521, Please use AT+DELO 00466 * This command set iBeacon into service mode until next power on. 00467 * In service mode, module not allow any link request. 00468 * BUSHU is Chinese spelling, meaning the deployment. 00469 * Note: Should to open iBeacon switch first (AT+IBEA). 00470 */ 00471 bool setIBeaconIntoServiceMode(void); 00472 00473 00474 00475 /** Set Bit format 00476 * @param bit7Format: 0:NotCompatible, 1:Compatible 00477 * @return 00478 * 1 NotCompatible, 00479 * 0 Compatible, 00480 * 0xFF Error 00481 * This command is used only for compatible uses 7 data bits, 2 stop bit device. 00482 */ 00483 bool setBitFormat(uint8_t bit7Format); 00484 00485 00486 /**Query BitFormat 00487 * @return 00488 * bit7 Swu=itch 00489 * 0xFF -error 00490 */ 00491 uint8_t queryBitFormat(void); 00492 00493 00494 /** Set baud rate 00495 * @param baud: Baudrate value 00496 * @return 00497 * 1 success, 00498 * 0 Error, 00499 */ 00500 bool setBaudRate(BaudRate_t baud); 00501 00502 00503 00504 /**Query baud rate 00505 * @return 00506 * Baudrate_t - Baudrate value 00507 */ 00508 BaudRate_t queryBaudRate(void); 00509 00510 /** Set Characteristic value 00511 * @param chValue (characteristic value): 0x0001~0xFFFE 00512 * @return 00513 * 1 success, 00514 * 0 Error, 00515 */ 00516 bool setCharacteristic(uint16_t chValue); 00517 00518 00519 00520 /**Query Characteristic value 00521 * @return 00522 * characteristic value: 0x0001~0xFFFE 00523 * error :0xFFFF 00524 */ 00525 uint16_t queryCharacteristic(void); 00526 00527 00528 /** Try connect to last succeeded device 00529 * @return 00530 * ConnectionStatus_t connection status. 00531 * Notice: Only Central role is used. 00532 * If remote device has already connected to other device or shut down, 00533 * “OK+CONNF” will received after about 10 seconds. 00534 */ 00535 ConnectionStatus_t connectToLastDevice(void); 00536 00537 00538 /** Try connect an address 00539 * @param address e.g." 0017EA090909 " 00540 * @return connection status 00541 * Notice: Only Central role is used. 00542 * If remote device has already connected to other device or shut down, 00543 * “OK+CONNF” will received after about 10 seconds. 00544 * 00545 * Notice: Only central role is used. 00546 If remote device has already connected to other device or shut down, 00547 “OK+CONNF” will received after about 10 Seconds. 00548 e.g. 00549 Try to connect an device which MAC address is 00:17:EA:09:09:09 00550 Send: AT+CON0017EA090909 00551 May receive a reply: 00552 OK+CONNA ========= Accept request, connecting 00553 OK+CONNE ========= Connect error 00554 OK+CONN ========= Connected, if AT+NOTI1 is setup 00555 OK+CONNF ========= Connect Failed, After 10 seconds 00556 */ 00557 ConnectionStatus_t connectToAnAddress(const char* address); 00558 00559 00560 /**Query PIO04~PIO11 input(output) state 00561 * @return 00562 * in/out state: 0x00~0xFF 00563 * 00564 * This command is added since V515 version. 00565 */ 00566 uint8_t queryInputOutputState(void); 00567 00568 00569 /**Set PIO collection rate 00570 * @param colRateSec (PIO collection rate): 00-99 unit[s] 00571 * @return 00572 * 1 success, 00573 * 0 Error, 00574 * 00575 * In mode 1, when PIO state is change, module will send OK+Col:[xx] to 00576 * UART or remote side. This command is set send interval. 00577 * This command is added since V515 version. 00578 */ 00579 bool setPioCollectionRate (uint8_t colRateSec); 00580 00581 00582 00583 /**Query PIO collection rate 00584 * @return 00585 * PIO collection rate: 00-99 unit[s] 00586 * error :0xFF 00587 */ 00588 uint8_t queryPioCollectionRate(void); 00589 00590 00591 00592 /**Start a device discovery scan 00593 * @param [out] scanRes 00594 * @return 00595 * 1 success, 00596 * 0 Error, 00597 00598 Please set AT+ROLE1 and AT+IMME1 first. 00599 ---usage--: 00600 Send: AT+DISC? 00601 Recv: OK+DISCS 00602 Recv: OK+DISC:123456789012 (discovered device address information) 00603 If AT+SHOW1 is setup, you will receive then Name information as follow 00604 Recv: OK+NAME: xxx 00605 After send Name value, will send two extra “\r\n” value ASCII byte 00606 Recv: OK+DISC:234567890123 00607 Recv: OK+NAME: xxx 00608 After send Name value, will send two extra “\r\n” value ASCII byte ...(Max results is 6, use array 0~5) 00609 Recv: OK+DISCE 00610 Connect to a discovered device: AT+CONN0, AT+CONN1……AT+CONN5 00611 */ 00612 bool startDeviceDiscoveryScan(ScanResult_t* scanRes); 00613 00614 00615 00616 /**Connect to an Discovery device 00617 * @param [in] scanRes 00618 * @return 00619 * 1 success, 00620 * 0 Error, 00621 00622 This command is use after execute AT+DISC? 00623 This command will clear all discovery data. 00624 */ 00625 bool connectToDiscoveryDevice(ScanResult_t* scanRes); 00626 00627 00628 00629 /**Set IBeaconDeployMode 00630 * @param depMode - DeployMode_t 00631 * @return 00632 * 1 success, 00633 * 0 Error, 00634 * 00635 * After receive OK+DELO[para1], module will reset after 500ms. 00636 * This command will let module into non-connectable status until next power on. 00637 */ 00638 bool setIBeaconDeployMode(DeployMode_t depMode); 00639 00640 00641 /**Set filter of HM modules 00642 * @param filter -FilterOfHmModules_t 00643 * @return 00644 * 1 success, 00645 * 0 Error, 00646 */ 00647 bool setFilterOfHmModules(FilterOfHmModules_t filter); 00648 00649 00650 /**Query filter of HM modules 00651 * @return 00652 * Type of filter 00653 */ 00654 FilterOfHmModules_t queryFilterOfHmModules(void); 00655 00656 00657 00658 /**Remove bond information 00659 * @return 00660 * 1 success, 00661 * 0 Error, 00662 * Note1: Added in V524 version. 00663 */ 00664 bool removeBondInformation(void); 00665 00666 00667 /**System Help Information 00668 * @param [in] char* helpInformation 00669 * @return 00670 * 1 success, 00671 * 0 Error, 00672 */ 00673 bool getSystemHelpInformation(char* helpInformationBuf); 00674 00675 00676 /**Set Module work type 00677 * @param modWorkType -ModuleWorkType_t 00678 * @return 00679 * 1 success, 00680 * 0 Error, 00681 * This command is only used for Central role. 00682 */ 00683 bool setModuleWorkType(ModuleWorkType_t modWorkType); 00684 00685 00686 /**Query Module work type 00687 * @return 00688 * module Work Type -ModuleWorkType_t 00689 * This command is only used for Central role. 00690 */ 00691 ModuleWorkType_t queryModuleWorkType(void); 00692 00693 00694 00695 00696 00697 /**Set Module iBeacon Switch 00698 * @param turnOnOff 00699 0: Turn off iBeacon 00700 * 1: Turn on iBeacon 00701 * @return 00702 * 1 success, 00703 * 0 Error, 00704 * This command is added since V517 version. 00705 */ 00706 bool setModuleIBeaconSwitch (uint8_t turnOnOff); 00707 00708 00709 /**Query iBeacon switch 00710 * @return 00711 * 0: Turn off iBeacon 00712 * 1: Turn on iBeacon 00713 * This command is added since V517 version. 00714 */ 00715 uint8_t queryModuleIBeaconSwitch (void); 00716 00717 00718 00719 /**Set iBeacon UUID 00720 * @param: iBeacon Uuid - 0x00000001~0xFFFFFFFE 00721 * @return 00722 * 1 success, 00723 * 0 Error, 00724 * This command is added since V520 version. 00725 * Default: iBeacon UUID is: 74278BDA-B644-4520-8F0C-720EAF059935. 00726 * - uuid1 is 74278BDA 00727 * - uuid2 is B644-4520 00728 * - uuid1 is 8F0C-720E 00729 * - uuid1 is AF059935 00730 */ 00731 bool setIBeaconUuid (uint32_t uuid0,uint32_t uuid1,uint32_t uuid2, uint32_t uuid3); 00732 bool setIBeaconUuid (uint32_t* uuid); 00733 00734 /**Query iBeacon Uuid 00735 * @param: part of uuid - 0~3 00736 * @return 00737 * iBeacon Uuid - 0x00000001~0xFFFFFFFE 00738 * Error - 0x00 00739 * This command is added since V520 version. 00740 */ 00741 uint32_t queryIBeaconUuid(uint32_t* nr_of_uuid); 00742 00743 00744 00745 00746 /**Set Module iBeacon major version 00747 * @param: major version- 0x0001~0xFFFE 00748 * @return 00749 * 1 success, 00750 * 0 Error, 00751 ^ Default: 0xFFE0 00752 * This command is added since V517 version. 00753 */ 00754 bool setIBeaconMajor(uint16_t mjrVersion); 00755 00756 00757 /**Query Module iBeacon major 00758 * @return 00759 * iBeacon major version- 0x0001~0xFFFE 00760 * Error - 0x0000 00761 * This command is added since V517 version. 00762 */ 00763 uint16_t queryIBeaconMajor(void); 00764 00765 00766 00767 /**Set Module iBeacon minor version 00768 * @param: minorversion- 0x0001~0xFFFE 00769 * @return 00770 * 1 success, 00771 * 0 Error, 00772 ^ Default: 0xFFE1 00773 * This command is added since V517 version. 00774 */ 00775 bool setIBeaconMinor(uint16_t mnrVersion); 00776 00777 00778 /**Query Module iBeacon minor 00779 * @return 00780 * iBeacon minor version- 0x0001~0xFFFE 00781 * Error - 0x0000 00782 * This command is added since V517 version. 00783 */ 00784 uint16_t queryIBeaconMinor(void); 00785 00786 00787 00788 00789 /**Set Module iBeacon Measured power 00790 * @param: measured Power 0x0001~0xFFFE 00791 * @return 00792 * 1 success, 00793 * 0 Error, 00794 ^ Default: 0xFFE1 00795 * This command is added since V519 version. 00796 */ 00797 bool setIBeaconMeasuredPower(uint16_t measuredPwr); 00798 00799 00800 /**Query Module iBeacon Measured power 00801 * @return 00802 * iBeacon minor version- 0x0001~0xFFFE 00803 * Error - 0x0000 00804 * This command is added since V519 version. 00805 */ 00806 uint16_t queryIBeaconMeasuredPower(void); 00807 00808 00809 00810 00811 /**Set Module Work Mode 00812 * @param: WorkMode_t 00813 * @return 00814 * 1 success, 00815 * 0 Error, 00816 ^ Default: 0xFFE1 00817 * This command is added since V519 version. 00818 */ 00819 bool setModuleWorkMode(ModuleWorkMode_t workMode); 00820 00821 00822 /**Query Module Work Mode 00823 * @return 00824 * iBeacon minor version- 0x0001~0xFFFE 00825 * Error - 0x0000 00826 * This command is added since V519 version. 00827 */ 00828 ModuleWorkMode_t queryModuleWorkMode(void); 00829 00830 00831 00832 00833 /**Set Module name 00834 * @param: name, length<12 00835 * @return 00836 * 1 success, 00837 * 0 Error, 00838 */ 00839 bool setModuleName(char* name, uint8_t nameLength); 00840 00841 00842 /**Query Module name 00843 * @param: name -> ptr to response buffer 00844 * @return 00845 * 1 success, 00846 * 0 Error, 00847 */ 00848 bool queryModuleName(char *name); 00849 00850 00851 00852 00853 /**Set Module parity bit 00854 * @param: ParityBit_t pBit 00855 * @return 00856 * 1 success, 00857 * 0 Error, 00858 */ 00859 bool setParityBit(ParityBit_t pBit); 00860 00861 00862 /**Query Module parity bit 00863 * @return 00864 * _ODD, _EVEN- val 00865 _NONE - error 00866 */ 00867 ParityBit_t queryParityBit(void); 00868 00869 00870 /**Set PIO1 output status (System LED) 00871 * @param: 00872 * uint8_t status[0~1] 00873 * 0 -Unconnected Output, 500ms High 500ms Low,Connected output High. 00874 * 1 -1: Unconnected output, Low, Connected output High. 00875 * @return 00876 * 1 success, 00877 * 0 Error, 00878 */ 00879 bool setPio1OutputStatus(uint8_t status); 00880 00881 00882 /**Query PIO1 output status (System LED) 00883 * @return 00884 * uint8_t status[0~1] 00885 * 0 -Unconnected Output, 500ms High 500ms Low,Connected output High. 00886 * 1 -1: Unconnected output, Low, Connected output High. 00887 * 0xFF - error 00888 */ 00889 uint8_t queryPio1OutputStatus(void); 00890 00891 00892 00893 00894 00895 /**Set PIO pins output /high or low 00896 * @param: 00897 * nrOfPio - is which PIO pin you want to Query/Set: Value: 2,3,4,5,6,7,8,9,A,B 00898 * val - Query or setup value. Value: 0 is low and 1 is high 00899 * @return 00900 * 1 success, 00901 * 0 Error, 00902 */ 00903 bool setPioPinsOutput(uint8_t nrOfPio, uint8_t val ); 00904 00905 00906 /**Query PIO pins output /high or low 00907 * @param: 00908 * nrOfPio - is which PIO pin you want to Query/Set: Value: 2,3,4,5,6,7,8,9,A,B 00909 * @return 00910 * uint8_t val - state of given PIO: 0- low and 1 -high 00911 * 0xFF - error 00912 */ 00913 uint8_t queryPioPinsOutput(uint8_t nrOfPio); 00914 00915 00916 00917 00918 /**Set Pin Code 00919 * @param: 00920 * pinCode - value: 0~999999 00921 * Default: 000000 00922 * @return 00923 * 1 success, 00924 * 0 Error, 00925 */ 00926 bool setPinCode (uint32_t pinCode ); 00927 00928 00929 /**Query Pin Code 00930 * @return 00931 * pinCode - value: 0~999999 00932 * 0xFFFFFFFF - error 00933 */ 00934 uint8_t queryPinCode (void); 00935 00936 00937 00938 00939 /**Set Module Power 00940 * @param: 00941 * modPower - value: 0~999999 00942 * Default: 2 00943 * @return 00944 * 1 success, 00945 * 0 Error, 00946 */ 00947 bool setModulePower(ModulePower_t modPower); 00948 00949 00950 /**Query Module Power 00951 * @return 00952 * modPower 00953 * _NONE - error 00954 */ 00955 ModulePower_t queryModulePower (void); 00956 00957 00958 00959 /**Set Module sleep type 00960 * @param: 00961 * modSleepType[0~1] - value: 0-Auto sleep, 1-don’t auto sleep 00962 * Default: 1 00963 * @return 00964 * 1 success, 00965 * 0 Error, 00966 */ 00967 bool setModuleSleepType(uint8_t modSleepType ); 00968 00969 00970 /**Query Module sleep type 00971 * @return 00972 * modSleepType 00973 * 0xFF - error 00974 */ 00975 uint8_t queryModuleSleepType (void); 00976 00977 00978 00979 /**Restore all setup value to factory setup 00980 * @return 00981 * 1 success, 00982 * 0 Error, 00983 */ 00984 bool restoreAll(void); 00985 00986 00987 /**Restart module 00988 * @return 00989 * 1 success, 00990 * 0 Error, 00991 */ 00992 bool restartModule(void); 00993 00994 00995 00996 /**Set Master and Slaver Role 00997 * @param: 00998 * role[0~1] - value: 0-Peripheral , 1-Central 00999 * Default: 0 01000 * @return 01001 * 1 success, 01002 * 0 Error, 01003 */ 01004 bool setMasterAndSlaveRole(uint8_t role); 01005 01006 01007 /**Query Master and Slaver Role 01008 * @return 01009 * role [0~1] - value: 0-Peripheral , 1-Central 01010 * 0xFF - error 01011 */ 01012 uint8_t queryMasterAndSlaveRole(void); 01013 01014 01015 01016 /**Query Query RSSI Value 01017 * @return 01018 * rssi - value: 01019 * 0xFF - error 01020 * Require: AT+MODE value > 0 01021 * Note: This command only used by Remote device query when connected. 01022 */ 01023 uint8_t queryRssiValue(void); 01024 01025 01026 01027 /**Query Last Connected Device Address 01028 * @return 01029 * addr - value: 01030 * null - error 01031 */ 01032 char* queryLastConnectedDeviceAddress(void); 01033 01034 01035 01036 /**Set Module Sensor work interval 01037 * @param: 01038 * interval [0~99] - values: 0-Save when connected, 1-Don’t Save ; Unit: minute 01039 * Default: 0 01040 * @return 01041 * 1 success, 01042 * 0 Error, 01043 * Note: This command is only use for HMSensor 01044 */ 01045 bool setModuleSensorWorkInterval(uint8_t interval); 01046 01047 01048 /**Query module Sensor work interval 01049 * @return 01050 * interval [0~99] - values: 0-Save when connected, 1-Don’t Save ; Unit: minute 01051 * 0xFF - error 01052 * Note: This command is only use for HMSensor 01053 */ 01054 uint8_t queryModuleSensorWorkInterval(void); 01055 01056 01057 01058 /**Work immediately 01059 * @return 01060 * 1 success, 01061 * 0 Error, 01062 * Note: This command is only used when AT+IMME1 is setup. 01063 */ 01064 bool workImmediately(void); 01065 01066 01067 01068 /**Query Module into sleep mode 01069 * @return 01070 * 1 success, 01071 * 0 Error, 01072 * Note: Only support Peripheral role. 01073 */ 01074 bool queryModuleIntoSleepMode(void); 01075 01076 01077 01078 /**Set Module save connected address parameter 01079 * @param: 01080 * saveParam [0~1] - values: 0-Save when connected, 1-Don’t Save 01081 * Default: 0 01082 * @return 01083 * 1 success, 01084 * 0 Error, 01085 */ 01086 bool setModuleSaveConnectedAddressParam(uint8_t saveParam); 01087 01088 01089 /**Query Module save connected address parameter 01090 * @return 01091 * saveParam [0~1] - values: 0-Save when connected, 1-Don’t Save 01092 * 0xFF - error 01093 */ 01094 uint8_t queryModuleSaveConnectedAddressParam(void); 01095 01096 01097 01098 /**Set sensor type on module PIO11(HM-11 is PIO3) 01099 * @param: 01100 * SensorType_t sensorType 01101 * Default: _NONE_SENSOR 01102 * @return 01103 * 1 success, 01104 * 0 Error, 01105 * Note: This command is use for HMSensor 01106 */ 01107 bool setSensorTypeOnModulePio(SensorType_t sensorType); 01108 01109 01110 /**Query sensor type on module PIO11(HM-11 is PIO3) 01111 * @return 01112 * SensorType_t sensorType 01113 * 0xFF - _INVALID_SENSOR_TYPE 01114 * Note: This command is use for HMSensor 01115 */ 01116 SensorType_t querySensorTypeOnModulePio(void); 01117 01118 01119 01120 /**Set discovery parameter 01121 * @param: 01122 * discoverParam [0~1] - values: 0-Don’t show name, 1-Show name 01123 * Default: 0 01124 * @return 01125 * 1 success, 01126 * 0 Error, 01127 * 01128 * Note:Please execute AT+FILT0 first. 01129 * If AT+SHOW1 is setup, AT+DISC? Command will show you name information 01130 * included into scan result package. 01131 */ 01132 bool setDiscoveryParameter (SensorType_t discoverParam); 01133 01134 01135 /**Query discovery parameter 01136 * @return 01137 * discoverParam [0~1] - values: 0-Don’t show name, 1-Show name 01138 * 0xFF - error 01139 */ 01140 uint8_t queryDiscoveryParameter (void); 01141 01142 01143 01144 01145 /**Query Module Sensor Temperature and humidity(if has a sensor) 01146 * @param: 01147 * temperature[out]: 0~120 01148 * humidity[out]: 0~120 01149 * @return 01150 * 1 success, 01151 * 0 Error, 01152 * Note: This command is use for HMSensor. 01153 * This value is added into scan response data package. 01154 * Data format is 0x02, 0x16, 0x00, 0xB0, [reserved], [temperature], [ humidity], [battery]. 01155 * Android: Included in OnLeScan function result array, you can see it direct. 01156 * iOS: Included in LeScan function result NSDictionary struct, service id is 0xB000. 01157 */ 01158 bool queryModuleSensorTempAndHumidity(uint8_t* temp, uint8_t* hum); 01159 01160 01161 01162 /**Query DS18B20 Sensor temperature 01163 * @param: 01164 * temperature[out]: 0~255 01165 * @return 01166 * 1 success, 01167 * 0 Error, 01168 * Note1: This command is use for HMSensor. 01169 * Note2: Added in V523 version. 01170 */ 01171 bool queryDS18B20SensorTemperature (uint8_t* temp); 01172 01173 01174 01175 /**Set Module connect remote device timeout value 01176 * @param: 01177 * timeout- range: 0~999999; values: 0-Save when connected, 1-Don’t Save; Unit: ms 01178 * Default: 0 01179 * @return 01180 * 1 success, 01181 * 0 Error, 01182 * Note: This value is only used for Central Role, when module has Last Connected address. 01183 */ 01184 bool setModuleConnectRemoteDeviceTimeoutValue(uint32_t timeout); 01185 01186 01187 01188 /**Query connect remote device timeout value 01189 * @return 01190 * timeout- range: 0~999999; values: 0-Save when connected, 1-Don’t Save; Unit: ms 01191 * 0xFFFFFFFF - error 01192 * Note: This value is only used for Central Role, when module has Last Connected address. 01193 */ 01194 uint32_t queryModuleConnectRemoteDeviceTimeoutValue(void); 01195 01196 01197 01198 /**Set Module Bond Mode 01199 * @param: 01200 * BondMode_t bondMode; 01201 * Default: _NOT_NEED_PIN_CODE 01202 * @return 01203 * 1 success, 01204 * 0 Error, 01205 * 01206 * Important: If your module version is less than V515, please don’t use this command. 01207 * Under android 4.3 AT+TYPE1 is same to AT+TYPE2. 01208 * Note1: Value 3 is added in V524. 01209 */ 01210 bool setModuleBondMode(BondMode_t bondMode); 01211 01212 01213 01214 /**Query Module Bond Mode 01215 * @return 01216 * BondMode_t bondMode; 01217 * 0xFFFFFFFF - _INVALID_BOND_MODE 01218 * 01219 * Important: If your module version is less than V515, please don’t use this command. 01220 * Under android 4.3 AT+TYPE1 is same to AT+TYPE2. 01221 * Note1: Value _AUTH_AND_BOND, is added in V524. 01222 */ 01223 BondMode_t queryModuleBondMode(void); 01224 01225 01226 01227 01228 /**Set service UUID 01229 * @param: service UUID - 0x0001~0xFFFE 01230 * Default: 0xFFE0 01231 * @return: 01232 * 1 success, 01233 * 0 Error, 01234 */ 01235 bool setServiceUuid (uint16_t serviceUuid); 01236 01237 01238 /**Query service UUID 01239 * @return 01240 * service UUID - 0x0001~0xFFFE 01241 * Error - 0xFFFF 01242 */ 01243 uint16_t queryServiceUuid(void); 01244 01245 01246 01247 /**Set UART sleep type 01248 * @param: 01249 * sleepType- range:[0~1] 01250 * value: 0-When module into sleep mode, you can wake up module through UART. 01251 * 1-When module into sleep mode, shutdown UART too 01252 * Default: 0 01253 * @return: 01254 * 1 success, 01255 * 0 Error, 01256 */ 01257 bool setUartSleepType (uint8_t sleepType); 01258 01259 01260 /**Query UART sleep type 01261 * @return: 01262 * sleepType- range:[0~1] 01263 * value: 0-When module into sleep mode, you can wake up module through UART. 01264 * 1-When module into sleep mode, shutdown UART too 01265 * Error - 0xFF 01266 */ 01267 uint8_t queryUartSleepType(void); 01268 01269 01270 01271 /**Query Software Version 01272 * @param: 01273 * [in ] version buf len 01274 * [out] version 01275 * @return: 01276 * 1 success, 01277 * 0 Error, 01278 * Note1: This command is use for HMSensor. 01279 * Note2: Added in V523 version. 01280 */ 01281 bool querySoftwareVersion(char* ver,uint8_t bufLen); 01282 01283 01284 //temporary here 01285 bool waitForData(int timeoutMs); 01286 01287 //@returns len of the string 01288 /*inline*/ bool hexToString(uint32_t hex, char*str,uint8_t len); 01289 /*inline */ uint32_t strToHex(char*const str,uint8_t len); 01290 private: 01291 01292 /// bool waitForData(int timeoutMs); 01293 BufferedSerial mSerial; 01294 01295 01296 01297 01298 }; 01299 01300 01301 01302 01303 01304 01305 01306 01307 01308 01309 01310 #endif
Generated on Tue Jul 12 2022 17:25:07 by
1.7.2