This article uses the following environment:
Main control: W801 (development board)
Compatible with: W800 AIR101
Software: CDK
W801 Bluetooth data transmission and reception and control design (I) - INDICATE
W801 Bluetooth data transmission and reception and control design (Part 2) - NOTIFY method
W800-KIT-Bluetooth-Temperature and humidity sensor (cht8305c)-RGB light-demo
1. Project Overview
^^^^This tutorial continues the previous one to introduce the use of W801's BT. The previous one uses the INDICATE method to send and receive data, and this article mainly uses the NOTIFY method to send and receive data. You can check the specific difference between Indicate and Notify yourself. I don't know much about this thing. It seems that (indicate sends and receives a response from the receiving end, and notify does not receive a response from the receiving end).
^^^^Program function: Similar to the above, the difference is that Indicate and Notify are different.
2. Programming
Preface: The program in this article is an improvement on the previous one, so you must download the program in the previous article.
The following codes are all added in wm_ble_server_api_demo.c.
1. Add macro definitions first. There are two main places for notify, as follows:
/* ble attr write/notify handle */
uint16_t g_ble_demo_attr_indicate_handle;
uint16_t g_ble_demo_attr_write_handle;
uint16_t g_ble_demo_conn_handle;
//add by zxx start
uint16_t g_ble_demo_attr_notify_handle;
//add by zxx end
#define WM_GATT_SVC_UUID 0xFFF0
#define WM_GATT_INDICATE_UUID 0xFFF1
#define WM_GATT_WRITE_UUID 0xFFF2
//add by zxx start
#define WM_GATT_NOTIFY_UUID 0xFFF3
//add by zxx end
2. The official demo only has WRITE and INDICATE, so add code characteristics:
//The notify_test function has no effect. If the Bluetooth notify method is not added, initialization will fail.
static int notify_test()
{
;
}
static const struct ble_gatt_svc_def gatt_demo_svr_svcs[] = {
{
/* Service: uart */
.type = BLE_GATT_SVC_TYPE_PRIMARY,
.uuid = BLE_UUID16_DECLARE(WM_GATT_SVC_UUID),
.characteristics = (struct ble_gatt_chr_def[]) {
.uuid = BLE_UUID16_DECLARE(WM_GATT_WRITE_UUID),
.val_handle = &g_ble_demo_attr_write_handle,
.access_cb = gatt_svr_chr_demo_access_func,
.flags = BLE_GATT_CHR_F_WRITE,
},{
.uuid = BLE_UUID16_DECLARE(WM_GATT_INDICATE_UUID),
.val_handle = &g_ble_demo_attr_indicate_handle,
.access_cb = gatt_svr_chr_demo_access_func,
.flags = BLE_GATT_CHR_F_INDICATE,
}
//add by zxx start
,{
.uuid = BLE_UUID16_DECLARE(WM_GATT_NOTIFY_UUID),
.val_handle = &g_ble_demo_attr_notify_handle,
//This function will not be called, but it must be there,
.access_cb = notify_test,
.flags = BLE_GATT_CHR_F_NOTIFY,
}
//add by zxx end
,{
0, /* No more characteristics in this service */
}
},
},
{
0, /* No more services */
},
};
3. Add the tls_ble_server_demo_api_send_notify_msg function. Just modify it according to the tls_ble_server_demo_api_send_msg function.
//add by zxx start
int tls_ble_server_demo_api_send_notify_msg(uint8_t *data, int data_len)
{
int rc;
struct os_mbuf *om;
//TLS_BT_APPL_TRACE_DEBUG("### %s len=%drn", __FUNCTION__, data_len);
//This sentence should be commented out, otherwise the logic of this code is wrong
//if(g_send_pending) return BLE_HS_EBUSY;
if(data_len<=0 || data == NULL)
{
return BLE_HS_EINVAL;
}
om = ble_hs_mbuf_from_flat(data, data_len);
if (!om) {
return BLE_HS_ENOMEM;
}
//The parameter g_ble_demo_attr_notify_handle handle should be the same as the handle of characteristics
rc = ble_gattc_notify_custom(g_ble_demo_conn_handle,g_ble_demo_attr_notify_handle, om);
//You can comment or not comment this sentence, I commented it
/*
if(rc == 0)
{
g_send_pending = 1;
}
*/
return rc;
}
//add by zxx end
2. Testing
1. App configuration
Configure as shown in the figure, note that TX is xxxf3 and RX is xxxf2. After the configuration is completed, the normal sending and receiving program can be performed.
The other test steps are the same as above and will not be repeated here.
Previous article:W801/W800 Bluetooth data transmission and control design (Part 3) - Actual project: Bluetooth transmission of temperature and humidity data
Next article:W801/W800 Bluetooth data transmission and reception and control design (I) - INDICATE
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- 【Zero Knowledge ESP8266】Tutorial: MESH Network Example
- In the timer mode selection, 0: 32-bit free count 1: 16-bit reload count What is the difference between these two modes?
- Shanghai Semiconductor IC Company Epidemic Welfare Package PK, Too Lucky!
- Configuration Case Sharing--Modbus to Profinet Gateway Connecting ACS510 Inverter
- Modification of 4-20mA two-wire passive digital display meter Part 6 (general schematic diagram)
- Radio Frequency Learning Knowledge Consulting Network and Information Query Network (Collation)
- Pixel Pump, an open source vacuum pump using micropython
- Questions about PCF8583
- Answers to questions about programming the Lingdongwei MM32 MCU
- 16-bit MSP430G series microprocessor usage expansion