1

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:

  1. heading
  2. pitch
  3. roll
  4. linear_accerlation_x
  5. linear_acceleration_y
  6. 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.

asked Dec 13, 2017 at 21:39

1 Answer 1

0

Apparently the solution to my problem was a simple client.println() after my JSON was ready to be printed to the BridgeClient.

Snippet:

root.printTo(client); client.println();

where root is DynamicJsonBuffer from the ArduinoJson library. The client.println() would immediately print \n and this would be read by the readline() python code.

answered Dec 14, 2017 at 15:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.