Author Topic: Android datalogger from a Bluetooth LE sensor  (Read 1005 times)

0 Members and 1 Guest are viewing this topic.

Offline RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 6186
  • Country: ro
Android datalogger from a Bluetooth LE sensor
« on: August 27, 2023, 03:06:13 pm »
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?

Offline abeyer

  • Frequent Contributor
  • **
  • Posts: 290
  • Country: us
Re: Android datalogger from a Bluetooth LE sensor
« Reply #1 on: August 27, 2023, 09:35:10 pm »
Not sure if it would be the best approach, 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.)
The following users thanked this post: RoGeorge

Offline RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 6186
  • Country: ro
Re: Android datalogger from a Bluetooth LE sensor
« Reply #2 on: August 28, 2023, 06:46:24 am »
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:

The 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:"
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.jjoe64:graphview:4.0.1'

The file created by the new project wizard already has an app/build.gradle file 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:
Update: I was asked by e-mail, how to import the project (in into Android Studio. Here is a simple process.

    Create a new project in Android Studio under any name. Make sure that your project supports at least API level 18. Choose the "create no Activity" option.
    Once your project is created, go and find it on the disk. On my Ubuntu system, the project files go under ~/StudioProjects/<ProjectName> where <ProjectName> is the name you gave to your project. We will call this directory <ProjectDir>.
    Go into <ProjectDir>/app/src and delete everything there. Copy into <ProjectDir>/app/src and unzip it. It will create a single directory called "main" and the sources below.
    In Android Studio, do File/Synchronize. After that is completed, you can open your project files, build APK, etc.
quote from

Though 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 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 entirely

Errors are many and various depending of what I'm doing, so that's why not posting any error messages yet, still diggin'.
« Last Edit: August 29, 2023, 08:06:32 am by RoGeorge »

Offline RoGeorgeTopic starter

  • Super Contributor
  • ***
  • Posts: 6186
  • Country: ro
Re: Android datalogger from a Bluetooth LE sensor
« Reply #3 on: August 29, 2023, 08:05:53 am »
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 a case instruction into if-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.  ;D

Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo