Menu

BlocklyScripts

Jim

Blockly Language

Blockly (https://developers.google.com/blockly) is a visual prrgramming language integrated in the M2MLabs Mainspring server to write scripts that are triggered when a new sensor value is received.

In addition to the standard Blockly blocks a set of Mainspring specific blocks allow interaction with the functionality of Mainspring to process sensor values and perform actions.

Sensordata Blocks

Sensordata Blocks

  • get actual sensor name: returns the name of the sensor being processed in the actual call of the script.
  • get actual attribute name: returns the name of the attribute being processed in the actual call of the script.
  • get received value of attribute <name>: returns the value of the given attribute of the device being processed in the actual call of the script.
  • get received datapoint of attribute <name>: returns the datapoint (timestamp, value) of the given attribute of the device being processed in the actual call of the script.
  • get received datapoint list of attribute <name>: returns all datapoints (timestamp, value) of the given attribute of the device being processed in the actual call of the script.
  • get value of <device> <sensor> <attribute>: returns the last stored value of the given device, sensor and attribute. This allows to read values of any device.
  • get datapoint of <device> <sensor> <attribute>: returns the last stored datapoint (timestamp, value) of the given device, sensor and attribute. This allows to read values of any device.
  • get datapoint list of <device> <sensor> <attribute> <max number="" of="" values="">: returns all stored datapoints (timestamp, value) of the given device, sensor and attribute up to the defined max number of values in descending order of timestamps. This allows to read values of any device.
  • get value of datapoint: returns the value of a datapoint.
  • get timestamp of datapoint: returns the timestamp of a datapoint as epoch.
  • get <device> <parameter>: returns a configuration or status parameter of a device
Actions Blocks

Actions Blocks

  • write: writes a value to the log file.
  • set <device> <parameter> <value>: set a configuration or status parameter to the defined value.
  • add to <device> <sensor> <attribute> <value>: add a value to device, sensor and attribute.
  • send command <actor> <parameter> <value>: sends a command to the actor.
  • send http <url> <content> <content type="">: posts a HTTP message to the url with content as payload and content type as http content type (e.g. application/json).
  • send email <recipient> <subject> <content> <from> <smtphost> <smtpport> <username> <password>: sends an email.
Example Script

The script checks the value of a received temperature and switches the cooling on if the temperature is above the defined threshold.
Example


Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.