Operators

Filtering

Operations that output a subset of their input items.

  • Drop Output all input items except the first n
  • Take Output only the first n input items.
  • Dedup Output every input item that is not equal to the previous input item.
  • Dedup (expiring) Output the input item if it is not equal to the previous input or it has been more than milli milliseconds since the last output.
  • Debounce Outputs each input after millis milliseconds if no other input has been received.
  • Throttle Rate limits the input stream to average at most one value per millis milliseconds. It functions by outputing the first input received (if any) in successive windows of millis milliseconds.
  • Sample Generates a stream of values with the latest value from its input stream every millis milliseconds.
  • Over Output only input items greater than threshold.
  • Under Output only input items less than threshold.
  • AtLeast Output only input items greater than or equal to threshold.
  • AtMost Output only input items less than or equal to threshold.
  • Positive Output only input items that are greater than 0.
  • Negative Output only input items that are less than 0.
  • Zero Output only input items that are less than 0.
  • True Output only input items equal to true.
  • False Output only input items equal to false.
  • Filter For each input item, apply the given function and output the input if the function returns true.

Transformation

Operations that transforms each input item to produce an output item.

  • Const For each input item, output value.
  • Abs For each input item, output it's absolute value.
  • Scale For each input item, output k × input value.
  • Add For each input item, output b + input value.
  • Clamp For each input item, output lo if the input is less than lo, hi if the input more than hi, or the input value if it is between lo and hi.
  • ClampLow For each input item, output the maximum of the input value or lo.
  • ClampHigh For each input item, output the minimum of the input value or hi.
  • IsOver Output true for each input item greater than threshold otherwise false.
  • IsUnder Output true for each input item less than threshold otherwise false.
  • IsAtLeast Output true for each input item greater than or equal to threshold otherwise false.
  • IsAtMost Output true for each input item less than or equal to threshold otherwise false.
  • IsPositive Output true for each input item that is greater than 0 otherwise false.
  • IsNegative Output true for each input item that is less than 0 otherwise false.
  • IsZero Output true for each input item that is less than 0 otherwise false.
  • Toggle On the first input, output ! initial and thereafter output ! previous output.
  • Project1 For each tuple input item, output the 1st element of the tuple
  • Project2 For each tuple input item, output the 2nd element of the tuple
  • Project3 For each tuple input item, output the 3rd element of the tuple
  • Counted For each tuple input item, output a tuple with the input item and total number of inputs seen.
  • Map For each tuple input item, apply the given function to the input and output the returned value.

The signature of function is

out-type function(const in-type&)
  • Map (no copy) For each tuple input item, call the given function with the input and result and output the result.

The signature of function is

void function(const in-type&, out-type&)
  • Scan The scan operator keeps a state of state-type which is initially init. For each input item, the given function is called with the input item and the current state as arguments. The returned value is output and becomes the new state.

The function signature of the update function is

state-type update(const in-type&, const state-type&)
  • Scan (no copy) The scan operator keeps a state of state-type which is initialized by init function (optional). For each input item, the given update function is called with the input item and the current state as arguments. The update can modify the state argument and the new state is the output of the operator.

The function signature of the update function is

void update(const in-type&, state-type&)

and the function signature of the init funciton is

void init(state-type&)

Aggregation

Operators that aggregate or summarize information from multiple items in output items.

  • Count For each item received, output the total number of items received since the start.
  • WinSum Outputs the sum of a width size sliding window over the input stream.
  • SumOf Outputs the sum of each batch of count input items.
  • SumOver Outputs the sum of each batch of input items received over millis milliseconds.
  • WinAverage Outputs the average of a width size sliding window over the input stream.
  • AverageOf Outputs the average of each batch of count input items.
  • AverageOver Outputs the average of each batch of input items received over millis milliseconds.
  • WinMin Outputs the minimum of a width size sliding window over the input stream.
  • MinOf Outputs the minimum of each batch of count input items.
  • MinOver Outputs the minimum of each batch of input items received over millis milliseconds.
  • WinMax Outputs the maximum of a width size sliding window over the input stream.
  • MaxOf Outputs the maximum of each batch of count input items.
  • MaxOver Outputs the maximum of each batch of input items received over millis milliseconds.

