I used the following code:
import socket
import struct
import pandas as pd
import streamlit as st
UDP_IP = "127.0.0.1"
UDP_PORT = 9000
sock = socket.socket(socket.AF_INET, # Internet
socket.SOCK_DGRAM) # UDP
sock.bind((UDP_IP, UDP_PORT))
while True:
data, addr = sock.recvfrom(1024) # buffer size is 1024 bytes
fields = struct.unpack_from('=ddd', data)
d = {'y': fields[0],
'x': fields[1],
'z': fields[2]}
df = pd.DataFrame([d], columns=d.keys())
df
The app does not display the dataframe (see below). What is the best way to deal with socket data to use in the app? The data is generated 1/60th of a second. I can reduce the frequency to 0.2 s but I don't know how to do that via socket
.