API Docs for:
Show:

Device Class

Defined in: app.js:6357

You can create an object of this class for each device that the app connects to.

Constructor

Device

()

Defined in app.js:6357

Methods

addBatchCommand

(
  • format
  • pin
  • value
  • duration
)
... Object

Defined in app.js:6455

Add a command to the batch, and send after a timeout This allows multiple commands issued in close succession to be batched up, reducing dealys in multiple API calls

Parameters:

  • format ...String

    Describe...

  • pin ...String

    Describe...

  • value ...String

    Describe...

  • duration ...String

    Describe...

Returns:

... Object:

Returns this.

alertPinValue

(
  • pin
  • format
)
... Object

Defined in app.js:6486

Shows a screen alert message with the value of the pin.

Parameters:

  • pin ...String

    Describe...

  • format ...String

    Optional format can be a (for analog) or d (for digital) value (Default: d).

Returns:

... Object:

Returns this.

analogRead

(
  • pin
  • callback
)
... Object

Defined in app.js:6515

...

Parameters:

  • pin ...String

    Describe...

  • callback ...String

    Describe...

Returns:

... Object:

Returns this.

analogWrite

(
  • pin
  • state
  • noBatch
)

Defined in app.js:6537

Send an API call to the device to write an analog value to pin. Optionally If useBatchCommands is true the command is cached and sent after a short delay in a batch

Parameters:

  • pin ...String

    Describe...

  • state ...String

    Describe...

  • noBatch ...String

    Describe...

attachServos

(
  • attachArray
)
... Object

Defined in app.js:6566

Attach servos to pins

Parameters:

  • attachArray ...String

    attachArray is a two-dimensional array [x][2].

Returns:

... Object:

Returns this.

Example:

For each x, the array has the servo number (e.g. 1) and the pin number (e.g. 7)

callFunction

() ... Object

Defined in app.js:7400

...

Returns:

... Object:

Returns this.

callFunction

(
  • called_function
  • parameters
  • onSuccess
  • onFail
)
... Object

Defined in app.js:6641

Calls a function defined on the device

Parameters:

  • called_function ...String

    Describe...

  • parameters ...String

    Describe...

  • onSuccess ...String

    Describe...

  • onFail ...String

    Describe...

Returns:

... Object:

Returns this.

cancelPending

(
  • method
  • pin
  • state
)
... Object

Defined in app.js:6679

Cancels the method,pin,state combination from the pending methods.

Parameters:

  • method ...String

    Describe...

  • pin ...String

    Describe...

  • state ...String

    Describe...

Returns:

... Object:

Returns this.

configureAddress

() ... Object

Defined in app.js:6702

Configures which address to use for calls to this device. Priority for which address to use is given in the following order:

  • 192.168.4.1 for local deviceID when using softAP
  • localIP
  • localIPFromRemote
  • The default cloud webservice

Returns:

... Object:

Returns this.

configureLayout

() ... Object

Defined in app.js:6748

configures the board layout using the IoT Builder layout settings Using a layout makes it much simpler for novice users as they make use of the IoT Builder to configure the board. Using a layout is optional. The app can simply set pins using pin numbers directly.

Returns:

... Object:

Returns this.

connect

(
  • onConnect
  • onFail
)
... Object

Defined in app.js:6774

Connects to the device.

Parameters:

  • onConnect ...String

    Optional function onConnect called once connected.

  • onFail ...String

    Optionalfunction onFail called if connection fails.

Returns:

... Object:

Returns this.

digitalRead

(
  • pin
  • callback
)
... Object

Defined in app.js:6798

...

Parameters:

  • pin ...String

    Reads the digital value of pin.

  • callback ...String

    Optional callback(data) function is called passing the data from the Response.

Returns:

... Object:

Returns this.

digitalWrite

(
  • pin
  • state
  • noBatch
)
... Object

Defined in app.js:6823

...