String operators

  • Lines Output a stream of lines (strbuf class) from an input stream of characters (char).
  • Format Build a formatted string from input items using the format template. Any occurrence of $1 in the template is replaced by the input value. Occurrences of $t are replaced by the current time as a Unix timestamp (number of seconds since Jan. 1, 1970).
  • Split Splits each input string at the given delimiter and outputs the resulting strings in a vector. The C++ types are strbuf input and Vec<strbuf,max-fields> output.
  • ToString Converts the input values to a string and outputs it as a strbuf
  • ToJson Converts the input values to a JSON string and outputs it as a jsons

Miscellaneous

  • Iterate Generates a stream of values from a generator (e.g. Range). The values are generated one every millis milliseconds. If repeat is true then the iterater will start over with the 1st value after it reaches the last. The millis and repeat parameters are optional with defaults 0 and false respectively.
  • Poll Generates a stream of values from an input by polling the current value every millis milliseconds.
  • Build This operator replaces the scan -> filter -> map pattern with a single operator and also only allocates one result object at creation time. The operator keeps a state of state-type which is initially init. For each input item, the given function is called with the input item and the current state and result as reference arguments. If the function returns true, the current value of result is output otherwise nothing is output.

Classes

Generators

Classes that generated data on demand (e.g. via Iterate)

  • Range Generates integers in the range from to to by increment. The increment is optional and defaults to 1. Combine with Iterate to generate a stream.

Producers

Classes that produce a stream of data

  • Interval Produces integers from 0 on every millis milliseconds.
  • Repeat Produces value every cycle.

Inputs

Classes that receive or sample input data

  • AnalogIn Reads analog values from an ADC pin.
  • BitIn Reads values from a digital pin.
  • GpioSerial Reads serial input from rxPin and outputs char values. A txPin is required, and will be put in output mode, but is never set.

Outputs

Classes that send or output data

  • AnalogOut Writes values to a PWM pin.
  • BitOut Writes values to a digital pin.
  • Console C++: Writes value to the serial output at the given baud. Javascript: Writes value to the console.
  • HttpPost Sends data to an HTTP endpoint using the HTTP POST method using transport (e.g. an instance of WiFiClient). Optional headers are provided as n array of strings.
  • MqttPub Publishs data to an MQTT endpoint with QOS 0. The username, password, and keepAlive parameters are optional.
  • SocketIO Sends data to a WebSocket via the socket.io module io with the event name event.

Consumers

  • Consume Calls the function for each input value with that value as an argument.

Methods

Configuration

Functions for device/system configuration.

  • ConnectWifi Connect to a WiFi access point with the given ssid and password.
  • NetworkTime Set the date/time using an Internet time server with the given transport (e.g. a WiFiClient)
  • Sleepy The Sleepy function enables automatic sleep management on both AVR and Atmel SAMD (ARM) devices. When sleep management is enabled, the scheduler will attempt to put the CPU in sleep/standby mode whenever there is 2 seconds or more before the next scheduled event. Tests on both architectures showed slightly over 2mA current draw while sleeping, which is probably a 1/10th or less of your awake mode usage.

The sleep manager uses the RTC on SAMD architectures and the WDT on AVR. Sleepy can be called from the beginning or end of the app function to enable sleep management. If you set the RTC time during setup, you must do that before calling Sleepy.

The resolution of both the RTC and WDT is 1 second. Using even second values in your program schedule will minimize the amount of time the CPU will be idle between the time it wakes and the next event happens.

USB Interaction - The USB interface tends to interfere with applications using sleep mode, and it is disabled by default when you enable sleep management. I recommend using the SPI interface for output when using sleep mode. If you must use the USB you can call Sleepy with the SLEEP_MGR_USB argument to enable the management of the USB. In this case, the USB will be detached before sleeping and reattached upon wake up.