求一个蓝牙接收的简单程序

2019-07-17 20:52发布

不会写啊!跪求一个接收蓝牙数据的简单的程序!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
5条回答
24不可说
2019-07-18 01:07
小钢炮的一段程序
  1. #include "app.h"
  2. #include "juma_sensor.h"
  3. /*start adv*/

  4. const char *name = "BlueNRG_IOT_2";
  5. uint8_t adv_address[6] = {0x08, 0x05, 0x04, 0x03, 0x02, 0x02};

  6. static float humidity;
  7. static float temperature;

  8. static void sensor_read(void* arg);

  9. void on_ready(void)
  10. {
  11.     uint8_t tx_power_level = 7;
  12.     uint16_t adv_interval = 100;
  13.     jsensor_app_set_sensor(JSENSOR_TYPE_HUMITY_TEMP);
  14.     /*Config Adv Parameter And Ready to Adv*/
  15.     ble_set_adv_param(name, adv_address, tx_power_level, adv_interval);
  16.     ble_device_start_advertising();
  17.     sensor_read(NULL);
  18. }

  19. static void sensor_read(void* arg)
  20. {
  21.     {
  22.         int16_t humidity;
  23.         int16_t temperature;
  24.         JSensor_HUM_TEMP_Typedef tdef;

  25.         tdef.humidity = &humidity;
  26.         tdef.temperature = &temperature;

  27.         if (JSENSOR_OK == jsensor_app_read_sensor(JSENSOR_TYPE_HUMITY_TEMP, (void *)&tdef)) {
  28.             ble_device_send(0x00, 2, (uint8_t *)&temperature);
  29.             ble_device_send(0x01, 2, (uint8_t *)&humidity);
  30.         }
  31.     }
  32. }


  33. /* Device On Message */
  34. void ble_device_on_message(uint8_t type, uint16_t length, uint8_t* value)
  35. {

  36.     if(type == 0x00) {
  37.         if(*value == 0x00) {
  38.             BSP_LED_Off(LED0);
  39.         }
  40.         if(*value == 0x01) {
  41.             BSP_LED_On(LED0);

  42.         }
  43.     }

  44. }
  45. /* Device on connect */
  46. void ble_device_on_connect(void)
  47. {

  48.     tBleStatus ret = BLE_WAIT_REMOTE_ENABLE_NOTIFY;

  49. }
  50. /* Device on disconnect */
  51. void ble_device_on_disconnect(uint8_t reason)
  52. {
  53.     /* Make the device connectable again. */
  54.     Ble_conn_state = BLE_CONNECTABLE;
  55. }
复制代码

一周热门 更多>