Parameters:

  • pin ...String

    Sets the digital output on pin to `state.

  • state ...String

    state must be either 1 or 0.

  • noBatch ...String

    Optionally If useBatchCommands is true the command is cached and sent after a short delay in a batch.

Returns:

... Object:

Returns this.

fade

(
  • pin
  • direction
  • duration
  • noBgChange
)
... Object

Defined in app.js:6866

Fade pin on or off, depending on direction.

Parameters:

  • pin ...String

    Optional pin is the pin number (Default: 5, except on RaspberryPi: 7).

  • direction ...String

    If direction is "on" or 1, the pin will fade from 0 to 100% . If direction is "out", "off" or 0, the pin will fade from 100% to 0. Default direction is 1

  • duration ...String

    Optional duration determines how long the fade should take (Default: 5 seconds).

  • noBgChange ...String

    Optional noBgChange ensures that the Screen BackgroundColor is not changed during blink.

Returns:

... Object:

Returns this.

getInfo

(
  • data
)
... Object

Defined in app.js:7724

...

Parameters:

  • data ...String

    Describe...

Returns:

... Object:

Returns this.

getInfo

(
  • onSuccess
  • address
  • onFail
)
... Object

Defined in app.js:6913

Queries the device to get basic info

Parameters:

  • onSuccess ...String

    onSuccess is the function run when the data is returned from the device (arguments: data, textStatus, jqXHR).

  • address ...String

    Optional address can be passed in, the default address is this.address.

  • onFail ...String

    Optional onFail is the function called when the connection fails (arguments: a, textStatus, b).

Returns:

... Object:

Returns this.

getLayout

(
  • callback
)
... Object

Defined in app.js:6965

...

Parameters:

  • callback ...String

    Describe...

Returns:

... Object:

Returns this.

getLEDPin

() ... Object

Defined in app.js:6991

...

Returns:

... Object:

Returns the pinNumber for the built-in LED for this device.

getLocalIPFromRemote

()

Defined in app.js:7020

Try to get the LocalIP from the Remote address;

getPin

(
  • pinNameOrNumber
)
... Object

Defined in app.js:7043

Redundant function

Parameters:

  • pinNameOrNumber ...String

    Describe...

Returns:

... Object:

Returns this.getPinValue()

getPinFormat

(
  • pinNumber
)
... Object

Defined in app.js:7059

...

Parameters:

  • pinNumber ...String

    Describe...

Returns:

... Object:

Returns this.

getPinMode

(
  • pinNumber
)
... Object

Defined in app.js:7072

...

Parameters:

  • pinNumber ...String

    Describe...

Returns:

... Object:

Returns this.

getPinValue

(
  • pinNameOrNumber
)
... Object

Defined in app.js:7085

Returns the value of pin pinNameOrNumber

Parameters:

  • pinNameOrNumber ...String

    If a name is passed in, then this device must have a layout with a pin named accordingly. If polling has not started, this function starts polling the pin values.

Returns:

... Object:

Returns this.

getVariable

(
  • variable
  • callback
)

Defined in app.js:7141

...

Parameters:

  • variable ...String

    Describe...

  • callback ...String

    Describe...

init

() ... Object

Defined in app.js:6418

Initialize the object

Returns:

... Object:

Returns this.

isPending

(
  • method
  • pin
  • state
)
... Object

Defined in app.js:7159

...

Parameters:

  • method ...String

    Describe...

  • pin ...String

    Describe...

  • state ...String

    Describe...

Returns:

... Object:

Returns true if the method,pin,state combination is pending.

motionDriving

(
  • state
  • settings
)
... Object

Defined in app.js:7179

Drive the car using motion control (accelerometer)

Parameters:

  • state ...String

    (Optional) State indicates if you are turning Motion Driving on (1) or off (0), Default: 1.

  • settings ...String

    (Optional) Settings passes an object of settings.

Returns:

... Object:

Returns this.

motionDrivingLoop

()

Defined in app.js:7207

run the motion driving process and keep looping calibrate PWM run logo command

motionDrivingSettings

()

Defined in app.js:7231

Adjusts the settings for motion driving based on the current device accelration properties

poll

() ... Object

Defined in app.js:7286

Starts the polling for this device. Repeatedly updates the pin values for tied pins

Returns:

... Object:

Returns this.

pollRepeat

() ... Object

Defined in app.js:7307

Runs on a loop, Reads pin values and updates tied variables

Returns:

... Object:

Returns null

readPins

(
  • onSuccess
  • onFail
)
... Object

Defined in app.js:7328

Reads all the pins and updates the device info

Parameters:

  • onSuccess ...String

    Optional onSuccess called once the info has been updated.

  • onFail ...String

    Optional onFail called if the info can't be updated.

Returns:

... Object:

Returns this.

sendCommands

(
  • cmds
  • callback
)

Defined in app.js:7363

Sends the next batch of commands

Parameters:

  • cmds ...String

    Optional cmds arary holds the commands to send, otherwise uses this.ioBatchCommands. cmds expect an array of command arrays, where each command array contains 4 items: [format,pin,value,duration].

  • callback ...String

    Optional callback is the callback function - this might be called multiple times if the commands are sent in multiple batches.

setLayout

(
  • data
)
... Object

Defined in app.js:7420

sets the layout to data (expecting a JSON object)

Parameters:

  • data ...String

    Describe...

Returns:

... Object:

Returns this.

setLED

(
  • val
)
... Object

Defined in app.js:7437

Sets the built-in LED to val

Parameters:

  • val ...String

    val can be 1/0 or ON/OFF or true/false. NB: Setting the LED "ON" in some cases pulls the Pin down (i.e. "OFF")!.

Returns:

... Object:

Returns this.

setMotorDriver

(
  • type
  • callback
)
... Object

Defined in app.js:7473

Sets the Motor Driver to type;

Parameters:

  • type ...String

    Describe...

  • callback ...String

    Describe...

Returns:

... Object:

Returns this.

Example:

Options are: 
   0 (default) Motor Shield
   1 L298N
   2 L9110

setPending

(
  • method
  • pin
  • state
)
... Object

Defined in app.js:7500

Sets a flag to indicate that a method,pin,state combination is pending (i.e. the AJAX request is running) This is used to stop duplicate requests being sent continuously thereby overloading the device

Parameters:

  • method ...String

    method must be one of:.

    • analogRead
    • analogWrite
    • digitalRead
    • digitalWrite
  • pin ...String

    Create a key using pin_state.

  • state ...String

    Describe...

Returns:

... Object:

Returns this.

setPin

(
  • pinNameOrNumber
  • val
)
... Object

Defined in app.js:7533

Sets the pin number pinNameOrNumber to val

Parameters:

  • pinNameOrNumber ...String

    Presume a pin number passed in.

  • val ...String

    Describe...

Returns:

... Object:

Returns this.

setPinFormat

(
  • pinNumber
  • format
)
... Object

Defined in app.js:7599

...

Parameters:

  • pinNumber ...String

    Sets the format of pinNumber to format.

  • format ...String

    format must be either d for digital or a for analog.

Returns:

... Object:

Returns this.

setPinMode

(
  • pin
  • state
)
... Object

Defined in app.js:7617

...

Parameters:

  • pin ...String

    Set the mode of pin to state.

  • state ...String

    state must be either i for input or o for output.

Returns:

... Object:

Returns this.

setRGB

(
  • color
  • pins
)
... Object

Defined in app.js:7655

Sets an RGB LED to color

Parameters:

  • color ...String

    color can be a HEX color or an object with properties r,g,b specifying a value 0-255.

  • pins ...String

    Optional pins specifies the pins to use, default is 5,6,7 for r,g,b. pins is an object with properties r,g,b specifying the pin numbers.

Returns:

... Object:

Returns this.

testLocalIP

(
  • fromRemote
)
... Object

Defined in app.js:7688

Tests this.local_ip to determine if the app can use it instead of the Remote address

Parameters:

  • fromRemote ...String

    Optional: If fromRemote is true it will test this.local_ipFromRemote.

Returns:

... Object:

Returns this.

tie

(
  • pinNameOrNumber
  • variable
)
... Object

Defined in app.js:7752

...

Parameters:

  • pinNameOrNumber ...String

    Ties the pin pinNameOrNumber to a variable. presume a pin number passed in.

  • variable ...String

    The variable is updated every time the pin is polled.

Returns:

... Object:

Returns this.

tieAllPinsToVariables

() ... Object

Defined in app.js:7823

Ties all input pins to variables by the same name Requires a layout to be specified for the device (to determine which pins are inputs) Allows for easy moniotring of pins: simply create form fields (variables) with the same names as the pins Also allows you to name variables using the pinNumber, but with multiple connected devices using pinNumber will cause conflicts.

Returns:

... Object:

Returns this.

togglePin

(
  • pinNameOrNumber
)
... Object

Defined in app.js:7858

...

Parameters:

  • pinNameOrNumber ...String

    Describe...

Returns:

... Object:

Returns null

toString.

()

Defined in app.js:7880

...

updatedTiedVariables

(
  • pinNumber
)
... Object

Defined in app.js:8012

Update all variables tied to pins with the latest pin value

Parameters:

  • pinNumber ...String

    Describe...

Returns:

... Object:

Returns this.

updateInfo

(
  • data
)
... Object

Defined in app.js:7897

Update the basic Info of the device using data

Parameters:

  • data ...String

    Describe...

Returns:

... Object:

Returns this.

updateProperties

(
  • props
)
... Object

Defined in app.js:7948

...

Parameters:

  • props ...String

    Describe...

Returns:

... Object:

Returns this.

updateRemoteAddress

() ... Object

Defined in app.js:7996

...

Returns:

... Object:

Returns this.