serial

class platypush.plugins.serial.SerialPlugin(device=None, baud_rate=9600, **kwargs)[source]

Bases: SensorPlugin

The serial plugin can read data from a serial device, as long as the serial device returns a JSON. You can use this plugin to interact for example with some sensors connected through an Arduino. Just make sure that the code on your serial device returns JSON values. If you’re using an Arduino or any ATMega compatible device, take a look at https://github.com/bblanchon/ArduinoJson.

__init__(device=None, baud_rate=9600, **kwargs)[source]
Parameters:
  • device (str) – Device path (e.g. /dev/ttyUSB0 or /dev/ttyACM0)

  • baud_rate (int) – Serial baud rate (default: 9600)

get_measurement(device=None, baud_rate=None)[source]

Reads JSON data from the serial device and returns it as a message

Parameters:
  • device (str) – Device path (default: default configured device)

  • baud_rate (int) – Baud rate (default: default configured baud_rate)

read(device=None, baud_rate=None, size=None, end=None)[source]

Reads raw data from the serial device

Parameters:
  • device (str) – Device to read (default: default configured device)

  • baud_rate (int) – Baud rate (default: default configured baud_rate)

  • size (int) – Number of bytes to read

  • end (int, bytes or str) – End of message byte or character

write(data, device=None, baud_rate=None)[source]

Writes data to the serial device.

Parameters:
  • device (str) – Device to write (default: default configured device)

  • baud_rate (int) – Baud rate (default: default configured baud_rate)

  • data (str, bytes or dict. If dict, it will be serialized as JSON.) – Data to send to the serial device