Is it possible to access light sensor raw data logs from an Android device (in my case, an LG Optimus)? If so, how is this possible and what format would the log be in?
The Android system monitors the light sensor (for things like auto-adjusting the backlight), but to my knowledge doesn't specifically log that data by default.
You can get an app like AndroSensor which allows access to all your phone sensors and can monitor and log the data for you.
Sadly, although Android does have light sensor data, it does not store it anywhere (as far as I'm aware anyway). Luckily, there is a very simple way of accessing and storing the data yourself!
Just follow the steps below, and you should be up and running with light sensor data in no time!
- Download Tasker from the Play Store
- Make a new .txt file in your documents folder and name it to
Light_sensor_data.txt(You may need a file viewer/editor such as File Explorer).
- Open Tasker and click
+→ Event → System → Device Boot.
- Click on the gear (back) in the top left corner.
- A pop-up menu will appear. Tap on New Task and name it
Light Sensor Data(Or whatever you want).
- Within the task, click on
+→ File → Write File.
- To the right of where it says File, there is a magnifying glass; Click on it.
- Now tap Documents → Light_sensor_data.txt
- Click the "pencil" to the right of Text. Now scroll down the list that says Variable Select and find Light Level. It is close to the middle.
- Now click the Gear or Back button.
+→ Task → Wait. If you need your results to update quickly, I would suggest setting MS to anywhere between
100, however this will use a lot of CPU so if you're ok with slower updating results, I would set Seconds to between
- Once again, click on the Gear (back). Now select
+→ Task → Goto and set Type to
Action Numberand Number to
- Tap the Gear (back) twice to get to the Tasks screen. Now click Profiles at the top of the screen.
- Tap on
+→ Event → System → Device Boot and click the Gear (back). A menu should pop-up; select Light Sensor Data.
- On the Profiles tab there should be a On/ Off switch to the right of your Task. Turn it to Off and then back to On.
- Restart your device.
Important note: not only you must have a light sensor on your device, but it must also be enabled. You can check if it is enabled or not by hitting the three dots in the upper right corner of tasker → Preferences and selecting the monitor tab. Now scroll down to Light Sensor and ensure that Yes is selected.
Given that everything was setup properly, you should now be able to access light levels by reading Light_sensor_data.txt You can also read the light level data using Tasker and even create a pop-up displaying the current information.
Good luck, and I hope this helps you.
Easy way to access it is to install Termux, a Linux terminal emulator that gives you access to the Linux commands on Android. On Samsung A3, you can access the data with
cat /sys/class/sensors/light_sensor/lux cat /sys/class/sensors/light_sensor/raw_data #alternative
You can install Python with Termux and write a Python script that will read the content of these files, and publish it on any Pub/sub system with MQTT. I've tried Mosquitto, and it works perfectly with Termux. You can even publish to cloud IOT of either AWS or Microsoft or Google. Any IoT broker will do.