In this demo, we will show you how to develop a smart pill dispenser for medicine reminders. Based on the Tuya IoT Development Platform, we use Tuya's Bluetooth Low Energy (LE) module, SDK, and the Smart Life app to connect this thing to the cloud.
You will implement the following features:
- Program schedules
- Alarm reminders
- Dispenser tracking
- Low battery warning
- Dosage activity monitoring
-
Install the integrated development environment (IDE) as per your chip platform.
-
Find the download URL of the Tuya Bluetooth LE SDK Demo Project from the following table. Refer to the
README.md
file under each branch to import the project.Chip platform Model Download URL Nordic nrf52832 tuya_ble_sdk_Demo_Project_nrf52832.git Realtek RTL8762C tuya_ble_sdk_Demo_Project_rtl8762c.git Telink TLSR825x tuya_ble_sdk_Demo_Project_tlsr8253.git Silicon Labs BG21 Coming soon. Beken BK3431Q tuya_ble_sdk_demo_project_bk3431q.git Beken BK3432 tuya_ble_sdk_Demo_Project_bk3432.git Cypress Psoc63 tuya_ble_sdk_Demo_Project_PSoC63.git
-
Edit code
-
In
tuya_ble_sdk_demo.h
, specify the PID of the product you created on the Tuya IoT Development Platform.#define TY_DEVICE_PID "xxxxxxxx"
Change
xxxxxxxx
to the PID. -
In
tuya_ble_app_demo.c
, specify theauthkey
andUUID
.#define TY_DEVICE_DID "zzzzzzzz" //16Bytes #define TY_DEVICE_AUTH_KEY "yyyyyyyy" //32Bytes
Change
yyyyyyyy
to your authkey andzzzzzzzz
to your UUID.
-
-
Compile code
Compile the edited code, download the code to the hardware, and run it. You may need to download the stack and bootloader depending on your chip models. Check the logs and use the third-party Bluetooth debugging app (such as LightBlue for iOS) to verify the Bluetooth broadcast.
Application/
├── include
│ ├── tuya_battery_monitor.h
│ ├── tuya_beep.h
│ ├── tuya_dp_process.h
│ ├── tuya_local_time.h
│ └── tuya_remind.h
└── src
├── tuya_battery_monitor.c
├── tuya_beep.c
├── tuya_dp_process.c
├── tuya_local_time.c
└── tuya_remind.c
Entry file: /tuya_ble_app/tuya_ble_app_main.c
.
void tuya_ble_sdk_demo_init(void)
is run to initialize the SDK. This function is run only once.
Function | tuya_ble_dp_data_send |
---|---|
Function prototype | tuya_ble_status_t tuya_ble_dp_data_send( uint32_t sn, tuya_ble_dp_data_send_type_t type, tuya_ble_dp_data_send_mode_t mode, tuya_ble_dp_data_send_ack_t ack, uint8_t *p_dp_data, uint32_t dp_data_len ) ; |
Feature overview | Send data point (DP) data to the cloud |
Parameters | sn[in] : the serial number. type[in] : the type of data sending, which can be a proactive notification or a follow-up response. mode[in] : the delivery mode. ack[in] : whether an ACK message is required. p_dp_data [in] : the DP data. dp_data_len[in] : the length of data, no more than TUYA_BLE_SEND_MAX_DATA_LEN-7 . TUYA_BLE_SEND_MAX_DATA_LEN is configurable. |
Return value | TUYA_BLE_SUCCESS : succeeded. TUYA_BLE_ERR_INVALID_PARAM : invalid parameter. TUYA_BLE_ERR_INVALID_STATE : failed to send data due to the current Bluetooth connection, such as Bluetooth disconnected. TUYA_BLE_ERR_NO_MEM : failed to request memory allocation. TUYA_BLE_ERR_INVALID_LENGTH : data length error. TUYA_BLE_ERR_NO_EVENT : other errors. |
Notes | The application calls this function to send DP data to the mobile app. |
Parameter description:
The Tuya IoT Development Platform manages data through DPs. The data generated by any device is abstracted into a DP. DP data consists of four parts, as described below.
-
Dp_id
: the DP ID of a data point defined on the Tuya IoT Development Platform. It is one byte. -
Dp_type
: the data type. It is one byte.#define DT_RAW 0 // Raw type. #define DT_BOOL 1 // Boolean type. #define DT_VALUE 2 // Value type. The value range is specified when a DP of value type is created on the Tuya IoT Development Platform. #define DT_STRING 3 // String type. #define DT_ENUM 4 // Enum type. #define DT_BITMAP 5 // Bitmap type.
-
Dp_len
: It can be one byte or two bytes. -
Dp_data
: the DP data, withdp_len
byte(s).
The data that the parameter p_data
points to must be packaged in the following format for reporting.
DP 1 data | — | DP n data | |||||||
---|---|---|---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 and greater | — | n | n+1 | n+2 | n+3 and greater |
Dp_id | Dp_type | Dp_len | Dp_len | Dp_data | — | Dp_id | Dp_type | Dp_len | Dp_data |
When this function is called, the maximum data length is TUYA_BLE_REPORT_MAX_DP_DATA_LEN
, which is 255+3
currently.
You can get support from Tuya with the following methods: