Module: caf_iot/plug_iot_handler

A handler for wrapping application code.

Properties:

 {methodsFileName: string, interval: number}

where:

  • methodsFileName: the name of a file containing the application logic. It defaults to ./iot_methods.js.
  • interval: time in msec between invocations of the main loop, i.e., __iot_loop__.
Source:

Extends

Members

fromCloud :caf.refMap

SharedMap to download information from the CA.

It is read-only.

Type:
  • caf.refMap
Source:

scratch :Object

Scratch state of this device handler.

It never rollbacks and contains anything.

Type:
  • Object
Source:

state :Object

State of this device handler.

It roll backs changes on abort, and contains JSON-serializable data only.

Type:
  • Object
Source:

toCloud :caf.refMap

SharedMap to upload information to the CA.

Type:
  • caf.refMap
Source:

Methods

__ca_fullCycle__(cb0)

Internal function.

Triggers two pulses, the second one after cloud sync finishes.

Sync is always at the end of a pulse, and fullCycle minimizes latency because it can process a cloud request without waiting for the cron process.

Parameters:
Name Type Description
cb0 cbType

A callback to continue after the first pulse.

Source:

__ca_getAppName__() → {string}

Returns the application name.

Source:
Returns:

The application name.

Type
string

__ca_getName__() → {string}

Returns the name of this device.

Matches the name of its CA in the cloud.

Source:
Returns:

The name of this device.

Type
string

__ca_pulse__(cb0)

Internal function.

Main loop periodically called by the framework.

Parameters:
Name Type Description
cb0 cbType

A callback to continue after pulse.

Source:

__iot_error__()

Optional error handler provided by the application.

This method is null unless provided by the application.

Strategy to handle errors:

  1. Call this handler with the error

    1.1 If handler propagates error in callback, shutdown top level. If shutdown fails exit process.

    1.2 If handler does not propagate the error in callback, just abort transaction. If abort fails follow as in 1.1

  2. If this handler is null, follow as in 1.1

The type of the handler is function(Error, cbType) where:

Error: An error raised by the last processed command. cbType: A callback that will propagate the error if it wants a shutdown, or, if the error is not propagated, just abort.

Source:

__iot_loop__(cb0)

Application main method called periodically by the framework.

This method is typically customized by the application.

Parameters:
Name Type Description
cb0 cbType

A callback to continue after setup.

Source:

__iot_setup__(cb0)

Application setup method called every time the framework resets.

This method is typically customized by the application.

Parameters:
Name Type Description
cb0 cbType

A callback to continue after setup.

Source: