Android datalogger from a Bluetooth LE sensor - Page 1
Forum section: electronics / general

author: RoGeorge
author_rank: Super Contributor
timestamp: August 27, 2023, 03:06:13 pm
content: The sensor is called SensorTag CC2541 from TI.The smartphone is an unused Android 6.0.1 (Marshmallow, level 27).The goal is to permanently log the temperature, humidity and air pressure from the Bluetooth LE SensorTag. Not too fast, once a minute or so, together with a timestamp, then to display a chart on the smartphone.The smartphone can stay powered from its wall adapter, and dedicated to do this task only.On a desktop would be possible to cobble such a logger by simply piping Linux tools, or with a bash script as most, but I guess this is not the case for Android. Would like to be all FOSS, if possible platform independent, too.What would be the approach? Is the Google SDK a must?

author: abeyer
author_rank: Frequent Contributor
timestamp: August 27, 2023, 09:35:10 pm
content: Not sure if it would be thebestapproach, but if you're trying to do something "easy" and without using the android sdk, I believe the web bluetooth apis are available in chrome on android back to 6. Seems like you might be able to do that in a little web app running in chrome. (though I haven't actually tried it... so ymmv, and I'd like to hear the outcome if you try it.)

author: RoGeorge
author_rank: Super Contributor
timestamp: August 28, 2023, 06:46:24 am
content: I want the easiest way to see some temperature/humidity/pressure chart on those SensorTag + phone, instead of keeping them unused in a drawer.Keeping it simple, and not using the Android Studio would have been nice, but I don't know enough Android development to swim against the current, so I give up to that idea. I've installed yesterday the current Android Studio Giraffe (2022.3.1 Patch 1) with the extension for Marshmallow (API23) and KVM (on Kubuntu 22.04).Found the sources of an app that does exactly that, plots some reads from a BLE sensor:http://mylifewithandroid.blogspot.com/2016/03/android-phone-as-weather-station.htmlThe problem is that I couldn't compile that for Android Marshmallow (API 23). The author has a zip with only the necessary files, not the entire project. It is supposed to create a default project, then replace the 'main' directory with the files from the zip. Then to manually modify the buil.gradle file.Never developed anything for Android before, so I have no idea what options to choose when creating the blank 'No activity' project, what/where to change from default to the old API23, and so on.At some point the author wrote "update app/build.gradle like this:"QuoteThe file created by the new project wizard already has anapp/build.gradlefile with its own section of dependencies. Even more, Gradle has changed since 2016 when that blog post was made, so now the Android Studio editor strikeout the words "compile" and invites me to run a syntax updater, about which I have no idea what it is, and so on.A few blogposts before the one I want to use, the author tells how to deploy the zip into a 'No activity" empty projected created with Android Studio:Quotequote fromhttp://mylifewithandroid.blogspot.com/2014/12/ever-since-i-created-gas-sensor-demo.htmlThough that quote was 2 years before what I try to compile, not sure if that procedure was still valid 2 years later.TL;DR the sources are just what I need, but they are not given as a complete project, and can't build an .apk with them.- Don't know if I'm creating the empty template with the proper choices,- or if I'm editing the gradle.build properly,- or if those sources can still be compiled with the today Android Studio,- or if some other extra settings are needed in the current Android Studio in order to build an .apk for Marshmallow- or maybe something else entirelyErrors are many and various depending of what I'm doing, so that's why not posting any error messages yet, still diggin'.

author: RoGeorge
author_rank: Super Contributor
timestamp: August 29, 2023, 08:05:53 am
content: The procedure described there to turn the zip into an Arduino Studio project didn't work for me, but managed to mix the provided sources with another complete project from the same blog, then import that in the latest Android Studio Giraffe.Had to fiddle a lot with the imported project files until it built without errors, but it worked eventually (please ignore the name, GasSensorDemo is a leftover from the projects mix, the attached project is the weather station from the above linked blog page). Had to change acaseinstruction intoif-then, manually add AIDL folder, specify extra parameters in the build.gradle file, change the repositories from intelij to google, etc. There were many changes in Android phones and in Android Studio since ~2015.The funny part is that the Weather Station apk doesn't work for my SensorTag. That project is for receiving from an advertising BLE beacon (a particular one that puts the data in a certain format, built for this particular project), while the SensorTag is not broadcasting it's sensor data. SensorTag uses proper GATT, and requires BLE pairing.