5606 views|6 replies

1237

Posts

66

Resources
The OP
 

[Silicon Labs BG22-EK4108A Bluetooth Development Review] VII. WeChat applet controls LED and receives button status 2 [Copy link]

 

In the previous post, I learned about the Bluetooth LED control and button status feedback routines of Silicon Labs BG22-EK4108A. The most important ones are the following services and characteristic values:

Writing a WeChat applet to control the LED on and off and obtain the button status is to write operations on these two characteristic values and subscribe to notifications. After receiving the notification data, it needs to be processed and displayed, which is achieved by exchanging data between two pages:

      wx.onBLECharacteristicValueChange(function(res){
          console.log(res);
          var tmp =that.ab2hex(res.value);
          var cdn = that.data.currDeviceName;
          that.printLog("当前蓝牙设备名字: " + cdn + "," + "收到Notify数据: " + that.ab2hex(res.value));
          //发送数据到其它页面
          if(cdn=='Blinky Example')
          {
            event.emit('environmetDataChanged',tmp);
          }
        });

Page showing notification data:

//屏幕打开时执行的函数
  onLoad: function () {
    //接收别的页面传过来的数据
    event.on('environmetDataChanged', this, function(data) {
      //另外一个页面传过来的data是16进制字符串形式
      console.log("接收到蓝牙设备发来的数据:"+data)
      var a=parseInt(data[0]+data[1],16);
      //实时修改显示值
      var up0 = "charts[" + 0 + "].data";
      this.setData({
        [up0]:a,
      });
    })
  },

When receiving LED control data '0' or '1', the LED is turned on and off:

During the service discovery process, the WeChat applet debug log shows that the discovered services are consistent with those defined in SSV5:

The logs of the process of writing characteristic values and receiving key status notifications are as follows:

WeChat applet log. After successfully connecting to the device, it will scan the device for services and then start receiving data with notification permissions:

Demo interface:

LED control:

Key status notification subscription:

Once you have mastered how to read and write characteristic values and subscribe to notification data, you can expand many interesting applications. For example, the development board collects sensor data through ADC and sends it to the WeChat applet in the form of notification. The demonstration effect is:


Latest reply

That’s amazing, you know both the front and back ends. You’re so talented, can I become your disciple?  Details Published on 2022-2-8 11:23
 
 

6555

Posts

0

Resources
2
 

Bluetooth LED control and button status feedback tests are pretty good

 
 
 

1412

Posts

3

Resources
3
 
It looks very high-end when controlled by a small program.

Comments

Mainly convenient for cross-platform  Details Published on 2022-1-25 18:09
 
 
 

1237

Posts

66

Resources
4
 
annysky2012 posted on 2022-1-25 16:54 Using a small program to control it looks very high-end.

Mainly convenient for cross-platform

Comments

Yes, mini programs are different.  Details Published on 2022-1-27 08:33
 
 
 

1412

Posts

3

Resources
5
 
dql2016 posted on 2022-1-25 18:09 Mainly convenient for cross-platform

Yes, mini programs are different.

Personal signature

没有什么不可以,我就是我,不一样的烟火! 

 
 
 

6818

Posts

11

Resources
6
 
That’s amazing, you know both the front and back ends. You’re so talented, can I become your disciple?
 
 
 

1237

Posts

66

Resources
7
 
lugl4313820 posted on 2022-2-8 11:23 That's amazing. You know both the front-end and back-end. You are a genius. Can I become your disciple?

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list