Metadata-Version: 2.1
Name: phonesensors
Version: 1.0.0
Summary: A package for receiving data from sensor-streaming phone apps.
Project-URL: Homepage, https://github.com/nup002/PhoneSensors
Project-URL: Bug Tracker, https://github.com/nup002/PhoneSensors/issues
Author-email: Magne Eik Lauritzen <mag.lauritzen@gmail.com>
License: MIT License
        
        Copyright (c) 2022 Magne Eik Lauritzen
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.7
Requires-Dist: numpy
Description-Content-Type: text/markdown

![License](https://img.shields.io/github/license/nup002/PhoneSensors?style=flat-square)
![PyPI](https://img.shields.io/pypi/v/phonesensors?style=flat-square)
[![Flake8](https://github.com/nup002/PhoneSensors/actions/workflows/flake8.yml/badge.svg)](https://github.com/nup002/PhoneSensors/actions/workflows/flake8.yml)
# PhoneSensors
`phonesensors` is a Python package to aid with receiving various sensor data from phones in a quick and easy way. It is 
meant to be used in conjunction with the
[SensorStreamer](https://play.google.com/store/apps/details?id=cz.honzamrazek.sensorstreamer&hl=en&gl=US)
app for Android devices, but support for any other app streaming sensor data over a TCP socket can be implemented 
with ease by subclassing the `BaseParser` in `parsers.py`. 

## How to install
```
pip install phonesensors
```


## How to use
Open the SensorStreamer app and make it a TCP server emitting JSON packets on a port of your choice. Port 5000 is used
for this example. Find out the IP address of your device (e.g. 192.168.1.1). The following code snippet will print
the sensor data being streamed from your device:
```
from phonesensors import SensorStreamerClient, Apps
with SensorStreamerClient("192.168.1.1", 5000, Apps.SENSORSTREAMER) as client:
  for data in client:
    print(data)
```

## Data format
`data` in the above example code snippet is a `SensorDataCollection` instance. You can obtain the specific sensor data 
by accessing its attributes. The sensor data and timestamps are returned as numpy arrays:
```
acceleration_values = packet.acc.values
acceleration_timestamps = packet.acc.timestamps
proximity_values = packet.prox.values
proximity_timestamps = packet.prox.timestamps
```

Data from different sources may have different number of elements due to differences in sampling frequency. For example,
`acceleration_values`, a 3D vector, may have 4 samples and thus be a (4,3) array. While `proximity_values`, a 1D scalar,
may only have one sample and thus be a (1,) array. 
