So i am trying to get the data from a pressure sensor Boditrak. It is connected via USB but I am not sure which port is it using... When I am connecting it I have this Data Port this is how I see it. It has its own software, but I need to get it through Python. This is the code that I wrote:
import socket
serverAddress = 'http://localhost/api'
serverPort = 63342
bufferSize = 4096
def connect(self):
global s
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.settimeout(10)
print("Connecting to server")
s.connect((serverAddress, serverPort))
print("Connected to server\n")
response = s.recv(bufferSize)
print(response.decode("utf-8"))
Now I am not sure I am doing the right thing... but I am not sure how am I supposed to get it. Any help is appreciated. Also the data looks like this accessed in google chrome and I get every second a new frame
When I am running the script in terminal I get nothing. When I am reading the manual it says: "The DataPort device communicates with client devices (PC, tablet, phones) over a wifi network using a REST API. The primary role of the DataPort device is to scan one or more Boditrak sensor mats at a prescribed frequency and store those readings in a buffer"
Also do I need to have a server side and a client side? If yes, how is it supposed to look like?
Thank you!
PS. This is the live data that I want to get
Maybe I should call this GET /api/sse HTTP/1.1. But how?
For example, i took another approach but still no answer...
import socket
from urllib import parse
def connect():
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
url = parse.urlparse('http://localhost/api')
s.connect((url[1], 80))
msg = 'GET' + 'http://localhost/api' + 'HTTP/1.1\r\n\r\n'
s.send(msg.encode('utf-8'))
response = s.recv(4096)
data = response.decode('utf-8')
print(data)
if __name__ == "__main__":
connect()
I get the following answer:
b''
UPDATE: I get some data now. Here is the code:
import socket #for sockets
import sys #for exit
def connect():
#create an INET, STREAMing socket
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print('Failed to create socket')
sys.exit()
print('Socket Created')
host = '127.0.0.1';
port = 80;
try:
remote_ip = socket.gethostbyname( host )
except socket.gaierror:
#could not resolve
print('Hostname could not be resolved. Exiting')
sys.exit()
#Connect to remote server
s.connect((remote_ip , port))
print('Socket Connected to ' + host + ' on ip ' + remote_ip)
#Send some data to remote server
message2 = b"GET /api/sse HTTP/1.1\r\n\r\n"
try:
# Set the whole string
s.sendall(message2)
except socket.error:
# Send failed
print('Send failed')
sys.exit()
print('Message send successfully')
# Now receive data
reply2 = s.recv(16384)
print('Frames:', reply2.decode())
if __name__ == "__main__":
connect()
And the reply:
Socket Created
Socket Connected to 127.0.0.1 on ip 127.0.0.1
Message send successfully
Frames: Access-control-allow-origin: *
Access-control-allow-methods: GET, OPTIONS
Content-type: application/json
Cache-control: no-cache, no-store, must-revalidate
Pragma: no-cache
Expires: 0
Content-Length: 2583
{
"device":{ "class":"Boditrak DataPort", "name":"DataPort-******", "id":"*********", "address":"127.0.0.1", "model":"wia" },
"sensors":[ { "name":"**********", "columns":32, "rows":32, "width":470, "height":470, "minimum":0, "maximum":200, "units":"mmHg" } ],
"frames":[ { "id":719, "time":"2021-04-19 16:19:47.041", "readings":[ [ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1
,1,2,1,1,2,1,1,1,0,0,0,0,1,1,0,2,2,2,2,1,1,2,3,0,0,0,1,1,2,0,1 ] ] } ],
"filters":{ "spot":false, "smooth":false, "noise":false },
"time":"2021-04-19 16:19:47.097",
"frequency":27000,
"yield":false,
"calibrated":true,
"sensorsRequired":0,
"others":[ ]
}
I have to figure it out how to get it continuously. Still sees the last frame...
Last update!
import socket #for sockets
import sys #for exit
import json
import time
t_end = time.time() + 60 * 0.2
def connect():
#create an INET, STREAMing socket
try:
global s
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
except socket.error:
print('Failed to create socket')
sys.exit()
print('Socket Created')
host = '127.0.0.1';
port = 80;
try:
remote_ip = socket.gethostbyname( host )
except socket.gaierror:
#could not resolve
print('Hostname could not be resolved. Exiting')
sys.exit()
#Connect to remote server
s.connect((remote_ip , port))
print('Socket Connected to ' + host + ' on ip ' + remote_ip)
message2 = b"GET /api/sse HTTP/1.1\r\n\r\n"
try:
# Set the whole string
s.sendall(message2)
except socket.error:
# Send failed
print('Send failed')
sys.exit()
print('Message send successfully')
while time.time() < t_end:
reply2 = s.recv(4096).decode('utf-8')
response = json.dumps(reply2)
print(response)
if __name__ == "__main__":
connect()
This code is working and it is giving me data in real time. I encountered problems with an error: [WinError 10053] An established connection was aborted by the software in your host machine -- and after I deactivated my antivirus it works.
Heading