I have an Arduino Yun which is interfaces via I2C to a Adafruit BNO055 breakout board.
My Aim is to use Python Flask in conjunction with BridgeServer and BridgeClient to obtain the Sensor Information from the ATmega32u4 microcontroller to the Microprocessor and use HTML5 Server Side Event (SSE) to display live sensor information on Network interfaces.
I would like to show the Euler angles and Linear Acceleration values:
- heading
- pitch
- roll
- linear_accerlation_x
- linear_acceleration_y
- linear_acceleration_z
An Example of similar concept can be obtained from Smart Measuring Cup by Adafruit. However, in the code sketch the user sends only one value :
BridgeClient client;
....
client.println(volume, 5);
And at the Python Flask end the code opens up a socket and uses makefile()
method to read value
def yunserver_sse():
try:
# Connect to YunServer instance that's listening on localhost.
soc = socket.create_connection(('localhost', 5678))
socfile = soc.makefile()
while True:
# Get data from server.
line = socfile.readline()
# Stop if the server closed the connection.
if not line:
raise StopIteration
# Send the data to the web page in the server sent event format.
yield 'data: {0}\n\n'.format(line)
# Sleep so the CPU isn't consumed by this thread.
time.sleep(0)
except socket.error:
# Error connecting to socket. Raise StopIteration to quit.
raise StopIteration
Instead of sending just one measured parameter how can I send all above mentioned 6 at the same time?
note
I tried using ArduinoJson library but I find it difficult to parse the JSON on the Python Flask end as readline()
expects a \n
at the end of the string.