Skip to main content
Version: 1.6.0

Compute

Hopit enables edge computing using Python to perform calculations on source signals. Additionally, new signals can be created through computation. One Python script can be executed for each route.

First, install your preferred Python version from the official Python website. Then, navigate to the Settings page and manually configure the Python DLL if it cannot be detected automatically.

https://localhost:5050/Settings
Compute Module Settings

Once the Python settings are configured, you can start writing a Python script for any route by opening the Python editor.

https://localhost:5050/Routes
Python Editor for the Compute Module

You can then edit the Python script as demonstrated in the comments of the example. Each script must define the function:

compute(signals, time: datetime, period: timedelta)

This function is triggered at each scrape interval. The arguments passed to it are:

  • signals: a dictionary containing the current signal values,
  • time: the current timestamp,
  • period: the time elapsed since the last function call.

You can access and modify individual signals using dictionary-style syntax: signals["<<SIGNAL_NAME>>"].

The initialization function setup() is called once before the first compute call and can be used to initialize the global state, load configurations, or prepare external resources.

Logging from the Python script to hopit's Log can be done using these functions for the respective log levels:

  • log.trace(message)
  • log.debug(message)
  • log.info(message)
  • log.warning(message)
  • log.error(message)
  • log.critical(message)