1
完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
Make an app for the ti SensorTag in 5 minutes! Everyone who knows web technologies can now create mobile applications for the Texas Instruments TI SensorTag. Thanks to a high-level scripting library there is no need to do low-level programming in Objective-C or Java. And you can still do a native build of the final app and publish it on Apple App Store and on Google Play.
The TI SensorTag In this tutorial we will look at a new and innovative way to develop mobile applications for the Texas Instruments TI SensorTag – using HTML5 and JavaScript. By building on the code examples and the demo app, you will be able to contribute your own SensorTag apps to the app stores, using web technologies and a high-level JavaScript library specially made to communicate with the SensorTag. The Texas Instruments TI SensorTag is a widely-popular battery powered, Bluetooth Low Energy (BLE) device, with a number of different sensors that can be used for various applications and projects. Available sensors are:
Demo app The demo app showcases the TI SensorTag. Coded in HTML5 and JavaScript, the app runs on a mobile phone or tablet (Android or iOS) and the various values from the SensorTag is displayed on-screen in real time. To date, only a few Android-based devices actually carry the required BLE hardware and software (September 2014), so please make sure your devices meets the requirements to avoid frustration. For iOS, iPhone 4S or later with iOS 7 or later will all work with this demo app. The app connects to the closest SensorTag when started and displays readings for the different sensors. You can modify this example to do something interesting with the sensor values. Here is a photo of the app running on an iPad Mini: In the code The demo app consists of the following files:
The entire application logic of the demo app is made up by 92 lines of JavaScript code. Here is the complete listing: // SensorTag object.var sensorTag = TISensorTag.createInstance()function initialiseSensortag()[ sensorTag .statusCallback(statusHandler) .errorCallback(errorHandler) .keypressCallback(keypressHandler) .irTemperatureCallback(irTemperatureHandler) .humidityCallback(humidityHandler) .barometerCallback(barometerHandler) .accelerometerCallback(accelerometerHandler, 100) .magnetometerCallback(magnetometerHandler, 100) .gyroscopeCallback(gyroscopeHandler, 100) .connectToClosestDevice()]function statusHandler(status)[ displayValue('StatusData', status)]function errorHandler(error)[ displayValue('StatusData', 'Error: ' + error) if ('disconnected' == error) [ // If disconneted attempt to connect again. setTimeout( function() [ sensorTag.connectToClosestDevice() ], 1000) ]]function keypressHandler(data)[ displayValue('KeypressData', data[0])]function irTemperatureHandler(data)[ displayValue( 'IRTemperatureData', data[0] + ',' + data[1] + ',' + data[2] + ',' + data[3])]function accelerometerHandler(data)[ //console.log('length: ' + data.length) //console.log('acceldata: ' + data[0] + ' ' + data[1] + ' ' + data[2]) displayValue( 'AccelerometerData', data[0] + ',' + data[1] + ',' + data[2])]function humidityHandler(data)[ displayValue( 'HumidityData', data[0] + ',' + data[1] + ',' + data[2] + ',' + data[3])]function magnetometerHandler(data)[ displayValue( 'MagnetometerData', data[0] + ',' + data[1] + ',' + data[2])]function barometerHandler(data)[ displayValue( 'BarometerData', data[0] + ',' + data[1] + ',' + data[2] + ',' + data[3])]function gyroscopeHandler(data)[ displayValue( 'GyroscopeData', data[0] + ',' + data[1] + ',' + data[2] + ',' + data[3] + ',' + data[4] + ',' + data[5])]function displayValue(elementId, value)[ document.getElementById(elementId).innerHTML = value]document.addEventListener('deviceready', initialiseSensortag, false)When the app starts, the initialiseSensortag function is called. This function creates a SensorTag object that we use to enable sensors. The API for defining sensors uses a “fluent” style, where you chain together function calls. For each sensor used in the app, a callback function is given. This function will be called when sensor values are updated. Some sensors have a setting for the update interval, which given in milliseconds. As the final initialisation step, the function connectToClosestDevice is called. This makes the app scan for and connect to the SensorTag with the strongest RSSI (signal strength) value. The callback functions take a data parameter, that contains an array of sensor values (byte values). The number of data values differ depending on the sensor. For the full documentation of sensors and sensor values, see SensorTag_User_Guide and BLE_SensorTag_GATT_Server.pdf. Running the app using Evothings Studio The TI SensorTag app has been developed using Evothings Studio. When developing apps with Evothings Studio, you run the Evothings Client app on your mobile device to execute the application, and you use Evothings Workbench on your laptop/desktop machine, running a live-reload server. Start by installing the Evothings Client app on your iOS or Android device (available in the AppStore and on Google Play). If you use an Android device, make sure it has full support for BLE and runs Android 4.3 or later. Then download Evothings Studio and run the Evothings Workbench live server on your computer. To run the TI SensorTag demo app, do as follows:
Fun things to do You can modify the app in various ways. Play around with the source code, find out how to use Evothings Studio to quickly see your changes on the mobile device. You can for example play around with chaining the colours of the UI, make different things happen when pressing the buttons on the SensorTag, move an absolutely positioned div-tag using accelerometer data, and so on. Using BLE from JavaScript It can be quite a challenge to develop mobile applications for the Internet of Things (IoT) using Bluetooth Low Energy (BLE). By using high-level JavaScript libraries, IoT app development can be made easier and quicker. To access BLE from JavaScript, the Evothings BLE plugin for Apache Cordova is used. Files of interest:
Any app you create using Evothings Studio can be packaged as a native Apache Cordova app, that can be published on the app stores. The Evothings Client app itself is a Cordova app, it was even developed using Evothings Workbench! How to build a native app with Cordova is described in the Evothings Build Documentation. Share your projects Announce your apps and keep the discussion going on the Evothings Forum. Evothings Studio is a set of development tools that makes it fun to develop and rapid prototype IoT-apps for mobile phones and tablets. |
|
相关推荐
2个回答
|
|
谢谢分享!
TI sensortag的相关资料可以在 http://www.ti.com/ww/en/wireless_connectivity/sensortag2015/tearDown.html 进行下载 |
|
|
|
学习了 赞
|
|
|
|
只有小组成员才能发言,加入小组>>
336 浏览 1 评论
529 浏览 2 评论
NA555DR VCC最低电压需要在5V供电,为什么用3.3V供电搭了个单稳态触发器也使用正常?
774 浏览 3 评论
MSP430F249TPMR出现高温存储后失效了的情况,怎么解决?
651 浏览 1 评论
对于多级放大电路板,在PCB布局中,电源摆放的位置应该注意什么?
1130 浏览 1 评论
AT32F407在USART2 DMA发送数据时,接包接到了要发送的数据,程序还是处于等待传输完成的标识判断中,为什么?
56浏览 29评论
127浏览 23评论
请问下tpa3220实际测试引脚功能和官方资料不符,哪位大佬可以帮忙解答下
252浏览 20评论
请教下关于TAS5825PEVM评估模块原理图中不太明白的地方,寻求答疑
201浏览 14评论
两个TMP117传感器一个可以正常读取温度值,一个读取的值一直是0,为什么?
57浏览 13评论
小黑屋| 手机版| Archiver| 德赢Vwin官网 ( 湘ICP备2023018690号 )
GMT+8, 2024-12-23 00:10 , Processed in 0.759550 second(s), Total 50, Slave 44 queries .
Powered by 德赢Vwin官网 网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
德赢Vwin官网 观察
版权所有 © 湖南华秋数字科技有限公司
德赢Vwin官网 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号