IOS Sensor Tracking with SensorLog

IOS Sensor Tracking with SensorLog

Over the years I’ve used a variety of sensor tracking programs that ran on smart phones. These programs will read the sensors built in the phone and log them. I like this because it uses hardware that is already available. There are many apps that I have used to do this. The latest one I used is called SensorLog authored by Bernd Thomas. As of this writing it is at version 1.9.2, dated June 2nd, 2017. I’ll be covering some key points about this app that I hadn’t found online. Hopefully this will be useful for anyone looking to use this program.

Link to iTunes Apple Store – https://itunes.apple.com/us/app/sensorlog/id388014573?mt=8

First, let me give an overview of what SensorLog can do. This program will track and log sensor values read from IOS devices. The logging can be stored locally on the device or over the network using a couple of different methods. The sensors logged are the tilt, gyro, magnetic, audio, and GPS sensors. It also logs the uptime of the sensors as well as battery levels of the IOS device.

SensorLog does not display logged data. It does not have any reporting or other data representation mechanism. The program is focused instead on gathering sensor data to log files. Besides the internal log storage, data logs can also be sent to remote hosts. The first method is creating a sockets connection. Basically this allows the iPhone to open a port up to allow remote hosts to connect to it. Bernd gives an example of an Apple Mac storing the logs to its file system using this command.

nc 192.168.2.106 56204 > mylogfile.csv

The “nc” command is called netcat and it is a client server application. In the above example, we are using it on a Mac as a client. It is connecting to the iPhone’s IP address, mostly via WiFi. The port follows the IP, which is defined in SensorLog. Lastly, the “> mylogfile.csv” outputs to a file on the Mac, instead of displaying it on the screen, which is the default behavior of netcat data. Here is an example of netcat used as IRC.

The following screen shows the settings in SensorLog that allow it to be a netcat server.

The recording rate will change how often the sensor values are polled and displayed on the netcat client. It was interesting to log data this way. Connecting the iPhone to wireless and running SensorLog allowed me to track the iPhone from a Linux system with a fairly high recording frequency. The tilt, accelerometer, and gyro data showed as the iphone traveled through the building.

The sockets method can also be used in conjunction with locally saving the data to log files. These can then be emailed through a manual process. If you want a truly automated logging process, the GET/POST methods should do it.

The HTTP upload option should be set with either a GET or POST option. There are pre defined frequencies to choose from. The record rate available to socket or file logging doesn’t have the same resolution or granularity. The URL is going to be the website you plan to provide the sensor data to.

In the example provided by Bernd, available at http://www.berndthomas.net/SensorLog.php.zip, I use a php landing page that takes the URL string submitted by the SensorLog app and writes that to a locally stored log file. If I visit that same URL with a standard computer, it will display the log file contents. This is a great way to share the raw data in real time to anyone. Just be mindful of security if you have concerns and apply it where appropriate. This mechanism provides no security, so you’ll need to account for that elsewhere. Maybe in future versions the URL will support HTTPS. So do realize that the content can be intercepted and viewed by third parties.

Using Bernd’s php code wasn’t difficult, all you really need is a LAMP. I did make some changes to the code. The path of the log file is fully defined. Since I changed the location out of my webroot, I had to set permissions accordingly. Without the permission changes, the page displayed “Unable to open file” messages. Once set, I was able to see the data entered in the log file. In addition, when I visited the php page with my computer, I was also able to see the data logged.

It’s a modest logger, I’m looking forward to running the app on some bike routes in the future. Having a raw logger is nice because it affords me the option to manipulate, process, and present the data as I like. Who knows, maybe I’ll expand on the GET POST methods and have php log to a database. From there the data can do some really amazing things. That would be too much to cover in this post.

Since there isn’t much online information about the app, here is some information taken from the app itself for those interested in the details.

With SensorLog you can log your iPhone’s or iPad’s sensor data in four different ways: save to a file, read data during recording from a tcp/ip socket, combine both methods, and / or send via HTTP GET/POST method to a server.

The data sent by SensorLog over the tcp/ip socket follows the identical syntax as if you use the option log to file. If you select the method “log data to file”, you can send the log file as an email attachment or you can download it via iTunes.

To receive sensor data from SensorLog over a tcp/ip connection you can use any type of application that provides the possibility to open a tcp/ip connection on a dedicated socket port. On a mac computer running OS X you can do so by starting the terminal application and use for example the programs telenet or nc.

If for instance SensorLog writes to the socket with IP 192.168.2.106 using port 56204 you can save the received data to a file on your Mac’s filesystem by the following command:

$ nc 192.168.2.106 56204 > mylogfile.csv

Please note that your iPhone and computer need to be connected to a network with policies not blocking the communication.

If no WLAN is available setting up a personal hotspot on your iOS device is also an option to connect with your computer to SensorLog.

To retrieve data via HTTP GET/POST you need to operate a server which is able to process HTTP GET / POST requests. Please enter the fully qualified URL under which your server and its SensorLog service is reachable into the text field titled URL. SensorLog uses the csv column names as GET/POST argument names and the samples data as their values. A simple PHP example script can be found under

