-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
plotting real time android sensor data
- Loading branch information
1 parent
b13fcb1
commit 0bc757e
Showing
17 changed files
with
132 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
![rot_vector](https://github.com/imvickykumar999/Android-Sensors/assets/50515418/2fa50fe6-1e35-4009-8e3d-9eec602b3483) | ||
![proximity](https://github.com/imvickykumar999/Android-Sensors/assets/50515418/5bf043ce-f434-4185-8c3e-e07c9af412ca) | ||
![mag](https://github.com/imvickykumar999/Android-Sensors/assets/50515418/6ae3c745-af0e-46e2-900f-22d74d83ab63) | ||
![lin_accel](https://github.com/imvickykumar999/Android-Sensors/assets/50515418/ddd9e4d9-e248-4244-9051-7155730b33fb) | ||
![gyro](https://github.com/imvickykumar999/Android-Sensors/assets/50515418/e37a20c3-2769-4984-a1f3-67aa945eebcc) | ||
![gravity](https://github.com/imvickykumar999/Android-Sensors/assets/50515418/086d2d37-b036-4f32-a536-9b8d7642551e) | ||
![battery_voltage](https://github.com/imvickykumar999/Android-Sensors/assets/50515418/c92ace71-b316-48c8-a0b4-3081b97a5e61) | ||
![battery_temp](https://github.com/imvickykumar999/Android-Sensors/assets/50515418/ec2027fe-851e-471f-9aeb-b11d6d86f131) | ||
![battery_level](https://github.com/imvickykumar999/Android-Sensors/assets/50515418/9e81f2ac-911c-4ae0-b43b-9d43fe97087b) | ||
![battery_charging](https://github.com/imvickykumar999/Android-Sensors/assets/50515418/c165525c-ea1a-46f1-9502-eff350ee79c5) | ||
![accel](https://github.com/imvickykumar999/Android-Sensors/assets/50515418/cfb50d2f-759f-4c7b-8268-a78a201a4d31) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
|
||
# Download IP WebCam and Enable Data Logging. | ||
# https://play.google.com/store/apps/details?id=com.pas.webcam&hl=en&gl=US | ||
|
||
# On starting Server after scrolling all the way to bottom, | ||
# Data will be visible on http://{ip}:{port}/sensors.json | ||
|
||
import matplotlib.animation as animation | ||
import matplotlib.pyplot as plt | ||
from datetime import datetime | ||
from matplotlib import style | ||
import requests, json | ||
|
||
def convert(ts): | ||
ts /= 1000 | ||
unix = datetime.utcfromtimestamp(ts) | ||
mili = unix.strftime('%Y-%m-%d %H:%M:%S') | ||
return mili | ||
|
||
username = 'imvickykumar999' | ||
password = 'imvickykumar999' | ||
|
||
ip,port = '192.168.0.102', 8080 | ||
link = f"http://{ip}:{port}/sensors.json" | ||
|
||
style.use('fivethirtyeight') | ||
fig = plt.figure() | ||
ax1 = fig.add_subplot(1,1,1) | ||
|
||
print() | ||
sensor = {} | ||
filename = 'sensor.json' | ||
|
||
try: | ||
r = requests.get(link, auth=(username, password)) | ||
data = r.json() | ||
|
||
with open(filename, 'w') as outfile: | ||
json.dump(data, outfile) | ||
except: | ||
with open(filename, 'r') as f: | ||
data = json.load(f) | ||
|
||
for i, j in enumerate(data.keys()): | ||
print(i, j) | ||
sensor.update({i : j}) | ||
|
||
inp = input('\nEnter sensor number : ') | ||
if inp == '': | ||
inp = 0 | ||
else: | ||
inp = int(inp) | ||
|
||
def animate(k): | ||
try: | ||
r = requests.get(link, auth=(username, password)) | ||
data = r.json() | ||
|
||
xs, ys = [], [] | ||
keys = data[sensor[inp]] | ||
|
||
for i in keys['data']: | ||
print( | ||
format(i[1][0], ".5f"), | ||
keys['unit'], | ||
'\t', | ||
convert(int(i[0])) | ||
) | ||
xs.append(float(i[0])) | ||
ys.append(float(i[1][0])) | ||
|
||
ax1.clear() | ||
ax1.plot(xs, ys) | ||
ax1.set_ylim(-50, 50) | ||
|
||
plt.title(' '.join(sensor[inp].title().split('_'))) | ||
plt.savefig(f"static/{sensor[inp]}.png") | ||
return fig | ||
|
||
except Exception as e: | ||
print('\nPress CTRL+PAUSE/BREAK to exit.\n', e) | ||
|
||
plt.savefig(f"static/{sensor[inp]}.png") | ||
exit() | ||
|
||
print(f'Graph of {sensor[inp]}') | ||
ani = animation.FuncAnimation(fig, animate, interval=100) | ||
plt.show() | ||
|
||
|
||
rf''' | ||
>>> python live_plot.py | ||
0 accel | ||
1 battery_charging | ||
2 mag | ||
3 gyro | ||
4 proximity | ||
5 gravity | ||
6 lin_accel | ||
7 rot_vector | ||
8 battery_voltage | ||
9 battery_level | ||
10 battery_temp | ||
Enter sensor number : 0 | ||
Graph of accel | ||
. | ||
. | ||
. | ||
-0.7111 m/s² 2023-11-23 07:46:25 | ||
-1.3647 m/s² 2023-11-23 07:46:25 | ||
-1.1636 m/s² 2023-11-23 07:46:25 | ||
-0.9625 m/s² 2023-11-23 07:46:25 | ||
'accel' | ||
QObject::~QObject: Timers cannot be stopped from another thread | ||
^C | ||
''' |
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.