这几周研究下原码。我本想用IPHONE的应用软件控制一个开关量,也许是LED,从而控制继电器。再控制电脑开关。
由于IPHONE开发环境要MONEY。所以我想用两个sensortag进行通讯。那样一样行,但就得烧写两个程序一个主一个客户端。
那么就得破坏sensortag。有没有一个简单方法呢。那么就得分析程序。而要获得原码。可以在TI网上下。但我发现一个很好的方法。
从手机就可得到。前提是sensortag必须是连接上地。
在主界面下,点profiles
点Generate Source Code
可以把代码发到自己的邮件上。
Source code for Bluetooth low energy SensorTag.zip
(4.85 KB, 下载次数: 6)
通过浏览可以看出。Sensortag主要靠发广播来建立联系地。也就是说不用啥密码。
除了温度、湿度,三轴等等一些子函数。就是靠以下三个函数来读取数据
- //
- // BLEUtility.m
- //
- // Created by Ole Andreas Torvmark on 9/22/12.
- // Copyright (c) 2012 Texas Instruments All rights reserved.
- //
- #import "BLEUtility.h"
- @implementation BLEUtility
- +(void)writeCharacteristic:(CBPeripheral *)peripheral sUUID:(NSString *)sUUID cUUID:(NSString *)cUUID data:(NSData *)data {
- // Sends data to BLE peripheral to process HID and send EHIF command to PC
- for ( CBService *service in peripheral.services ) {
- if ([service.UUID isEqual:[CBUUID UUIDWithString:sUUID]]) {
- for ( CBCharacteristic *characteristic in service.characteristics ) {
- if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:cUUID]]) {
- /* EVERYTHING IS FOUND, WRITE characteristic ! */
- [peripheral writeValue:data forCharacteristic:characteristic type:CBCharacteristicWriteWithResponse];
-
- }
- }
- }
- }
- }
- +(void)readCharacteristic:(CBPeripheral *)peripheral sUUID:(NSString *)sUUID cUUID:(NSString *)cUUID {
- for ( CBService *service in peripheral.services ) {
- if([service.UUID isEqual:[CBUUID UUIDWithString:sUUID]]) {
- for ( CBCharacteristic *characteristic in service.characteristics ) {
- if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:cUUID]]) {
- /* Everything is found, read characteristic ! */
- [peripheral readValueForCharacteristic:characteristic];
- }
- }
- }
- }
- }
- +(void)setNotificationForCharacteristic:(CBPeripheral *)peripheral sUUID:(NSString *)sUUID cUUID:(NSString *)cUUID enable:(BOOL)enable {
- for ( CBService *service in peripheral.services ) {
- if ([service.UUID isEqual:[CBUUID UUIDWithString:sUUID]]) {
- for (CBCharacteristic *characteristic in service.characteristics ) {
- if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:cUUID]])
- {
- /* Everything is found, set notification ! */
- [peripheral setNotifyValue:enable forCharacteristic:characteristic];
-
- }
-
- }
- }
- }
- }
-
- @end
复制代码
而我就是想要点亮LED的的那部分,我想应是以上的三个函数来起作用啦。