Advertisement
ripred

hm-10.cpp

Sep 19th, 2022 (edited)
106
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 31.22 KB | Source Code | 0 0
  1. /*\
  2. |*|
  3. |*| Library of HM-10/11 AT commands
  4. |*|
  5. |*| Original source written 2020 by Trent M. Wyatt
  6. |*|
  7. |*| Based off of the datasheet: https://people.ece.cornell.edu/land/courses/ece4760/PIC32/uart/HM10/DSD%20TECH%20HM-10%20datasheet.pdf
  8. \*/
  9.  
  10. //
  11. // Library of HM-10/11 AT commands
  12. //
  13. //
  14. // Note - I have version 5.51:
  15. //
  16. // >AT+VERS?
  17. // DSD TECH V551
  18. //
  19. // AT-Command support for all HM-10 commands
  20. //
  21. // Original source written 2020 by Trent M. Wyatt
  22. //
  23.  
  24. #include <avr/pgmspace.h>
  25.  
  26. #include <Arduino.h>
  27. #include "hm10.h"
  28.  
  29. const char * const commands[] PROGMEM = {
  30.   "AT",
  31.   "AT+ADC[%X]?",    // %X: 3,4,5,6,7,8,9,A,B map to PIO3~PIOB
  32.   "AT+ADDR?",
  33.   "AT+ADVI?",
  34.   "AT+ADVI[%X]",    // P1: 0 ~ F
  35.                     // 0: 100ms
  36.                     // 1: 152.5 ms
  37.                     // 2: 211.25 ms
  38.                     // 3: 318.75 ms
  39.                     // 4: 417.5 ms
  40.                     // 5: 546.25 ms
  41.                     // 6: 760 ms
  42.                     // 7: 852.5 ms
  43.                     // 8: 1022.5 ms
  44.                     // 9: 1285 ms
  45.                     // A: 2000ms
  46.                     // B: 3000ms
  47.                     // C: 4000ms
  48.                     // D: 5000ms
  49.                     // E: 6000ms
  50.                     // F: 7000ms
  51.                     // Default: 9
  52.                     // HMSoft Default: 0
  53.                     // HMSensor Default: 9
  54.   "AT+ADTY?",
  55.   "AT+ADTY[%X]",    // %X: 0 ~ 3
  56.                     // 0: Advertising, ScanResponse, Connectable
  57.                     // 1: Only allow last device connect in 1.28 seconds
  58.                     // 2: Only allow Advertising and ScanResponse.
  59.                     // 3: Only allow Advertising
  60.                     // Default: 0
  61.   "AT+ANCS?",
  62.   "AT+ANCS[%X]",    // P1: 0 ~ 1
  63.                     // 0: Off
  64.                     // 1: On
  65.                     // Default: 0
  66.                     //
  67.                     // Note1: This command added in V524.
  68.                     // Note2: Please send AT+RESET to restart module if you set value 1.
  69.                     // Note3: Must execute AT+TYPE3 first.
  70.  
  71.  
  72.   "AT+ALLO?",
  73.   "AT+ALLO[%X]",    // P1: 0 ~ 1
  74.                     // 0: Off
  75.                     // 1: On
  76.                     // Default: 0
  77.                     // Note1: This command added in V523.
  78.                     // Note2: White List allows three MAC address link to module. Please use AT+AD
  79.                     // command set white list MAC address.
  80.   "AT+AD[%X]??",    // %X: 1, 2, 3
  81.   "AT+ALLO[%X][%6X]",
  82.                     // %s: MAC address
  83.                     // %X default: 0
  84.   "AT+BEFC?",
  85.   "AT+BEFC[%03X]",  // %X: 000 ~ 3FF
  86.                     // Default: 000
  87.                     // This command added in V527.
  88.                     // 3FF == 001111111111, left to right side is map to PIO0~PIOB, PIO0 and PIO1 are
  89.                     // used by system as pushbutton and system LED. Only Pio2~PIOB pins is available.
  90.                     // e.g. Set PIO2~PIOB all output high after power supplied.
  91.                     // Send: AT+BEFC3FF
  92.                     // Recv:OK+Set:3FF
  93.                     // When next time power on, module PIO2~PIOB will output high.
  94.                     // Note: Query PIO pins current state please use AT+PIO?? Command.
  95.                     // Note: Please don’t use this command when “AT+MODE1” is setup.
  96.   "AT+AFTC?",
  97.   "AT+AFTC[%03X]",  // P1: 000~ 3FF
  98.                     // Default: 000
  99.                     // This command added in V527.
  100.                     // 3FF == 001111111111, Left to right side is map to PIO0~PIOB, PIO0 and PIO1 is
  101.                     // used by system. Only Pio2~PIOB pins is available.
  102.                     // e.g. Set PIO2~PIOB all output high when connection is established.
  103.                     // Send: AT+AFTC3FF
  104.                     // Recv: OK+Set:3FF
  105.                     // When Bluetooth connection is established, module PIO2~PIOB will output high.
  106.                     // Note: Query PIO pins current state please use “AT+PIO??” command.
  107.                     // Note: Please don’t use this command when “AT+MODE1” is setup.
  108.   "AT+BATC?",
  109.   "AT+BATC[%X]",    // P1: 0 ~ 1
  110.                     // 0: Off
  111.                     // 1: On
  112.                     // Default: 0
  113.                     // This command added in V520
  114.   "AT+BATT?",       // Receive OK+BATT:[P1] - P1: 000 ~ 100
  115.                     // There are three ways to get battery information:
  116.                     //   a. Before establishing a connection, Send “AT+BATT?” through UART.
  117.                     //   b. After established a connection, In Mode 1 or 2, remote side send “AT+BATT?”
  118.                     // Battery information has included in scan response data package, one hour update
  119.                     // once. You can use Android or IOS discovery module, when module has been
  120.                     // discovered, you can get it from scan result array.
  121.                     // Data format is 0x02, 0x16, 0x00, 0xB0, [FLAG], [temperature], [ humidity], [battery].
  122.                     //
  123.                     // Android:
  124.                     // Included in OnLeScan function result array, you can see it direct.
  125.                     //
  126.                     // private BluetoothAdapter.LeScanCallback mLeScanCallback = new BluetoothAdapter.LeScanCallback() {
  127.                     //   @Override
  128.                     //   public void onLeScan(final BluetoothDevice device, int rssi, byte[] scanRecord) {
  129.                     //     ......<Other code>......
  130.                     //     String sBatt = ""; //Battery
  131.                     //     String sTemp = ""; //Temperature
  132.                     //     String sHumi = ""; //Humidity
  133.                     //     for (int i = 0; i < scanRecord.length; i++) {
  134.                     //       if (i + 7 < scanRecord.length) {
  135.                     //         // Since V522
  136.                     //         if (scanRecord[i] == 0x07 && scanRecord[i + 1] == 0x16 && scanRecord[I + 2] == 0x00 && scanRecord[I + 3] == 0xB0) {
  137.                     //         if (scanRecord[i] == 0x02 && scanRecord[i + 1] == 0x16 && scanRecord[I + 2] == 0x00 && scanRecord[I + 3] == 0xB0) {
  138.                     //           if (scanRecord[i + 7] > 0)
  139.                     //             sBatt = String.valueOf(scanRecord[i + 7]);
  140.                     //           if (scanRecord[i + 5] > 0)
  141.                     //             sTemp = String.valueOf(scanRecord[i + 5]);
  142.                     //           if (scanRecord[i + 6] > 0)
  143.                     //             sHumi = String.valueOf(scanRecord[i + 6]);
  144.                     //         }
  145.                     //       }
  146.                     //     }
  147.                     //     ......<Other code>......
  148.                     //   }
  149.                     // };
  150.                     //
  151.                     // iOS:
  152.                     // c. Included in LeScan function result NSDictionary struct, service id is 0xB000.
  153.   "AT+BATT[%0x02]", // P1: 0x00 ~ 0xFF
  154.                     // Not include ‘?’
  155.                     // This command is used to set battery information byte in advertising data when you
  156.                     // doesn’t want to use battery function buy want to use as AT+FLAG command.
  157.   "AT+BIT7?",       // P1: bit7 switch.
  158.   "AT+BIT7[%1X]",   // 0 = Not compatible
  159.                     // 1 = Compatible
  160.                     // Default: 0
  161.                     // This command is used only for compatible uses 7 data bits, 2 stop bit device.
  162.   "AT+BAUD?",       // Baud rate #
  163.   "AT+BAUD[%1X]",   //
  164.                     // 0 = 9600
  165.                     // 1 = 19200
  166.                     // 2 = 38400
  167.                     // 3 = 57600
  168.                     // 4 = 115200
  169.                     // 5 = 4800
  170.                     // 6 = 2400
  171.                     // 7 = 1200
  172.                     // 8 = 230400
  173.                     // Default: 0 (9600)
  174.                     //
  175.                     // e.g.
  176.                     // Query baud:
  177.                     //   Send: AT+BAUD?
  178.                     //   Receive: OK+Get:0
  179.                     // Setup baud:
  180.                     //   Send: AT+BAUD1
  181.                     //   Receive: OK+Set:1
  182.                     // Note: If setup to Value 7, After next power on, module will not support any AT
  183.                     //       Commands, until PIO0 is pressed, Module will change Baud to 9600.
  184.   "AT+COMI?",       // Receive: OK+Get:[P1]
  185.                     // P1: 0 ~ 9
  186.                     // Default: 3 (20 ms)
  187.   "AT+COMI[%1X]",   // 0 =    7.5 ms
  188.                     // 1 =   10.0 ms
  189.                     // 2 =   15.0 ms
  190.                     // 3 =   20.0 ms
  191.                     // 4 =   25.0 ms
  192.                     // 5 =   30.0 ms
  193.                     // 6 =   35.0 ms
  194.                     // 7 =   40.0 ms
  195.                     // 8 =   45.0 ms
  196.                     // 9 = 4000.0 ms
  197.                     // Note: This command is added since V538
  198.   "AT+COMA?",       // Receive: OK+Get:[P1]
  199.                     // P1: 0 ~ 9
  200.                     // Default: 7 (40 ms)
  201.   "AT+COMA[%1X]",   //
  202.                     // 0 =    7.5 ms
  203.                     // 1 =   10.0 ms
  204.                     // 2 =   15.0 ms
  205.                     // 3 =   20.0 ms
  206.                     // 4 =   25.0 ms
  207.                     // 5 =   30.0 ms
  208.                     // 6 =   35.0 ms
  209.                     // 7 =   40.0 ms
  210.                     // 8 =   45.0 ms
  211.                     // 9 = 4000.0 ms
  212.                     // Note: This command is added since V538
  213.   "AT+COLA?",       // Receive: OK+Get:[P1]
  214.                     // P1: 0 ~ 4
  215.                     // Default: 0
  216.   "AT+COLA[P1]",    //
  217.                     // Note: This command is added since V538
  218.   "AT+COSU?",       // Receive: OK+Get:[P1]
  219.                     // P1: 0 ~ 6
  220.                     // Default: 6 (6000 ms)
  221.                     // 0 =  100.0 ms
  222.                     // 1 = 1000.0 ms
  223.                     // 2 = 2000.0 ms
  224.                     // 3 = 3000.0 ms
  225.                     // 4 = 4000.0 ms
  226.                     // 5 = 5000.0 ms
  227.                     // 6 = 6000.0 ms
  228.                     // Note: This command is added since V538
  229.   "AT+COUP?",       // Receive: OK+Get:[P1]
  230.                     // P1: 0 ~ 1
  231.                     // 0 = Don’t update
  232.                     // 1 = Update
  233.                     // Default: 1 (update)
  234.                     // This command is only use when module is in slave role.
  235.                     // Note: This command is added since V538
  236.   "AT+CHAR?",       // Receive: OK+Get:[P1]
  237.                     // P1: 0x0001~0xFFFE
  238.   "AT+CHAR[P1]",    // Default: 0xFFE1
  239.                     // e.g. change characteristic value to 0xAAA0
  240.                     // Send: AT+CHAR0xAAA0
  241.                     // Recv: OK+Set:0xAAA0
  242.   "AT+CLEAR",       // Notice: Only Central role is used.
  243.   "AT+CONNL",       // Receive: OK+CONN[P1]
  244.                     // P1: L, E, F, N
  245.                     // L: Connecting
  246.                     // E: Connect error
  247.                     // F: Connect Fail
  248.                     // N: No Address
  249.                     // Notice: Only Central role is used. Must set up AT+IMME1 and AT+ROLE1 first.
  250.                     // If remote device has already connected to other device or shut down,
  251.                     // “OK+CONNF” will received after about 10 seconds.
  252.   "AT+CO[P0][P1]",  // Receive: OK+CO[P0][P0][P2]
  253.                     // P0: N, 0, 1, 2
  254.                     //   N: Normal Address
  255.                     //   0: Static MAC
  256.                     //   1: Static random MAC
  257.                     //   2: Random MAC
  258.                     // P1: Address (like: 0017EA090909)
  259.                     // P2: A, E, F
  260.                     //   A: Connecting
  261.                     //   E: Connect error
  262.                     //   F: Connect Fail
  263.                     //
  264.                     // Notice: Only central role is used. Must set up AT+IMME1 and AT+ROLE1 first.
  265.                     // If remote device has already connected to other device or shut down,
  266.                     // “OK+CONNF” will received after about 10 Seconds.
  267.                     // e.g.
  268.                     // Try to connect an device which MAC address is 00:17:EA:09:09:09
  269.                     // Send: AT+CON0017EA090909
  270.                     // May receive a reply:
  271.                     //  OK+CONNA ========= Accept request, connecting
  272.                     //  OK+CONNE ========= Connect error
  273.                     //  OK+CONN ========= Connected, if AT+NOTI1 is setup
  274.                     //  OK+CONNF ========= Connect Failed, After 10 seconds
  275.                     // Note: O is not zero
  276.   "AT+CONN[P1]",    // Receive: OK+CONN[P2]
  277.                     // P1: 0~5
  278.                     // P2: E, F, 0~5
  279.                     // E: Link error
  280.                     // F: Link failed
  281.                     // 0~5: Try to connect
  282.                     // This command is used after executing: AT+DISC?
  283.                     // When AT+DISC? Command return first device use P1 as 0, then second device
  284.                     // use P1 as 1, third device use P1 as 2.
  285.                     // This command will clear all discovery data.
  286.   "AT+COL??",       // Receive: P1: 0x00~0xFF
  287.                     // P1 is a byte, has 8 bits, bit 7 ~ bit 0 is map to the PIO4 ~ PIO11.
  288.                     // This command is added since V515 version.
  289.   "AT+CYC??",       // Receive: OK+ Get:[P1]
  290.                     // P1: 00 ~ 99
  291.                     // Unit: seconds
  292.                     // Default: 10
  293.   "AT+CYC[P1]",     // Receive: OK+ Set:[P1]
  294.                     // In mode 1, when PIO state is change, module will send OK+Col:[xx] to UART or
  295.                     // remote side. This command is set send interval.
  296.                     // This command is added since V515 version.
  297.   "AT+COMP?",       // Receive: OK+ Get:[P1]
  298.                     // P1: 0, 1, ?
  299.                     // 0: Off
  300.                     // 1: On
  301.                     // ?: Query
  302.                     // Default: 0
  303.   "AT+COMP[P1]",    // Receive: OK+ Set:[P1]
  304.                     // Please reference <How_To_Use_HM-1x_Study_function.pdf>
  305.                     // This command is added since V542 version.
  306.   "AT+DISC?",       // Recieve: OK+DIS[P0][P1]
  307.                     // P0: C, 0, 1, 2
  308.                     //  C: Common string
  309.                     //  0~2: Address type
  310.                     // P1: S, E, [MAC String]
  311.                     // S: Start discovery
  312.                     // E: End discovery
  313.                     // MAC String: Device MAC string
  314.                     // Please set AT+ROLE1 and AT+IMME1 first.
  315.                     // e.g.
  316.                     // Send: AT+DISC?
  317.                     // Recv: OK+DISCS
  318.                     // Recv: OK+DIS[P0]:123456789012 (discovered device address information)
  319.                     // If AT+SHOW1 is setup, you will receive then Name information as follow
  320.                     // Recv: OK+NAME: xxx
  321.                     //  After send Name value, will send two extra “\r\n” value ASCII byte
  322.                     // If AT+SHOW2 is setup, you will receive then RSSI information as follow
  323.                     // Recv: OK+RSSI: xxx\r\n
  324.                     // If AT+SHOW3 is setup, you will receive then RSSI information and Name information
  325.                     // Recv: OK+DIS[P0]:234567890123
  326.                     // Recv: OK+NAME: xxx
  327.                     //  After send Name value, will send two extra “\r\n” value ASCII byte
  328.                     // …..(Before V535 max results is 6, Since V535 not limit)
  329.                     // Recv: OK+DISCE
  330.                     // Connect use array index:
  331.                     // Connect to a discovered device: AT+CONN0, AT+CONN1……AT+CONN5
  332.                     // Connect use MAC string: AT+CON[MAC String]
  333.   "AT+DISI?",       // Receive: OK+DISC[P0:P1:P2:P3:P4]
  334.                     // P0: Factory ID
  335.                     // P1: iBeacon UUID
  336.                     // P2: Major Value
  337.                     // Minor Value
  338.                     // Measured Power
  339.                     // P3: MAC
  340.                     // P4: RSSI
  341.                     //
  342.                     // Please set AT+ROLE1 and AT+IMME1 first.
  343.                     // e.g.
  344.                     // Send: AT+DISI?
  345.                     // Recv: OK+DISCS (Scan start)
  346.                     // Recv: OK+DIS[P0:P1:P2:P3:P4] (if have one device)
  347.                     // Recv: OK+DIS[P0:P1:P2:P3] (if have two devices)
  348.                     // ........
  349.                     // Recv: OK+DISCE (Scan end)
  350.                     // P0 length is 8; P1 length is 32; P2 length is 10; P3 length is 12, P4 length is 4
  351.                     // P2 include Major Value (length 4);
  352.                     // Minor Value (length 4);
  353.                     // Measured Power (length 2)
  354.                     // If the device not enable iBeacon function, P0, P1, P2 will use ‘0’ fill.
  355.                     // Note: Added since V539
  356.   "AT+DISA?",       // Recieve:
  357.                     //    OK+DISAS -> Start scan
  358.                     //    OK+DISC[P0:P1:P2:P3:P4]
  359.                     //    OK+DISAE -> Scan finished
  360.                     //
  361.                     // P0: Device MAC (6Byte)
  362.                     // P1: Device Type(1Byte)
  363.                     // P2: Device RSSI(1Byte)
  364.                     // P3: Rest Data Length
  365.                     //  (1Byte)
  366.                     // P4: Rest Data
  367.                     //
  368.                     // Please set AT+IMME1 and AT+ROLE1 first.
  369.                     // Note: All data is in Hex format.
  370.                     // Added in V547
  371.   "AT+DELO[P1]",    // Receive: OK+DELO[P1]
  372.                     // P1: 1, 2
  373.                     //   1: Allowed to broadcast and scanning
  374.                     //   2: Only allow broadcast
  375.                     //
  376.                     // After receive OK+DELO[P1], module will reset after 500ms.
  377.                     // This command will let module into non-connectable status until next power on.
  378.   "AT+ERASE",       // Recieve: OK+ERASE
  379.                     // Note: Added in V524 version.
  380.   "AT+FFE2[P1]",    // Receive: OK+ Set:[P1]
  381.                     // P1: ?, 0, 1, 2
  382.                     //  ?: Query
  383.                     //  0: Only use one Characteristic
  384.                     //  2: Use two Characteristic
  385.                     //     Second Char value = first Char value + 1
  386.                     //  3: Use two Characteristic
  387.                     //     Second Char value = first Char value - 1
  388.                     // Note: This command added since V550.
  389.   "AT+FLAG[P1]",    // Receive: OK+ Set:[P1]
  390.                     // P1: 0~FF (one byte)
  391.                     // Note: This command added in V530. Please ref to AT+BATT? Command.
  392.   "AT+FIOW?",       // Receive: OK+ Get:[P1]
  393.                     // P1: 0, 1
  394.                     //  0: Off
  395.                     //  1: On
  396.                     //  Default: 0
  397.   "AT+FIOW[P1]",    // Receive: OK+ Set:[P1]
  398.   "AT+GAIN?",       // Receive: OK+ Get:[P1]
  399.                     // P1: 0, 1
  400.                     //  0: No RX gain
  401.                     //  1: Open RX gain
  402.                     //  Default: 0
  403.   "AT+GAIN[P1]",    // Receive: OK+ Set:[P1]
  404.                     // Note: This command is added since V535
  405.   "AT+HELP?",       // Receive: Help Information
  406.   "AT+HUMI[P1]",    // Receive: OK+Set:[P1]
  407.                     // P1: 0x00~0xFF
  408.                     // This command is used to set humi information byte in advertising data when you
  409.                     // doesn’t want to use humi function but want to use as AT+FLAG command.
  410.                     // Note: Added in V544
  411.   "iAT+IMME?",      // Receive: OK+ Get:[P1]
  412.                     // P1: 0, 1
  413.                     //  1: When module is powered on,
  414.                     //     only respond the AT Command,
  415.                     //     don’t do anything. Until AT +
  416.                     //     START, AT+CON, AT+CONNL
  417.                     //     commands is received.
  418.                     //  0: When power on, module will
  419.                     //     start work immediately
  420.                     // Default: 0
  421.   "AT+IMME[P1]",    // Receive: OK+ Set:[P1]
  422.                     // This command is only used for Central role.
  423.   "AT+IBEA?",       // Receive: OK+Get:[P1]
  424.                     // P1: 0, 1
  425.                     //  0: Turn off iBeacon
  426.                     //  1: Turn on iBeacon
  427.                     //  Default: 0
  428.   "AT+IBEA[P1]",    // Receive: OK+Set:[P1]
  429.                     // iBeacon UUID is: 74278BDA-B644-4520-8F0C-720EAF059935.
  430.                     // This command is added since V517 version.
  431.   "AT+IBE0?",       // Receive: OK+Get:[P1]
  432.                     // P1: 00000001~FFFFFFFE
  433.                     // Default: 74278BDA
  434.                     //
  435.   "AT+IBE0[P1]",    // Receive: OK+Set:[P1]
  436.                     // iBeacon UUID is: 74278BDA-B644-4520-8F0C-720EAF059935.
  437.                     //                  ^^^^^^^^ (colored in red in response)
  438.                     // This command can change red color string in iBeacon UUID.
  439.                     // This command is added since V520 version.
  440.                     // e.g.: Send: AT+IBE012345678 change iBeacon UUID red color string to
  441.                     // “12345678”
  442.   "AT+IBE1?",       // Receive: OK+Get:[P1]
  443.                     // P1: 00000001~FFFFFFFE
  444.                     // Default: B6444520
  445.   "AT+IBE1[P1]",    // Receive: OK+Set:[P1]
  446.                     //
  447.                     // iBeacon UUID is: 74278BDA-B644-4520-8F0C-720EAF059935.
  448.                     //                           ^^^^ ^^^^ (colored in red in response)
  449.                     // This command can change red color string in iBeacon UUID.
  450.                     // This command is added since V520 version.
  451.                     // e.g.: Send: AT+IBE112345678 change iBeacon UUID red color string to
  452.                     // “12345678”
  453.   "AT+IBE2?",       // Receive: OK+Get:[P1]
  454.                     // P1: 00000001~FFFFFFFE
  455.                     // Default: 8F0C720E
  456.   "AT+IBE2[P1]",    // Receive: OK+Set:[P1]
  457.                     //
  458.                     // iBeacon UUID is: 74278BDA-B644-4520-8F0C-720EAF059935.
  459.                     //                                     ^^^^ ^^^^ (colored in red in response)
  460.                     // This command can change red color string in iBeacon UUID.
  461.                     // This command is added since V520 version.
  462.                     // e.g.: Send: AT+IBE112345678 change iBeacon UUID red color string to
  463.                     // “12345678”
  464.   "AT+IBE3?",       // Receive: OK+Get:[P1]
  465.                     // P1: 00000001~FFFFFFFE
  466.                     // Default: AF059935
  467.   "AT+IBE3[P1]",    // Receive: OK+Set:[P1]
  468.                     // iBeacon UUID is: 74278BDA-B644-4520-8F0C-720EAF059935.
  469.                     //                                              ^^^^^^^^ (colored in red in response)
  470.                     // This command can change red color string in iBeacon UUID.
  471.                     // This command is added since V520 version.
  472.                     // e.g.: Send: AT+IBE112345678 change iBeacon UUID red color string to
  473.                     // “12345678”
  474.   "AT+MARJ?",       // Receive: OK+Get:[P1]
  475.                     // P1: 0x0001, 0xFFFE
  476.                     // Default: 0xFFE0
  477.                     //
  478.   "AT+MARJ[P1]",    // Receive: OK+Set:[P1]
  479.                     //
  480.                     // e.g. Change marjor version to 0x0102
  481.                     // Send: AT+MARJ0x0102, if all is okay, module will send back OK+Set: 0x0102
  482.                     // This command is added since V517 version.
  483.   "AT+MINO?",       // Receive: OK+Get:[P1]
  484.                     // P1: 0x0001, 0xFFFE
  485.                     // Default: 0xFFE1
  486.   "AT+MINO[P1]",    // Receive: OK+Set:[P1]
  487.                     // This command is added since V517 version.
  488.   "AT+MEAS?",       // Receive: OK+Get:[P1]
  489.                     // P1: 0x01~ 0xFF
  490.                     // Default: 0xC5
  491.   "AT+MEAS[P1]",    // OK+Set:[P1]
  492.                     // This command is added since V519 version.
  493.   "AT+MODE?",       // Receive: OK+Get:[P1]
  494.                     // P1: 0, 1, 2
  495.                     //  0: Transmission Mode
  496.                     //  1: PIO collection Mode + Mode 0
  497.                     //  2: Remote Control Mode + Mode 0
  498.                     // Default: 0
  499.   "AT+MODE[P1]",    // Receive: OK+Set:[P1]
  500.                     //
  501.                     // Mode 0:
  502.                     //      Before establishing a connection, you can use the AT command configuration
  503.                     //      module through UART.
  504.                     //      After established a connection, you can send data to remote side from each
  505.                     //      other.
  506.                     // Mode 1:
  507.                     //      Before establishing a connection, you can use the AT command configuration
  508.                     //      module through UART.
  509.                     //      After established a connection, you can send data to remote side. Remote side
  510.                     //      can do fellows:
  511.                     //      Send AT command configuration module.
  512.                     //      Collect PIO04 to the PIO11 pins input state of HM-10.
  513.                     //      Collect PIO03 pins input state of HM-11.
  514.                     //      Remote control PIO2, PIO3 pins output state of HM-10.
  515.                     //      Remote control PIO2 pin output state of HM-11.
  516.                     //      Send data to module UART port (not include any AT command and per package
  517.                     //      must less than 20 bytes).
  518.                     // Mode 2:
  519.                     //      Before establishing a connection, you can use the AT command configuration
  520.                     //      module through UART.
  521.                     //      After established a connection, you can send data to remote side. Remote side
  522.                     //      can do fellows:
  523.                     //      Send AT command configuration module.
  524.                     //      Remote control PIO2 to PIO11 pins output state of HM-10.
  525.                     //      Remote control PIO2, PIO3 pins output state of HM-11.
  526.                     //      Send data to module UART port (not include any AT command and per package
  527.                     //      must less than 20 bytes).
  528.   "AT+NOTI?",       // Receive: OK+Get:[P1]
  529.                     // P1: 0, 1
  530.                     //  0: Don’t Notify
  531.                     //  1: Notify
  532.                     //  Default: 0
  533.   "AT+NOTI[P1]",    // Receive: OK+Set:[P1]
  534.                     //
  535.                     // If this value is set to 1, when link ESTABLISHED or LOSTED module will send
  536.                     // OK+CONN or OK+LOST string through UART.
  537.   "AT+NOTP?",       // Receive: OK+ Get[P1]
  538.                     // P1: 0, 1; default: 0
  539.                     //  0: without address
  540.                     //  1: with address
  541.   "AT+NOTP[P1]",    // Receive: OK+ Set[P1]
  542.                     //
  543.                     // This command must work with “AT+NOTI1”, if this switch is open, when the
  544.                     // module connect to disconnect, the prompt string will include the remote address.
  545.                     // OK+CONN:001122334455 String “001122334455” is the MAC address string
  546.                     // Added since V534.
  547.   "AT+NAME",        // Receive: OK+NAME[P1]
  548.                     // P1: module name, Max length is 12.
  549.                     // Default: HMSoft
  550.   "AT+NAME[P1]",    // Receive: OK+SetName[P1]
  551.                     //
  552.                     // e.g.
  553.                     // change module name to bill_gates
  554.                     // Send: AT+NAMEbill_gates
  555.                     // Receive: OK+SetName:bill_gates
  556.   "AT+PCTL?",       // Receive: OK+Get:[P1]
  557.                     // P1: 0,1
  558.                     //  0:Normal power output
  559.                     //  1:Max power output
  560.                     //  Default: 1
  561.   "AT+PCTL[P1]",    // Receive: OK+Set:[P1]
  562.                     // Noted: Added in V527
  563.   "AT+PARI?",       // Receive: OK+Get:[P1]
  564.                     // P1: 0,1,2
  565.                     //  0:None
  566.                     //  1:EVEN
  567.                     //  2:ODD
  568.                     //  Default: 0 (None)
  569.   "AT+PARI[P1]",    // Receive: OK+Set:[P1]
  570.   "AT+PIO1?",       // Receive: OK+Get:[P1]
  571.                     // P1: 0, 1
  572.                     //  0: Unconnected Output
  573.                     //     500ms High 500ms Low,
  574.                     //     Connected output High.
  575.                     //  1: Unconnected output Low,
  576.                     //     Connected output High.
  577.                     // Default: 0
  578.   "AT+PIO1[P1]",    // Receive: OK+Set:[P1]
  579.   "AT+PIO[P1]?",    // Receive: OK+PIO:[P1][P2]
  580.                     // P1: 2~B, ?
  581.                     // P2: 0, 1, ?
  582.                     // HM-11 only has 4 pins.
  583.                     // P1 is which PIO pin you want to Query/Set
  584.                     // Value: 2,3,4,5,6,7,8,9,A,B.
  585.                     // P2 is Query or setup value.
  586.                     // “0” is low and “1” is high and
  587.                     // “?” is query
  588.   "AT+PIO[P1][P2]", // Receive: OK+PIO:[P1][P2]
  589.                     //
  590.                     // e.g.
  591.                     // Query PIO2
  592.                     // Send: AT+PIO2?
  593.                     // Setup PIO2 output high
  594.                     // Send: AT+PIO21
  595.                     // Receive: OK+PIO21
  596.                     // HM-10 HMSensor version: P1 value is 2~A
  597.                     // HM-10 HMSoft version: P1 value is 2~B
  598.                     // HM-11 HMSensor version: P1 value is 2
  599.                     // HM-11 HMSoft version: P1 value is 2, 3
  600.                     // V525 added PIO2 PWM function, P2 value is 0~9
  601.                     // 0: output low
  602.                     // 1: output high
  603.                     // 2: output 100ms PWM
  604.                     // 3: output 200ms PWM
  605.                     // ....
  606.                     // 9: output 800ms PWM
  607.                     //  V527 added AT+PIO?? Format query all pins output state.
  608.   "AT+PASS?",       // Receive: OK+Get:[P1]
  609.                     // P1 is Pin Code,
  610.                     // 000000~999999
  611.                     // Default: 000000
  612.   "AT+PIN[P1]",     // Receive: OK+Set:[P1]
  613.                     //
  614.                     // e.g.
  615.                     // Query Pin Code
  616.                     // Send: AT+PIN?
  617.                     // Receive: OK+PIN:000000
  618.                     // Setup Pin Code 008888
  619.                     // Send: AT+PIN008888
  620.                     // Receive: OK+Set:008888
  621.   "AT+POWE?",       // Receive: OK+Get:[P1]
  622.                     // P1: 0 ~ 3
  623.                     //  0: -23dbm
  624.                     //  1: -6dbm
  625.                     //  2: 0dbm
  626.                     //  3: 6dbm
  627.                     // Default: 2
  628.   "AT+POWE[P1]",    // OK+Set:[P1]
  629.   "AT+PWRM?",       // Receive: OK+Get:[P1]
  630.                     // P1: 0~1
  631.                     //  0:Auto sleep
  632.                     //  1:don’t auto sleep
  633.                     // Default: 1
  634.   "AT+PWRM[P1]",    // Receive: OK+Set:[P1]
  635.                     // Only support peripheral role.
  636.   "AT+RELI?",       // Receive: OK+Get:[P1]
  637.                     // P1: 0, 1
  638.                     //  0: Normal advertising
  639.                     //  1: Reliable advertising
  640.                     // Default: 0
  641.   "AT+RELI[P1]",    // receive: OK+Set:[P1]
  642.                     // Note: This command is added since V530
  643.   "AT+RENEW",       // Receive: AT+RENEW
  644.   "AT+RESET",       // Receive: OK+RESET
  645. };
  646.  
Advertisement
Comments
  • ripred
    1 year (edited)
    # text 0.13 KB | 0 0
    1. Based off of the datasheet: https://people.ece.cornell.edu/land/courses/ece4760/PIC32/uart/HM10/DSD%20TECH%20HM-10%20datasheet.pdf
    2.  
Add Comment
Please, Sign In to add comment
Advertisement