Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more details for CC2650 demo #49

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion bluetooth-CC2650-demo/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,15 @@ This section contains instructions on how to make use of bluetooth mapper of Kub
git clone https://github.com/kubeedge/examples.git $GOPATH/src/github.com/kubeedge/examples
```

3. Create the CC2650 SensorTag device model and device instance.
3. Create the CC2650 SensorTag device model and device instance. Please change the device model name "CC2650-sensortag" to the name your node get. You can use `hcitool lescan` to get the name.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. Some little questions, why do we need change the device-model name? and what's the hcitool?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. Some little questions, why do we need change the device-model name? and what's the hcitool?

The hcitool is a bluetooth tool on Linux, hcitool lescan can get the low energy bluetooth devices around the node and their name. It might has a length limit on some Linux version, on my node, the name is cut to "CC2650 Sen". The bluetooth mapper identify a device by this name.

Copy link
Author

@majoyz majoyz Jun 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code to get the name is here:

func (b *BLEConfig) Load() error {
	readConfigFile := ReadConfigFile{}
	readConfigMap := DeviceProfile{}
	err := readConfigFile.ReadFromConfigFile()
	if err != nil {
		return errors.New("Error while reading from configuration file " + err.Error())
	}
	err = readConfigMap.ReadFromConfigMap()
	if err != nil {
		return errors.New("Error while reading from config map " + err.Error())
	}
	b.Mqtt = readConfigFile.Mqtt
	b.Scheduler = readConfigFile.Scheduler
	b.Watcher = readConfigFile.Watcher
	// Assign device information obtained from config file
	for _, device := range readConfigMap.DeviceInstances {
		if strings.EqualFold(device.Model, readConfigFile.DeviceModelName) {
			b.Device.ID = device.ID
			b.Device.Name = device.Model
		}
	}

The device's name is from the device model name in the configmap.
The code to compare name is here:

func onPeripheralDiscovered(p gatt.Peripheral, a *gatt.Advertisement, rssi int) {
	if strings.EqualFold(a.LocalName, strings.Replace(deviceName, "-", " ", -1)) {
		klog.Infof("Device: %s found !!!! Stop Scanning for devices", deviceName)
		// Stop scanning once we've got the peripheral we're looking for.
		p.Device().StopScanning()
		klog.Infof("Connecting to %s", deviceName)
		p.Device().Connect(p)
	}
}

The a.LocalName is the name scaned.


```console
hcitool lescan
LE Scan ...
58:20:59:31:8E:BB CC2650 Sen

Note: In this case, you need to change the device model name to "CC2650-Sen" in config and yaml files.

cd $GOPATH/src/github.com/kubeedge/examples/bluetooth-CC2650-demo/sample-crds
kubectl apply -f CC2650-device-model.yaml
kubectl apply -f CC2650-device-instance.yaml
Expand Down