Global
eval
Evaluate the given String
Example
Parameter Name |
Description |
str |
String to be evaluated |
toInteger
Convert the given object to an integer value
Example
var n = toInteger('5') + 1;
Parameter Name |
Description |
object |
Object to be converted |
isNaN
Tests if the object is NaN
Example
isNaN(1); // false
isNaN('abc'); // true
Parameter Name |
Description |
number |
Object to be tested for NaNity |
meminfo
Prints platform dependent memory information
describe
Print object description to the console
Example
Parameter Name |
Description |
object |
Object to describe |
compile
Compiles a function for faster execution
Example
var f = compile(function() { return 1 + 1; });
Parameter Name |
Description |
function |
function_to_be_compiled |
objGraph
Create a DOT graph of allocated objects
Array
Array (constructor)
Array Constructor
Example
var a = new Array(5);
var b = new Array(1, 2, 3);
Para
mete
r
Name |
Desc
ript
ion |
Leng
th
or
[ite
m1,
item
2,
..] |
Numb
er
of
entr
ies
to
Allo
cate
or
comm
a
sepa
rate
d
list
of
item
s
to
push
to
the
new
arra
y |
push
The arguments are appended to the end of the array, in the order in
which they appear
Example
Parameter Name |
Description |
item1 [, item2 [, ...] ] |
object[s] to be added |
pop
The last element of the array is removed from the array and returned
Example
var a = [2, 1];
var one = a.pop();
forEach
Calls cb once for each element present in the array, in ascending order
Example
var a = [1, 2, 3];
a.forEach(function(value, k, obj) { console.log(value + ' [' + k + '] ' + ' @ ' + obj); });
Para
mete
r
Name |
Desc
ript
ion |
cb |
func
tion
that
acce
pts
thre
e
argu
ment
s:Va
lue
of
the
elem
ent,
Inde
x
of
the
elem
ent,
The
obje
ct
bein
g
trav
erse
d |
this |
[opt
iona
l]
if
prov
ided
,
used
as
the
‘thi
s’
valu
e
for
each
invo
cati
on
of
‘cb’
.
If
not
prov
ided
,
‘und
efin
ed’
is
used |
indexOf
Searches for searchElement in the elements of the array
Example
var a = [1, 2, 3];
var one = a.indexOf(2);
Parameter Name |
Description |
searchElement |
Object to search for |
fromIndex |
[optional] start search index |
join
Joins the string coversions of the elements of the array separated by
occurrences of the separator
Example
var a = [1, 2, 3];
debug.assert(a.join('-'), '1-2-3');
Parameter Name |
Description |
separator |
[optional] string. If not provided, a single comma is used |
map
Calls cb once for each element present in the array, in ascending order,
and constructs a new Array from the results
Example
var a = [1, 2, 3];
var b = a.map(function(value, k, obj) { return value + 1 });
debug.assert(b, [2, 3, 4]);
Para
mete
r
Name |
Desc
ript
ion |
cb |
func
tion
that
acce
pts
thre
e
argu
ment
s:Va
lue
of
the
elem
ent,
Inde
x
of
the
elem
ent,
The
obje
ct
bein
g
trav
erse
d |
this |
[opt
iona
l]
if
prov
ided
,
used
as
the
‘thi
s’
valu
e
for
each
invo
cati
on
of
‘cb’
.
If
not
prov
ided
,
‘und
efin
ed’
is
used |
slice
Creates a new array with elements from the specified array starting from
index ‘start’ up to index ‘end’
Example
[1, 2, 3].slice(1); // [2, 3]
Parameter Name |
Description |
start |
Element index to start from, may be undefined |
end |
Last element index (not inclusive), may be undefined |
sort
Sorts the array elements
Example
[3, 1, 2].sort(); // [1, 2, 3]
Para
mete
r
Name |
Desc
ript
ion |
comp
aref
n |
Func
tion
rece
ivin
g
(x,
y)
and
retu
rns
a
nega
tive
valu
e
if x
< y,
zero
if x
= y
or a
posi
tive
valu
e
if x
> y |
filter
Calls cb once for each element present in the array, in ascending order,
and constructs a new Array from any element for which cb returned ‘true’
Example
var a = [1, 2, 3];
var b = a.filter(function(value) { return value > 1 });
b; // [2, 3]
Para
mete
r
Name |
Desc
ript
ion |
cb |
func
tion
that
acce
pts
thre
e
argu
ment
s:Va
lue
of
the
elem
ent,
Inde
x
of
the
elem
ent,
The
obje
ct
bein
g
trav
erse
d |
this |
[opt
iona
l]
if
prov
ided
,
used
as
the
‘thi
s’
valu
e
for
each
invo
cati
on
of
‘cb’
.
If
not
prov
ided
,
‘und
efin
ed’
is
used |
concat
Concatanates a given array with a list of items. If an item is an array
itself, its members are used
Example
var a = [1, 2, 3];
var b = a.concat([4, 5, 6], 7); // [1, 2, 3, 4, 5, 6, 7]
Parameter Name |
Description |
[item1 [, item2 [, item3]]] |
optional list of items to concatanate |
String
String (constructor)
String Constructor
Example
var s = new String('hello');
Parameter Name |
Description |
String |
String |
split
Breaks a string into substrings based on occurences of ‘separator’
Example
var s = '1|2|3';
var a = s.split('|');
debug.assert(a, [ '1', '2', '3' ]);
Parameter Name |
Description |
separator |
Delimiter |
indexOf
Search for occurences of ‘searchString’ in a given string
Example
var s = 'looking for me';
var i = s.indexOf('for');
debug.assert(i, 8);
Parameter Name |
Description |
searchString |
String to search for |
substring
Creates a new string based on a subset of a given string
Example
var s = 'a big string';
var big = s.substring(2, 5);
Parameter Name |
Description |
start |
Character position to start from |
end |
Character position to end with (not including |
charAt
Creates a new string containing the character at a position
Example
var s = 'a string';
var a = s.charAt(0);
Parameter Name |
Description |
pos |
Position of character |
charCodeAt
Get the ASCII value of the character at a position
Example
var s = 'a string';
var ninty_seven = s.charCodeAt(0);
Parameter Name |
Description |
pos |
Position of character |
toLowerCase
Convert a string to lower case characters
Example
var s = 'Hello World';
s.toLowerCase(); // 'hello world'
toUpperCase
Convert a string to upper case characters
Example
var s = 'Hello World';
s.toUpperCase(); // 'HELLO WORLD'
Object
Object (constructor)
Object Constructor
toString
The object is converted to a string
Example
var a = 1;
debug.assert(a.toString(), '1');
Parameter Name |
Description |
radix |
(optional) radix to use in conversion |
on
Adds a listener for the specified event
Example
a.on('data', function() { console.log('data!'); });
Parameter Name |
Description |
event |
event to listen on |
cb |
callback function called on event |
emit
Execute each of the listeners on the event
Example
Parameter Name |
Description |
event |
event to listen on |
removeAllListeners
removes listeners on a specified event, or all events
Example
a.removeAllListeners('data');
Parameter Name |
Description |
event |
(optional) event to stop listening on |
listeners
Returns an array with listeners for the specified event
Example
Parameter Name |
Description |
event |
event for fetching listeners |
Math
sin
Compute the sine of an angle
Example
Parameter Name |
Description |
angle |
angle in radians |
asin
Compute the arc sine of a number
Example
var pi = Math.asin(1) * 2;
Parameter Name |
Description |
x |
number |
cos
Compute the cosine of an angle
Example
Parameter Name |
Description |
angle |
angle in radians |
acos
Compute the arc cosine of a number
Example
Parameter Name |
Description |
x |
number |
tan
Compute the tangent of an angle
Example
var half = Math.tan(0.463648);
Parameter Name |
Description |
angle |
angle in radians |
atan
Compute the arc tangent of a number
Example
var pi = Math.atan(1) * 4;
Parameter Name |
Description |
x |
number |
sqrt
Compute the square root of a number
Example
var three = Math.sqrt(9);
Parameter Name |
Description |
x |
number |
log
Compute the natural logarithm of a number
Example
Parameter Name |
Description |
x |
number |
exp
Compute the base-e exponent of a number
Example
Parameter Name |
Description |
x |
number |
floor
Compute the largest integral value not greater than the argument
Example
var three = Math.floor(3.5);
Parameter Name |
Description |
x |
number |
ceil
Compute the smallest integral value not less than the argument
Example
var three = Math.ceil(2.5);
Parameter Name |
Description |
x |
number |
round
Round to nearest integer, away from zero
Example
var three = Math.round(2.7);
var two = Math.round(2.2);
Parameter Name |
Description |
x |
number |
abs
Compute the absolute value of an integer
Example
Parameter Name |
Description |
x |
number |
atan2
Compute the arc tangent of two variables
Example
var pi = Math.atan2(1, 1) * 4;
Parameter Name |
Description |
x |
number |
y |
number |
pow
Power function
Example
var hundred = Math.pow(10, 2);
Parameter Name |
Description |
x |
number |
y |
number |
Netif
linkStatus
Get link status
Example
var e = new ENC28J60(SPI1, GPIO_PE3, GPIO_PF4);
console.log('link status: ' + e.linkStatus ? 'connected' : 'disconnected')
MACAddrGet
Get Interface MAC Address
Example
var e = new ENC28J60(SPI1, GPIO_PE3, GPIO_PF4);
console.log(e.MACAddrGet());
IPAddrGet
Get Interface IP Address
Example
var e = new NetifINET('eth0');
console.log(e.IPAddrGet());
onPortChange
Calls ‘cb’ when link state has changed
Example
var e = new ENC28J60(SPI1, GPIO_PE3, GPIO_PF4);
e.onPortChange(function() { console.log('port state changed!'); });
Parameter Name |
Description |
cb |
callback function called when link status has changed |
IPConnect
Obtain IP Address
Example
var e = new ENC28J60(SPI1, GPIO_PE3, GPIO_PF4);
e.IPConnect();
Parameter Name |
Description |
cb (optional) |
callback function called on IP address availablity |
IPDisconnect
Release IP Address
Example
var e = new ENC28J60(SPI1, GPIO_PE3, GPIO_PF4);
e.IPDisconnect();
TCPConnect
Connect to a TCP IP:PORT
Example
var e = new NetifINET();
e.TCPIPConnect('192.168.1.10', 80, function() { console.log('connected'); });
Parameter Name |
Description |
ip |
IP address to connect to |
port |
tcp port to connect to |
cb |
callback function called on TCP connectivity |
TCPDisconnect
Release TCP connection
Example
var e = new NetifINET();
e.TCPIPConnect('192.168.1.10', 80, function() { console.log('connected'); e.TCPDisconnect() });
onTCPData
Calls ‘cb’ when TCP data is available
Example
var e = new NetifINET();
e.onTCPData(function() { console.log('TCP data ready!'); });
Para
mete
r
Name |
Desc
ript
ion |
cb |
call
back
func
tion
call
ed
when
TCP
data
is
avai
labl
e.
Empt
y
call
back
remo
ves
the
list
ener |
onTCPDisconnect
Calls ‘cb’ when TCP stream is disconnected
Example
var e = new NetifINET();
e.onTCPDisconnect(function() { console.log('TCP disconnected!'); });
Para
mete
r
Name |
Desc
ript
ion |
cb |
call
back
func
tion
call
ed
when
TCP
stre
am
is
disc
onne
cted
.
Empt
y
call
back
remo
ves
the
list
ener |
TCPWrite
Writes data to the TCP socket
Example
var e = new NetifINET();
e.TCPIPConnect('192.168.1.10', 80, function() { e.TCPWrite('GET / HTTP 1.0
'); });
Parameter Name |
Description |
data |
Data (byte/array/string/typed array) to be sent |
TCPRead
Reads data from the TCP socket
Example
var e = new NetifINET();
e.onTCPData(function() { console.log(n.TCPRead()); });
e.TCPIPConnect('192.168.1.10', 80, function() { e.TCPWrite('GET / HTTP 1.0
'); });
ENC28J60 (constructor)
ENC28J60 Ethernet Constructor
Example
var enc = new ENC28J60(SPI0, GPIO_PF0, GPIO_PF1);
console.log('link status: ' + enc.linkStatus() ? 'connected' : 'disconnected');
Parameter Name |
Description |
SPI port |
SPI Port |
CS |
SPI Chip Select Pin |
Interrupt |
Interrupt Pin |
ESP8266 (constructor)
ESP8266 Wi-Fi Constructor
Example
var esp = new ESP8266(function() {
esp.IPConnect(function() { console.log('connected'); });
}, UART4);
Parameter Name |
Description |
cb |
Callback to be called when device is ready |
Serial port (optional) |
Serial Port |
StellarisEth (constructor)
Stellaris Ethernet Object Constructor
Example
var enc = new StellarisEth();
console.log('link status: ' + enc.linkStatus() ? 'connected' : 'disconnected');
NetifINET (constructor)
INET Network Interface Object Constructor
Example
var n = new NetifINET('eth0');
console.log('link status: ' + n.linkStatus() ? 'connected' : 'disconnected');
Parameter Name |
Description |
Net Device |
Network Interface Name |
LinuxPacketEth (constructor)
Linux Packet Ethernet Object Constructor
Example
var n = new LinuxPacketEth('eth0');
console.log('link status: ' + n.linkStatus() ? 'connected' : 'disconnected');
Parameter Name |
Description |
Net Device |
Linux Network Interface Name |
ESP8266_WIFI (constructor)
ESP8266 Wi-Fi Constructor
Example
var esp = new ESP8266_WIFI();
esp.IPConnect();
GPIO
digitalWrite
Set the digital value of a GPIO or a number of GPIOs
Example
digitalWrite(GPIO_PF2, true); /* Turn on PF2 */
digitalWrite([GPIO_PF1, GPIO_PF2, GPIO_PF3], 0x5); /* Turn on PF1 & PF3 */
Para
mete
r
Name |
Desc
ript
ion |
pin[
s] |
Sing
le
GPIO
ID
or
arra
y
of
GPIO
IDs |
valu
e |
Bool
ean
for
a
sing
le
GPIO
In
case
of
an
arra
y,
valu
e
is
cons
ider
ed
an
inte
ger
wher
e
thef
irst
arra
y
elem
ent
maps
to
the
MSB |
digitalPulse
Create a digital pulse on a GPIO pin for a given period
Example
digitalPulse(GPIO_PF2, true, 0.1);
Parameter Name |
Description |
pin |
GPIO pin ID |
value |
Boolean |
ms |
Pulse period in milliseconds |
digitalRead
Read the digital state of a GPIO pin or a number of pins
Example
var state = digitalRead(GPIO_PF2);
var a = digitalRead([GPIO_PF0, GPIO_PF1, GPIO_PF2
Parameter Name |
Description |
pin[s] |
GPIO pin ID or array of GPIO pin IDs |
analogWrite
Set the analog value of a GPIO pin
Example
analogWrite(GPIO_PF2, 0.5);
Parameter Name |
Description |
pin |
GPIO pin ID |
value |
Floating point number with range [0-1] |
options (Optional) |
Object: { freq : } |
analogRead
Read the analog value of a GPIO pin
Example
var f = analogRead(GPIO_PF2);
Parameter Name |
Description |
pin |
GPIO pin ID |
setWatch
Calls a function whenever the GPIO pin changes state
Example
setWatch(function() { console.log('button changed state'); }, GPIO_PF0);
Para
mete
r
Name |
Desc
ript
ion |
cb |
call
back
func
tion
:The
func
tion
may
rece
ive
an
obje
ct
of
type
:{
time
stam
p:
in
seco
nds,
stat
e:
curr
ent
pin
stat
e} |
pin |
GPIO
pin
ID |
opti
ons |
opti
onal
opti
ons
obje
ct
of
type
{
qlen
:
int
//
numb
er
of
pend
ing
samp
les
for
proc
essi
ng
smal
ler
than
128,
must
be
powe
r
of
2.
Defa
ult
=1 } |