pyopticon.majumdar_lab_widgets.iot_relay_widget module

class pyopticon.majumdar_lab_widgets.iot_relay_widget.IotRelayWidget(parent_dashboard, name, nickname, default_serial_port)

Bases: GenericWidget

Widget for using an Arduino to control a Digital Loggers Internet of Things (IoT) Relay, like this: https://www.digital-loggers.com/iot2.html . This can be used for on/off control of pretty much any AC-powered device like a light, fan, or pump.

The arduino is expected to control the IoT relay with a digital output pin and to read serial commands using its built-in USB connection. An arduino nano works well; these typically use mini-B USB connections. The arduino ground and digital output pin get connected to the green connector on the side of the IoT relay. Commands to the arduino are broken up by carriage return and newline characters. The arduino should turn on the IoT relay when the command ‘1’ is received and turn it off when the command ‘0’ is received. Additionally, when the command ‘Q’ for query is received, it should reply with its status (‘1’ or ‘0’) followed by a newline or carriage return character.

A suitable arduino sketch (program) to control the IoT relay can quickly be written by analogy to this Arduino forum post: https://forum.arduino.cc/t/serial-commands-to-activate-a-digital-output/49036/3 A working .ino sketch is also available in the majumdar_lab_widgets source code file on this project’s Github.

Parameters:
  • parent_dashboard (richardview.dashboard.RichardViewDashboard) – The dashboard object to which this device will be added

  • name (str) – The name that the widget will be labeled with, and under which its data will be logged, e.g. “Methane Mass Flow Controller”

  • nickname (str) – A shortened nickname that can be used to identify the widget in automation scripts, e.g. “CH4 MFC”

  • default_serial_port (str) – The name of the default selected serial port, e.g. ‘COM9’

on_failed_serial_open()

If serial failed, set readout to ‘No Reading’

on_handshake()

Handshake with the Arduino.

on_update()

Query the device and update the display based on the reply.

on_serial_close()

When serial is closed, set all readouts to ‘None’.

on_confirm()

When ‘confirm’ is pressed, send the appropriate commands to the arduino.