Skip to main content
Rollback to Revision 2
Source Link
Juraj
  • 18.3k
  • 4
  • 32
  • 50

Reading JSON from Arduino via Serial Missing Parts of Message - SOLVED

EDIT

For anyone else looking for this in the future the change I had to make was in the Python side, using pyserial instead of the version provided by the webiopi.

This is the final code:

import serial

# Configure the serial port (replace with your port and baud rate)
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)

@webiopi.macro
def getSerialArduinoData():
    json = ""

    webiopi.sleep(1)

    ser.write(b'd') #send command "d" to request data from Arduino

    data_bytes = ser.read_until(b'\n') # Read until the newline character

    json = data_bytes.decode('utf-8') # Decode the bytes to a string
    json = json.strip() # Remove the delimiter from the end
    return json

Reading JSON from Arduino via Serial Missing Parts of Message - SOLVED

EDIT

For anyone else looking for this in the future the change I had to make was in the Python side, using pyserial instead of the version provided by the webiopi.

This is the final code:

import serial

# Configure the serial port (replace with your port and baud rate)
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)

@webiopi.macro
def getSerialArduinoData():
    json = ""

    webiopi.sleep(1)

    ser.write(b'd') #send command "d" to request data from Arduino

    data_bytes = ser.read_until(b'\n') # Read until the newline character

    json = data_bytes.decode('utf-8') # Decode the bytes to a string
    json = json.strip() # Remove the delimiter from the end
    return json

Reading JSON from Arduino via Serial Missing Parts of Message

Problem solved.
Source Link

Reading JSON from Arduino via Serial Missing Parts of Message - SOLVED

EDIT

For anyone else looking for this in the future the change I had to make was in the Python side, using pyserial instead of the version provided by the webiopi.

This is the final code:

import serial

# Configure the serial port (replace with your port and baud rate)
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)

@webiopi.macro
def getSerialArduinoData():
    json = ""

    webiopi.sleep(1)

    ser.write(b'd') #send command "d" to request data from Arduino

    data_bytes = ser.read_until(b'\n') # Read until the newline character

    json = data_bytes.decode('utf-8') # Decode the bytes to a string
    json = json.strip() # Remove the delimiter from the end
    return json

Reading JSON from Arduino via Serial Missing Parts of Message

Reading JSON from Arduino via Serial Missing Parts of Message - SOLVED

EDIT

For anyone else looking for this in the future the change I had to make was in the Python side, using pyserial instead of the version provided by the webiopi.

This is the final code:

import serial

# Configure the serial port (replace with your port and baud rate)
ser = serial.Serial('/dev/ttyACM0', 9600, timeout=1)

@webiopi.macro
def getSerialArduinoData():
    json = ""

    webiopi.sleep(1)

    ser.write(b'd') #send command "d" to request data from Arduino

    data_bytes = ser.read_until(b'\n') # Read until the newline character

    json = data_bytes.decode('utf-8') # Decode the bytes to a string
    json = json.strip() # Remove the delimiter from the end
    return json
removed the "can anyone help?" question
Source Link
jsotola
  • 1.6k
  • 2
  • 13
  • 22

Can anyone point me in some directions on why thisWhy could this be happening?

Thank you in advance.

Can anyone point me in some directions on why this could be happening?

Thank you in advance.

Why could this be happening?

Source Link
Loading