http://www.berndthomas.net/SensorLog.php.zip

Explanation of the logged data (csv columns):

loggingTime(txt) The time a set of sensor samples (csv line) is written to the log file or socket. For the sample time of an individual sensor please see the timestamp of each sensor.

loggingSample(N) Sample set (csv line) number.

identifierForVendor(txt)
https://developer.apple.com/reference/uikit/uidevice/1620059-identifierforvendor
https://developer.apple.com/reference/foundation/nsuuid/1416585-uuidstring

deviceID(txt) A device ID chosen by the user.

locationTimestamp_since1970(s)
locationLatitude(WGS84)
locationLongitude(WGS84)
locationAltitude(m)
locationSpeed(m/s)
locationCourse(°)
locationVerticalAccuracy(m)
locationHorizontalAccuracy(m)
locationFloor(Z)
https://developer.apple.com/reference/corelocation/cllocation

locationHeadingTimestamp_since1970(s)
locationHeadingX(µT)
locationHeadingY(µT)
locationHeadingZ(µT)
locationTrueHeading(°)›locationMagneticHeading(°)
locationHeadingAccuracy(°)
https://developer.apple.com/reference/corelocation/clheading

accelerometerTimestamp_sinceReboot(s)
https://developer.apple.com/reference/coremotion/cmlogitem
accelerometerAccelerationX(G)
accelerometerAccelerationY(G)
accelerometerAccelerationZ(G)
https://developer.apple.com/reference/coremotion/cmaccelerometerdata

gyroTimestamp_sinceReboot(s)
https://developer.apple.com/reference/coremotion/cmlogitem
gyroRotationX(rad/s)
gyroRotationY(rad/s)
gyroRotationZ(rad/s)
https://developer.apple.com/reference/coremotion/cmgyrodata/1616167-rotationrate

motionTimestamp_sinceReboot(s)
https://developer.apple.com/reference/coremotion/cmlogitem
motionYaw(rad)
motionRoll(rad)
motionPitch(rad)
https://developer.apple.com/reference/coremotion/cmattitude

motionRotationRateX(rad/s)
motionRotationRateY(rad/s)
motionRotationRateZ(rad/s)
https://developer.apple.com/reference/coremotion/cmdevicemotion/1615967-rotationrate

motionUserAccelerationX(G)
motionUserAccelerationY(G)
motionUserAccelerationZ(G)
https://developer.apple.com/reference/coremotion/cmdevicemotion/1616149-useracceleration

motionAttitudeReferenceFrame(txt)
motionQuaternionX(R)
motionQuaternionY(R)
motionQuaternionZ(R)
motionQuaternionW(R)
https://developer.apple.com/reference/coremotion/cmattitude

motionGravityX(G)
motionGravityY(G)
motionGravityZ(G)
https://developer.apple.com/reference/coremotion/cmdevicemotion/1616164-gravity

motionMagneticFieldX(µT)
motionMagneticFieldY(µT)
motionMagneticFieldZ(µT)
motionMagneticFieldCalibrationAccuracy(Z)
https://developer.apple.com/reference/coremotion/cmcalibratedmagneticfield

activityTimestamp_sinceReboot(s)
https://developer.apple.com/reference/coremotion/cmlogitem
activity(txt)
activityActivityConfidence(Z)
activityActivityStartDate(txt)
https://developer.apple.com/reference/coremotion/cmmotionactivity

pedometerStartDate(txt)
pedometerNumberofSteps(N)
pedometerDistance(m)
pedometerFloorAscended(N)
pedometerFloorDescended(N)
pedometerEndDate(txt)
https://developer.apple.com/reference/coremotion/cmpedometerdata

altimeterTimestamp_sinceReboot(s)
https://developer.apple.com/reference/coremotion/cmlogitem
altimeterReset(bool)
altimeterRelativeAltitude(m)
https://developer.apple.com/reference/coremotion/cmaltitudedata/1615907-relativealtitude
altimeterPressure(kPa)
https://developer.apple.com/reference/coremotion/cmaltitudedata

IP_en0(txt) IP address of the WLAN connection.
IP_pdp_ip0(txt) IP address of the cellular data connection.

deviceOrientation(Z)
https://developer.apple.com/reference/uikit/uidevice/1620053-orientation

batteryState(R)
https://developer.apple.com/reference/uikit/uidevicebatterystate
batteryLevel(Z)
https://developer.apple.com/reference/uikit/uidevice/1620042-batterylevel

avAudioRecorderPeakPower(dB)
https://developer.apple.com/reference/avfoundation/avaudiorecorder/1389463-peakpower
avAudioRecorderAveragePower(dB)
https://developer.apple.com/reference/avfoundation/avaudiorecorder/1387176-averagepower

I hope you have enjoyed the introduction to the SensorLog app from Bernd Thomas and some of its features. The limited amount of information online is what prompted me to write this post and I hope it offers you some help with the use of this neat app. Enjoy.

Comments are closed.