Repository URL to install this package:
|
Version:
8.2.2 ▾
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=windows-1252">
<TITLE>Python API</TITLE>
<META NAME="GENERATOR" CONTENT="OpenOffice 4.1.0 (Win32)">
<META NAME="CREATED" CONTENT="0;0">
<META NAME="CHANGEDBY" CONTENT="Alex Bilyk">
<META NAME="CHANGED" CONTENT="20180711;23140292">
<LINK rel="stylesheet" type="text/css" href="styleNormal.css">
</HEAD>
<BODY LANG="en-US" TEXT="#000000" LINK="#1152b1" BGCOLOR="#fdf1af" DIR="LTR">
<div id="main-content" tabindex="0">
<P CLASS="mainheading1">Python API</P></div>
<HR>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-ProgramStructureandEvents"></A>
Program Structure and Events</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=N/A"></A>Package =
N/A</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>cleanUp()</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>If defined, this function is called once just before the
program stops.</P>
</TD>
<TD>
<PRE CLASS="western">def cleanUp():
print("program is stopping.")</PRE>
</TD>
</TR>
<TR>
<TD>
<P>mouseEvent(pressed, x, y, firstPress)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>If defined, this function is called when the user clicks and/or
moves the mouse on the workspace icon of this device.</P>
<UL>
<LI><P STYLE="margin-bottom: 0in">pressed - a boolean indicating
whether the left mouse button is pressed down
</P>
<LI><P STYLE="margin-bottom: 0in">x - the x coordinate (in
pixels) of the mouse relative to the workspace icon's top left
corner
</P>
<LI><P STYLE="margin-bottom: 0in">y - the y coordinate (in
pixels) of the mouse relative to the workspace icon's top left
corner
</P>
<LI><P>firstPress - a boolean indicating whether the left mouse
button is the first time being pressed down after the last call
to this function; pressed is true when the mouse button is
pressed and moved, but firstPress is true only when the mouse
button is first pressed but not when moved.
</P>
</UL>
<P> </P>
</TD>
<TD>
<PRE CLASS="western">def mouseEvent(pressed, x, y, firstPress):
if firstPress:
doSomething()</PRE>
</TD>
</TR>
<TR>
<TD>
<P>measurementSystemChangeEvent()</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>If defined, this function is called when the user changes the
measurement system between Metric and Imperial in Preferences. Use
Options.isUsingMetric() in the options package to get the current
setting.</P>
</TD>
<TD>
<PRE CLASS="western">from options import *
def measurementSystemChangeEvent():
METRIC = Options.isUsingMetric()
unit = "C" if METRIC else "F"
refresh()</PRE>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-DigitalI/O"></A>Digital
I/O </H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=gpio"></A>Package =
gpio</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>pinMode(slot, mode) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Set a digital slot to INPUT or OUTPUT. </P>
</TD>
<TD>
<P>pinMode(1, OUT)</P>
<P>pinMode(2, IN)</P>
</TD>
</TR>
<TR>
<TD>
<P>digitalRead(slot) </P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Reads from a digital slot, returns HIGH or LOW. </P>
</TD>
<TD>
<P>val = digitalRead(1) </P>
</TD>
</TR>
<TR>
<TD>
<P>digitalWrite(slot, value) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Writes to a digital slot with HIGH or LOW. </P>
</TD>
<TD>
<P>digitalWrite(1, HIGH) </P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-AnalogI/O"></A>Analog I/O </H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=gpio.1"></A>Package
= gpio</H3>
</TD>
</TR>
<TR>
<TD>
<P>Function </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>analogRead(slot) </P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Reads from an analog slot, returns 0 to 1023. </P>
</TD>
<TD>
<P>val = analogRead(A1)</P>
</TD>
</TR>
<TR>
<TD>
<P>analogWrite(slot, value) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Writes a PWM wave to a digital slot, from 0 to 255. </P>
</TD>
<TD>
<P>analogWrite(A1, 128)</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-CustomI/O"></A>Custom I/O </H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=gpio.2"></A>Package
= gpio</H3>
</TD>
</TR>
<TR>
<TD>
<P>Function </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P>Description </P>
</TD>
<TD>
<P>Example </P>
</TD>
</TR>
<TR>
<TD>
<P>customRead(slot) </P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Reads from an custom slot, returns a String</P>
</TD>
<TD>
<P>val = customRead(1)</P>
</TD>
</TR>
<TR>
<TD>
<P>customWrite(slot, value) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Writes a string to a digital slot. You can use customRead
directly from the other side</P>
</TD>
<TD>
<P>customWrite(1, "hello")</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-InputInterrupts/Events"></A>
Input Interrupts/Events </H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=gpio.3"></A>Package
= gpio</H3>
</TD>
</TR>
<TR>
<TD>
<P>Function </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P>Description </P>
</TD>
<TD>
<P>Example </P>
</TD>
</TR>
<TR>
<TD>
<P>add_event_detect(slot, callback) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Registers a function to be called when the input of a slot
changes.</P>
<P>This works for analog, digital and custom inputs. Whenever the
input changes, the callback is called.</P>
<P>Only one function is registered per slot. Calling this a second
time for the same slot will remove the first callback.</P>
</TD>
<TD>
<PRE CLASS="western">def detect():
input = analogRead(0)
# do something
add_event_detect(0, detect)</PRE>
</TD>
</TR>
<TR>
<TD>
<P>remove_event_detect(slot)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Unregisters the slot for input changes.</P>
</TD>
<TD>
<P>remove_event_detect(0)</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-Time"></A>Time</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=time"></A>Package =
time</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>delay(tmsec)
</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Pauses the program for tmsec milliseconds. Value of 0 has the
meaning of sleeping until the next execution cycle, as determined
by the run-time.</P>
</TD>
<TD>
<P>delay(1700) same as sleep(1.7)</P>
</TD>
</TR>
<TR>
<TD>
<P>sleep(tsec)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Pauses the program for tsec seconds. Fractional seconds values
for tsec are acceptable. Value of 0 has the meaning of sleeping
until the next execution cycle, as determined by the run-time.</P>
</TD>
<TD>
<P>sleep(0.25)same as delay(250)</P>
</TD>
</TR>
<TR>
<TD>
<P>uptime()</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Returns the time since the device was started in seconds.</P>
</TD>
<TD>
<P>print(uptime())</P>
</TD>
</TR>
<tr>
<td>gmtime([secs])</td>
<td>struct_time</td>
<td>Converts a time in seconds since epoch to struct_time in UTC. If secs is not provided, it uses the current
time as returned by time().</td>
<td>print(gmtime())</td>
</tr>
<tr>
<td>localtime([secs])</td>
<td>struct_time</td>
<td>Converts a time in seconds since epoch to struct_time in local time. If secs is not provided, it uses the
current time as returned by time().</td>
<td>print(localtime())</td>
</tr>
<tr>
<td>asctime([time])</td>
<td>string</td>
<td>Converts a time in struct_time to a string in the form of
<span class="pre" style="color: rgb(0,0,0);">'Sun</span>
<span style="color: rgb(0,0,0);"> </span>
<span class="pre" style="color: rgb(0,0,0);">Jun</span>
<span style="color: rgb(0,0,0);"> </span>
<span class="pre" style="color: rgb(0,0,0);">20</span>
<span style="color: rgb(0,0,0);"> </span>
<span class="pre" style="color: rgb(0,0,0);">23:21:05 </span>
<span class="pre" style="color: rgb(0,0,0);">1993'. If time is not provided, it uses the current time as returned by localtime().</span>
</td>
<td>print(asctime())</td>
</tr>
<tr>
<td>ctime([secs])</td>
<td>string</td>
<td>Converts a time in seconds since epoch to a string in the form of
<span class="pre" style="color: rgb(0,0,0);">'Sun</span>
<span style="color: rgb(0,0,0);"> </span>
<span class="pre" style="color: rgb(0,0,0);">Jun</span>
<span style="color: rgb(0,0,0);"> </span>
<span class="pre" style="color: rgb(0,0,0);">20</span>
<span style="color: rgb(0,0,0);"> </span>
<span class="pre" style="color: rgb(0,0,0);">23:21:05 </span>
<span class="pre" style="color: rgb(0,0,0);">1993'. If secs is not provided, it uses the current time as returned by time().</span>
</td>
<td>print(ctime())</td>
</tr>
<tr>
<td>mktime(time)</td>
<td>int</td>
<td>Converts a time in struct_time to a time in seconds since epoch.</td>
<td>mktime(localtime())</td>
</tr>
<tr>
<td>timezone</td>
<td>int</td>
<td>
<span style="color: rgb(0,0,0);">The local (non-DST) timezone's offset in seconds west of UTC.</span>
</td>
<td>print(timezone)</td>
</tr>
<tr>
<td>altzone</td>
<td>int</td>
<td>The local (DST) timezone's offset in seconds west of UTC.</td>
<td>print(altzone)</td>
</tr>
<tr>
<td>tzname</td>
<td>tuple(string, string)</td>
<td>A tuple of two strings with the first being the local non-DST timezone name, and second being the local DST
timezone name.</td>
<td>print(tzname)</td>
</tr>
<tr>
<td>daylight</td>
<td>int</td>
<td>Nonzero if in a DST timezone.</td>
<td>print(daylight)</td>
</tr>
<tr>
<td>accept2dyear</td>
<td>bool</td>
<td>Whether two digit year will be accepted.</td>
<td>print(accept2dyear)</td>
</tr>
<tr>
<td>
<div>strftime(format[, time])</div>
</td>
<td>string</td>
<td>
<p>Converts a time in struct_time to a string in the format.</p>
<p>Format directives:</p>
<ul>
<li>
<p>%a - Locale's abbreviated weekday name.
<br>%A - Locale's full weekday name.
<br>%b - Locale's abbreviated month name.
<br>%B - Locale's full month name.
<br>%c - Locale's appropriate date and time representation.
<br>%d - Day of the month as a decimal number [01,31].
<br>%H - Hour (24-hour clock) as a decimal number [00,23].
<br>%I - Hour (12-hour clock) as a decimal number [01,12].
<br>%j - Day of the year as a decimal number [001,366].
<br>%m - Month as a decimal number [01,12].
<br>%M - Minute as a decimal number [00,59].
<br>%p - Locale's equivalent of either AM or PM.
<br>%S - Second as a decimal number [00,61].
<br>%U - Week number of the year (Sunday as the first day of the week) as a decimal number [00,53].
All days in a new year preceding the first Sunday are considered to be in week 0.
<br>%w - Weekday as a decimal number [0(Sunday),6].
<br>%W - Week number of the year (Monday as the first day of the week) as a decimal number [00,53].
All days in a new year preceding the first Monday are considered to be in week 0.
<br>%x - Locale's appropriate date representation.
<br>%X - Locale's appropriate time representation.
<br>%y - Year without century as a decimal number [00,99].
<br>%Y - Year with century as a decimal number.
<br>%Z - Time zone name (no characters if no time zone exists).
<br>%% - A literal '%' character.</p>
</li>
</ul>
</td>
<td>print(strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))</td>
</tr>
<tr>
<td>
<span style="color: rgb(0,0,0);">strptime(string[, format])</span>
</td>
<td>struct_time</td>
<td>Converts a time in string format to a time in struct_time. The format parameter uses the same directives
as those used by strftime(); it defaults to "%a %b %d %H:%M:%S %Y" which matches the formatting returned
by ctime().</td>
<td>print(strptime("30 Nov 00", "%d %b %y"))</td>
</tr>
<tr>
<td>
<br>
</td>
<td>
<br>
</td>
<td>
<br>
</td>
<td>
<br>
</td>
</tr>
<tr>
<td>
<strong>struct_time class</strong>
</td>
<td>
<br>
</td>
<td>
<br>
</td>
<td>
<br>
</td>
</tr>
<tr>
<td>tm_year</td>
<td>int</td>
<td>year, for example, 1993</td>
<td>
<br>
</td>
</tr>
<tr>
<td>tm_mon</td>
<td>
<span>int</span>
</td>
<td>month of year, range [1, 12]</td>
<td>
<br>
</td>
</tr>
<tr>
<td>tm_mday</td>
<td>
<span>int</span>
</td>
<td>day of month, range [1, 31]</td>
<td>
<br>
</td>
</tr>
<tr>
<td>tm_hour</td>
<td>
<span>int</span>
</td>
<td>hours, range [0, 23]</td>
<td>
<br>
</td>
</tr>
<tr>
<td>tm_min</td>
<td>
<span>int</span>
</td>
<td>minutes, range [0, 59]</td>
<td>
<br>
</td>
</tr>
<tr>
<td>tm_sec</td>
<td>
<span>int</span>
</td>
<td>seconds, range [0, 61]</td>
<td>
<br>
</td>
</tr>
<tr>
<td>tm_wday</td>
<td>
<span>int</span>
</td>
<td>day of week, range [0, 6], Monday is 0</td>
<td>
<br>
</td>
</tr>
<tr>
<td>tm_yday</td>
<td>
<span>int</span>
</td>
<td>day of year, range [1, 366]</td>
<td>
<br>
</td>
</tr>
<tr>
<td>tm_isdst</td>
<td>
<span>int</span>
</td>
<td>1 if summer time is in effect, 0 if not, and -1 if unknown</td>
<td>
<br>
</td>
</tr>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-BasicNetworking"></A>Basic
Networking </H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=networking"></A>Package
= networking</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>localIP() </P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the local IP. </P>
</TD>
<TD>
<P>ip = localIP()</P>
</TD>
</TR>
<TR>
<TD>
<P>subnetMask() </P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the subnet mask. </P>
</TD>
<TD>
<P>mask = subnetMask()</P>
</TD>
</TR>
<TR>
<TD>
<P>gatewayIP() </P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the gateway IP. </P>
</TD>
<TD>
<P>gateway = gatewayIP() </P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-HTTPClient"></A>HTTP Client</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=http"></A>Package =
http</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>HTTPClient() </P>
</TD>
<TD>
<P>HTTPClient</P>
</TD>
<TD>
<P>Creates a HTTP Client. </P>
</TD>
<TD>
<P>http = HTTPClient()</P>
</TD>
</TR>
<TR>
<TD>
<P>open(url) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Gets an URL. </P>
</TD>
<TD>
<P>http.open(“<A HREF="http://www.cisco.com/">http://www.cisco.com</A>”)</P>
</TD>
</TR>
<TR>
<TD>
<P>stop() </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Stops the request. </P>
</TD>
<TD>
<P>http.stop()</P>
</TD>
</TR>
<TR>
<TD>
<P>onDone(callback) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for when the request is done. </P>
</TD>
<TD>
<P>def onHTTPDone(status, data): <BR>print(data)</P>
<P>...</P>
<P>http.onDone(onHTTPDone)</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-HTTPServer(SBConly)"></A>HTTP Server (SBC
only)</H3>
</TD>
<TD COLSPAN=3>
<P> Package = http</P>
</TD>
</TR>
<TR>
<TD>
<P>Function</P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P>Description</P>
</TD>
<TD>
<P>Example</P>
</TD>
</TR>
<TR>
<TD>
<P>route(path, callback);</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets up a route for path and calls callback when it is
requested. Routes also support wildcards using *.</P>
</TD>
<TD>
<P>def onRouteHello(url,
response):<BR>response.send("hello")<BR>HTTPServer.route("/hello", onRouteHello)</P>
<P><BR><BR>
</P>
<P>def onRouteAll(url,
response):<BR>response.send("world")<BR>HTTPServer.route("/*", onRouteAll)</P>
<P STYLE="margin-bottom: 0in">
</P>
<P><BR>
</P>
</TD>
</TR>
<TR>
<TD>
<P>start(port) </P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Starts listening on port. </P>
</TD>
<TD>
<P>HTTPServer.start(80)</P>
</TD>
</TR>
<TR>
<TD>
<P>stop() </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Stops listening. </P>
</TD>
<TD>
<P>HTTPServer.stop()</P>
</TD>
</TR>
<TR>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Response class</STRONG></P>
</TD>
<TD>
<P> </P>
</TD>
<TD>
<P>Passed into the HTTPServer route handler.</P>
</TD>
<TD>
<P> </P>
</TD>
</TR>
<TR>
<TD>
<P>send(content)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sends content back as response.</P>
</TD>
<TD>
<P>response.send("hello")</P>
</TD>
</TR>
<TR>
<TD>
<P>setContentType(type)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the content type in the response.</P>
</TD>
<TD>
<P>response.setContentType("text/plain")</P>
</TD>
</TR>
<TR>
<TD>
<P>sendFile(filePath)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sends a file back as response. The file path is in the device's
file manager, not relative to the source code of the current
project/script.</P>
</TD>
<TD>
<P>response.sendFile("/test.txt")</P>
</TD>
</TR>
<TR>
<TD>
<P>sendNotFound()</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sends a file not found as response.</P>
</TD>
<TD>
<P>response.sendNotFound()</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-Email"></A>Email</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=email"></A>Package
= email</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>setup(email, server, username, password) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets up the email client to be used. </P>
</TD>
<TD>
<P>EmailClient.setup(“user@cisco.com”, "cisco.com",
"username", "password")</P>
</TD>
</TR>
<TR>
<TD>
<P>send(address, subject, body) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sends an email. </P>
</TD>
<TD>
<P>EmailClient.send("pt@cisco.com", "subject",
"body)</P>
</TD>
</TR>
<TR>
<TD>
<P>receive() </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Receives emails. </P>
</TD>
<TD>
<P>EmailClient.receive()</P>
</TD>
</TR>
<TR>
<TD>
<P>onSend(callback)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for when sending an email is done. </P>
</TD>
<TD>
<P>def onEmailSend(success): <BR>print(success)</P>
<P>...</P>
<P>EmailClient.onSend(onEmailSend) </P>
</TD>
</TR>
<TR>
<TD>
<P>onReceive(callback) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for when emails are received. </P>
</TD>
<TD>
<P STYLE="margin-bottom: 0in">def onEmailReceive(sender,
subject, body): <BR>print(body)</P>
<P STYLE="margin-bottom: 0in">...</P>
<P>EmailClient.onReceive(onEmailReceive)</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-TCP"></A>TCP</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=tcp"></A>Package =
tcp</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>TCPClient() </P>
</TD>
<TD>
<P>TCPClient</P>
</TD>
<TD>
<P>Creates a TCP Client. </P>
</TD>
<TD>
<P>client = TCPClient()</P>
</TD>
</TR>
<TR>
<TD>
<P>connect(ip, port) </P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Connects to ip and port. </P>
</TD>
<TD>
<P>client.connect("1.1.1.1", 2000)</P>
</TD>
</TR>
<TR>
<TD>
<P>connected()</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Returns true if connected</P>
</TD>
<TD>
<P>client.connected()</P>
</TD>
</TR>
<TR>
<TD>
<P>close() </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Disconnects. </P>
</TD>
<TD>
<P>client.close()</P>
</TD>
</TR>
<TR>
<TD>
<P>state() </P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the state of the connection. </P>
</TD>
<TD>
<P>client.state()</P>
</TD>
</TR>
<TR>
<TD>
<P>remoteIP() </P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the remote IP. </P>
</TD>
<TD>
<P>client.remoteIP()</P>
</TD>
</TR>
<TR>
<TD>
<P>remotePort() </P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the remote port. </P>
</TD>
<TD>
<P>client.remotePort()</P>
</TD>
</TR>
<TR>
<TD>
<P>localIP()</P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the local IP</P>
</TD>
<TD>
<P>client.localIP()</P>
</TD>
</TR>
<TR>
<TD>
<P>localPort()</P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the local port</P>
</TD>
<TD>
<P>client.localPort()</P>
</TD>
</TR>
<TR>
<TD>
<P>send(data) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sends data to remote connection</P>
</TD>
<TD>
<P>client.send("hello")</P>
</TD>
</TR>
<TR>
<TD>
<P>sendWithPDUInfo(data, pduInfo)
</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Sends data to remote connection with PDU info.</P>
</TD>
<TD>
<P><FONT COLOR="#000000">data = "hello"pduInfo =
PDUInfo(0xffff00)</FONT> <FONT COLOR="#000000">pduInfo.setOutFormat("MyProtocol",
"MyPDU", {"type": "REPLY", "data":
data})pduInfo.addOutMessage("I am sending some data.")</FONT>
<FONT COLOR="#000000">client.sendWithPDUInfo(data, pduInfo) </FONT>
</P>
</TD>
</TR>
<TR>
<TD>
<P>onReceive(callback)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for when data is received. </P>
</TD>
<TD>
<P STYLE="margin-bottom: 0in">def onTCPReceive(data): <BR>print(data)</P>
<P STYLE="margin-bottom: 0in">...</P>
<P>client.onReceive(onTCPReceive)</P>
</TD>
</TR>
<TR>
<TD>
<P>onReceiveWithPDUInfo(callback)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P><FONT COLOR="#000000">Sets the callback for when data is
received and includes the PDU info.</FONT>
</P>
</TD>
<TD>
<PRE CLASS="western" STYLE="margin-bottom: 0.2in">client = TCPClient()...def onTCPReceiveWithPDUInfo(data, pduInfo): print(client.remoteIP() + ": " + data) pduInfo.addInMessage("I got some data.") pduInfo.setAccepted()...
client.onReceiveWithPDUInfo(onTCPReceiveWithPDUInfo)</PRE>
</TD>
</TR>
<TR>
<TD>
<P>onConnectionChange(callback) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for when the connection changes. </P>
</TD>
<TD>
<P STYLE="margin-bottom: 0in">def onTCPConnectionChange(type): <BR>print(type)</P>
<P STYLE="margin-bottom: 0in">...</P>
<P>client.onConnectionChange(onTCPConnectionChange)</P>
</TD>
</TR>
<TR>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
</TR>
<TR>
<TD>
<P>TCPServer() </P>
</TD>
<TD>
<P>TCPServer</P>
</TD>
<TD>
<P>Creates a TCP Server. </P>
</TD>
<TD>
<P>server = TCPServer() </P>
</TD>
</TR>
<TR>
<TD>
<P>listen(port) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Starts listening on port. </P>
</TD>
<TD>
<P>server.listen(2000)</P>
</TD>
</TR>
<TR>
<TD>
<P>stop() </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Stops listening. </P>
</TD>
<TD>
<P>server.stop()</P>
</TD>
</TR>
<TR>
<TD>
<P>onNewClient(callback)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for when a new client comes in. </P>
</TD>
<TD>
<P STYLE="margin-bottom: 0in">def onTCPNewClient(client): <BR>print(client)</P>
<P STYLE="margin-bottom: 0in">...</P>
<P>server.onNewClient(onTCPNewClient)</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-UDP"></A>UDP</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=udp"></A>Package =
udp</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>UDPSocket() </P>
</TD>
<TD>
<P>UDPSocket</P>
</TD>
<TD>
<P>Creates an UDP Socket. </P>
</TD>
<TD>
<P>udp = UDPSocket() </P>
</TD>
</TR>
<TR>
<TD>
<P>begin(port) </P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Starts listening on port. </P>
</TD>
<TD>
<P>udp.begin(2000)</P>
</TD>
</TR>
<TR>
<TD>
<P>stop() </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Stops listening. </P>
</TD>
<TD>
<P>udp.stop()</P>
</TD>
</TR>
<TR>
<TD>
<P>send(ip, port, data) </P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Sends data. </P>
</TD>
<TD>
<P>udp.send("1.1.1.1", 2000, "hello")</P>
</TD>
</TR>
<TR>
<TD>
<P>sendWithPDUInfo(ip, port, data, pduInfo)
</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P><FONT COLOR="#000000">Sends data with PDU info.</FONT>
</P>
</TD>
<TD>
<P>data = "hello"pduInfo = PDUInfo(0xffff00)
pduInfo.setOutFormat("MyProtocol", "MyPDU",
{"type": "REPLY", "data":
data})pduInfo.addOutMessage("I am sending some data.")
udp.sendWithPDUInfo("1.1.1.1", 2000, data, pduInfo)
</P>
</TD>
</TR>
<TR>
<TD>
<P>onReceive(callback)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for when data is received. </P>
</TD>
<TD>
<P STYLE="margin-bottom: 0in">def onUDPReceive(ip, port,
data):</P>
<P STYLE="margin-bottom: 0in">print(data)</P>
<P>...</P>
<P>udp.onReceive(onUDPReceive)</P>
</TD>
</TR>
<TR>
<TD>
<P>onReceiveWithPDUInfo(callback)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P><FONT COLOR="#000000">Sets the callback for when data is
received and includes PDU info.</FONT>
</P>
</TD>
<TD>
<PRE CLASS="western" STYLE="margin-bottom: 0.2in">def onUDPReceiveWithPDUInfo(ip, port, data, pduInfo): print(data)
pduInfo.addInMessage("I got some data.") pduInfo.setAccepted()...
udp.onReceiveWithPDUInfo(onUDPReceiveWithPDUInfo)</PRE>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-File(SBConly)"></A>File (SBC
only)</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=file,os,os.path"></A>
Package = file, os, os.path</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>bool exists(path) </P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Returns whether a file exists in the file system. </P>
</TD>
<TD>
<P>exists("/file.txt") </P>
</TD>
</TR>
<TR>
<TD>
<P>File open(path, mode) </P>
</TD>
<TD>
<P>File</P>
</TD>
<TD>
<P>Opens a file for reading or writing. </P>
</TD>
<TD>
<P>file = open("/file.txt", "r") </P>
</TD>
</TR>
<TR>
<TD>
<P>bool remove(path) </P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Removes a file. </P>
</TD>
<TD>
<P>remove("/file.txt")</P>
</TD>
</TR>
<TR>
<TD>
<P>bool mkdir(path) </P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Creates a directory including all intermediate directories. </P>
</TD>
<TD>
<P>mkdir("/dir1/dir2")</P>
</TD>
</TR>
<TR>
<TD>
<P>bool rmdir(path) </P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Removes a directory. </P>
</TD>
<TD>
<P>rmdir("/dir1/dir2")</P>
</TD>
</TR>
<TR>
<TD>
<P>listdir(path) </P>
</TD>
<TD>
<P>list</P>
</TD>
<TD>
<P>Lists all files in a directory. </P>
</TD>
<TD>
<P>files = listdir("/dir1")</P>
</TD>
</TR>
<TR>
<TD>
<P>exists(path) </P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Test if path exists </P>
</TD>
<TD>
<P>val = exists("/file") </P>
</TD>
</TR>
<TR>
<TD>
<P>isfile(path)</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Test if path is a file</P>
</TD>
<TD>
<P>val = exists("/file")</P>
</TD>
</TR>
<TR>
<TD>
<P>isdir(path)</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Test if path is a directory</P>
</TD>
<TD>
<P>val = exists("/file")</P>
</TD>
</TR>
<TR>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
</TR>
<TR>
<TD>
<P>tell()</P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Return read/write pointer of the file</P>
</TD>
<TD>
<P>file.tell()</P>
</TD>
</TR>
<TR>
<TD>
<P>close() </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Closes the file. </P>
</TD>
<TD>
<P>file.close()</P>
</TD>
</TR>
<TR>
<TD>
<P>seek(position) </P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Seeks to position in file. </P>
</TD>
<TD>
<P>file.seek(0)</P>
</TD>
</TR>
<TR>
<TD>
<P>readline() </P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Reads a line of string or to the end of file. </P>
</TD>
<TD>
<P>val = file.readline()</P>
</TD>
</TR>
<TR>
<TD>
<P>read(length) </P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Reads the length of byte into string</P>
</TD>
<TD>
<P>val = file.read()</P>
</TD>
</TR>
<TR>
<TD>
<P>write(val) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Writes as binary. </P>
</TD>
<TD>
<P>file.write(val)</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-USB"></A>USB</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=usb"></A>Package =
usb</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>USB( usbNum, speed)</P>
</TD>
<TD>
<P>USB</P>
</TD>
<TD>
<P>The variable for USB port.</P>
</TD>
<TD>
<P>usb = USB(0, 9600);</P>
</TD>
</TR>
<TR>
<TD>
<P>close() </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Ends communication. </P>
</TD>
<TD>
<P>usb.close(); </P>
</TD>
</TR>
<TR>
<TD>
<P>inWaiting() </P>
</TD>
<TD>
<P>int </P>
</TD>
<TD>
<P># of bytes available for reading in buffer. </P>
</TD>
<TD>
<P>bytes = usb.inWaiting();</P>
</TD>
</TR>
<TR>
<TD>
<P>readLine() </P>
</TD>
<TD>
<P>string</P>
</TD>
<TD>
<P>Reads a line of string or to the end of stream. </P>
</TD>
<TD>
<P>val = usb.readLine(); </P>
</TD>
</TR>
<TR>
<TD>
<P>read() </P>
</TD>
<TD>
<P>string</P>
</TD>
<TD>
<P>Reads the first character and removes from buffer. </P>
</TD>
<TD>
<P>val = usb.read(); </P>
</TD>
</TR>
<TR>
<TD>
<P>peek()</P>
</TD>
<TD>
<P>string</P>
</TD>
<TD>
<P>Reads one character without removing from buffer.</P>
</TD>
<TD>
<P>val = usb.peek();</P>
</TD>
</TR>
<TR>
<TD>
<P>write(val) </P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Prints to USB, returns the number of bytes written. </P>
</TD>
<TD>
<P>val = usb.write(val); </P>
<P><BR>
</P>
</TD>
</TR>
<TR>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
<TD>
<P> </P>
</TD>
</TR>
<TR>
<TD>
<P>PTmata(usbNum, speed)</P>
</TD>
<TD>
<P>PTmata</P>
</TD>
<TD>
<P>The variable for PTmata communication over USB port.</P>
</TD>
<TD>
<P>ptmata = PTmata(0, 9600)</P>
</TD>
</TR>
<TR>
<TD>
<P>close() </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Ends communication. </P>
</TD>
<TD>
<P>ptmata.close() </P>
</TD>
</TR>
<TR>
<TD>
<P>pinMode(slot, mode) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Set a digital slot on other side to INPUT or OUTPUT. </P>
</TD>
<TD>
<P>ptmata.pinMode(1, OUT)</P>
<P>ptmata.pinMode(2, IN)</P>
</TD>
</TR>
<TR>
<TD>
<P>digitalRead(slot) </P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Reads from a digital slot on other side, returns HIGH or
LOW. </P>
</TD>
<TD>
<P>val = ptmata.digitalRead(1)</P>
</TD>
</TR>
<TR>
<TD>
<P>digitalWrite(slot, value) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Writes to a digital slot on other side with HIGH or
LOW. </P>
</TD>
<TD>
<P>ptmata.digitalWrite(1, HIGH)</P>
</TD>
</TR>
<TR>
<TD>
<P>analogRead(slot) </P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Reads from an analog slot on other side, returns 0 to 1023. </P>
</TD>
<TD>
<P>val = ptmata.analogRead(A1); </P>
</TD>
</TR>
<TR>
<TD>
<P>analogWrite(slot, value) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Writes a PWM wave to a digital slot on other side, from 0 to
255. </P>
</TD>
<TD>
<P>ptmata.analogWrite(A1, 128); </P>
</TD>
</TR>
<TR>
<TD>
<P>customRead(slot) </P>
</TD>
<TD>
<P>string</P>
</TD>
<TD>
<P>Reads from an custom slot on other side, returns a String</P>
</TD>
<TD>
<P>val = ptmata.customRead(1); </P>
</TD>
</TR>
<TR>
<TD>
<P>customWrite(slot, value) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Writes a string to a digital slot on other side. You can use
customRead directly from the other side</P>
</TD>
<TD>
<P>ptmata.customWrite(1, "hello"); </P>
</TD>
</TR>
<TR>
<TD>
<P>inWaiting() </P>
</TD>
<TD>
<P>int </P>
</TD>
<TD>
<P># of bytes available for reading in buffer. </P>
</TD>
<TD>
<P>bytes = ptmata.inWaiting();</P>
</TD>
</TR>
<TR>
<TD>
<P>processInput()</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Reads from buffer and processes inputs for commands and reports
of states.</P>
</TD>
<TD>
<PRE CLASS="western">def loop() :
while ptmata.inWaiting():
ptmata.processInput()
ptmata.readAndReportData()</PRE>
</TD>
</TR>
<TR>
<TD>
<P>readAndReportData()</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Reads this side's slot values and report to other side if they
are changed.</P>
</TD>
<TD>
<P>ptmata.readAndReportData();</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-IoEClient(SBConly)"></A>IoE
Client (SBC only)</H3>
<P><BR>
</P>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=ioeclient"></A>Package
= ioeclient</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>IoEClient.setup(api)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets up the API for remote monitor and control from IoE server.</P>
<P>The api is an object with the following properties describing
the device:</P>
<UL>
<LI><P STYLE="margin-bottom: 0in">type - a string for the type of
this device
</P>
<LI><P STYLE="margin-bottom: 0in">states - an Array of objects
with the following properties describing the state:
</P>
<UL>
<LI><P STYLE="margin-bottom: 0in">name - a string for this state
</P>
<LI><P STYLE="margin-bottom: 0in">type - a string for the type
of this state; can be "bool", "number",
"options", "string"
</P>
<LI><P STYLE="margin-bottom: 0in">options (required if type is
"options") - an object that maps values to names
</P>
<LI><P STYLE="margin-bottom: 0in">unit (optional if type is
"number") - the default or Metric unit label; the
value of a number state sent to the IoE Server should be in this
unit
</P>
<LI><P STYLE="margin-bottom: 0in">imperialUnit (optional if type
is "number") - the Imperial System unit label
</P>
<LI><P STYLE="margin-bottom: 0in">toImperialConversion (optional
if type is "number") - a string to be evaluated to
convert the default value to Imperial unit where x is the
default value
</P>
<LI><P STYLE="margin-bottom: 0in">toMetricConversion (optional
if type is "number") - a string to be evaluated to
convert the value in Imperial unit to the default or Metric
unit, where x is the Imperial value
</P>
<LI><P STYLE="margin-bottom: 0in">decimalDigits (optional if
type is "number") - the number of decimal digits to
round to on IoE Server pages; default is to not round
</P>
<LI><P STYLE="margin-bottom: 0in">controllable - a boolean
indicating whether it is remotely controllable
</P>
<LI><P STYLE="margin-bottom: 0in">minValue (required if type is
"number" and controllable is true) - the minimum value
to allow the IoE Server to set in default or Metric unit
</P>
<LI><P>maxValue (required if type is "number" and
controllable is true) - the maximum value to allow the IoE
Server to set in default or Metric unit
</P>
</UL>
</UL>
<P>For measurement systems other than Metric and Imperial, use
only the "unit" property. That means if you want a
device to show more than Metric and Imperial, you need to create
another device for other measurement systems.</P>
<P> </P>
</TD>
<TD>
<PRE CLASS="western">IoEClient.setup({
"type": "Door",
"states": [{
"name": "Open",
"type": "bool"
}, {
"name": "Lock",
"type": "options",
"options": {
"0": "Unlock",
"1": "Lock"
},
"controllable": True
}]
});
IoEClient.setup({
"type": "Thermostat",
"states": [{
"name": "Status",
"type": "options",
"options": {
"0": "Off",
"1": "Cooling",
"2": "Heating",
"3": "Auto"
},
"controllable": True
}, {
"name": "Temperature",
"type": "number",
"unit": "&deg;C",
"imperialUnit": "&deg;F",
"toImperialConversion": "x*1.8+32",
"toMetricConversion": "(x-32)/1.8",
"decimalDigits": 1
}, {
"name": "Auto Cool Temperature",
"type": "number",
"unit": "&deg;C",
"imperialUnit": "&deg;F",
"toImperialConversion": "x*1.8+32",
"toMetricConversion": "(x-32)/1.8",
"decimalDigits": 1,
"controllable": True,
"minValue": 10,
"maxValue": 100
}, {
"name": "Auto Heat Temperature",
"type": "number",
"unit": "&deg;C",
"imperialUnit": "&deg;F",
"toImperialConversion": "x*1.8+32",
"toMetricConversion": "(x-32)/1.8",
"decimalDigits": 1,
"controllable": True,
"minValue": -100,
"maxValue": 20
}]
});</PRE>
</TD>
</TR>
<TR>
<TD>
<P>IoEClient.reportStates(states)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Reports the states of this device to the IoE server.<BR>The
argument can be a string representing all states of this device.
Each state is separated by a comma. The argument can also be an
array representing all states.<BR>The number of states must match
the length of the states property in setup().</P>
</TD>
<TD>
<P>IoEClient.reportStates("0,1")</P>
<P>IoEClient.reportStates([0, 1, "str"])</P>
</TD>
</TR>
<TR>
<TD>
<P>IoEClient.onInputReceive(callback)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for processing inputs received from IoE
server.<BR>The argument to the callback is a string containing all
states of this device.</P>
<P>This is called with all states info. onStateSet is called with
only the state that was changed.</P>
</TD>
<TD>
<P>def onInputReceiveDone(input): <BR>print(input)</P>
<P>...<BR>IoEClient.onInputReceive(onInputReceiveDone)</P>
</TD>
</TR>
<TR>
<TD>
<P>IoEClient.onStateSet(callback)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for processing inputs received from IoE
server.<BR>The arguments to the callback are state name and state
value.</P>
<P>This is called with only the state that was changed.
onInputReceive is called with all states info.</P>
</TD>
<TD>
<P>def onStateSet(stateName, value):<BR>print(stateName + ":
" + value)<BR>...<BR>IoEClient.onStateSet(onStateSet) </P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-Physical"></A>Physical</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=physical"></A>Package
= physical</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>move(x,y) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Move thing to position x and y in screen coordinates. The
parameters expect x and y are ints. Casting may be required.</P>
</TD>
<TD>
<P>move(200,200)</P>
</TD>
</TR>
<TR>
<TD>
<P>moveBy(x,y)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Increment position of thing by x and y in screen
coordinates. The parameters expect x and y are ints. Casting
may be required.</P>
</TD>
<TD>
<P>moveBy(1,0)</P>
</TD>
</TR>
<TR>
<TD>
<P>moveItemInWorkspace(name, x, y)</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Moves the item defined by name to x and y in screen coordinates
in the active workspace</P>
</TD>
<TD>
<P>moveItemInWorkspace("building", 300,300)</P>
</TD>
</TR>
<TR>
<TD>
<P>getX()</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Gets the x position of thing in screen coordinates.</P>
</TD>
<TD>
<P>x = getX()</P>
</TD>
</TR>
<TR>
<TD>
<P>getY()</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Gets the y position of thing in screen coordinates.</P>
</TD>
<TD>
<P>y = getY()</P>
</TD>
</TR>
<TR>
<TD>
<P>devicesAt(x, y, width, height)</P>
</TD>
<TD>
<P>list</P>
</TD>
<TD>
<P>Gets a list of devices at position x and y with a boundary of
width and height. The parameters expect x and y are ints.
Casting may be required.</P>
</TD>
<TD>
<P>devices = devicesAt(10,10,100,100)</P>
</TD>
</TR>
<TR>
<TD>
<P>devicesIncludingClustersAt(x, y, width, height)</P>
</TD>
<TD>
<P>Array of string</P>
</TD>
<TD>
<P>Gets a list of devices at position x and y with a boundary of
width and height including clusters</P>
</TD>
<TD>
<P>devicesIncludingClustersAt(10, 10, 100, 100)</P>
</TD>
</TR>
<TR>
<TD>
<P>getName()</P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Gets the name of the thing</P>
</TD>
<TD>
<P>devName = getName()</P>
</TD>
</TR>
<TR>
<TD>
<P>getDeviceProperty(deviceName, property)</P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Gets the property of a device with the specified property</P>
</TD>
<TD>
<P>prop = getDeviceProperty("Car", "material")</P>
</TD>
</TR>
<TR>
<TD>
<P>setDeviceProperty(deviceName, property, value)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Set property for device</P>
</TD>
<TD>
<P>prop= setDeviceProperty("Car", "material",
"metal")</P>
</TD>
</TR>
<TR>
<TD>
<P>setComponentOpacity(componentName, value)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Set the opacity of a component in the thing. The value is from
0 to 1, where 1 is opaque.</P>
</TD>
<TD>
<P>setComponentOpacity("light", 0.5)</P>
</TD>
</TR>
<TR>
<TD>
<P>setComponentRotation(componentName, value)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the component rotation in degrees</P>
</TD>
<TD>
<P>setComponentRotation("hourHand", 90)</P>
</TD>
</TR>
<TR>
<TD>
<P>setThingRotation(value)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the entire thing rotation in degrees</P>
</TD>
<TD>
<P>setThingRotation(180)</P>
</TD>
</TR>
<TR>
<TD>
<P>getSerialNumber()</P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Gets the serial number of the thing</P>
</TD>
<TD>
<P>serialNo = getSerialNumber()</P>
</TD>
</TR>
<TR>
<TD>
<P>setCustomText(x,y,width,height,text)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Write some text on the Thing viewable on the workspace.</P>
</TD>
<TD>
<P>setCustomText(0,0,100,100,"Device is On")</P>
</TD>
</TR>
<TR>
<TD>
<P>fillColor(componentName, red, green, blue)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Fill the component with the specified RGB values. The component
original image will have to be transparent for the color to show
up.</P>
</TD>
<TD>
<P>fillColor("led", 0,0,255)</P>
</TD>
</TR>
<TR>
<TD>
<P>addSound(soundID, soundPath)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Adds a sound to the device so it can be used. Sound is
referenced by the ID for later use. PT sound folder is:</P>
<P>"/../Sounds/"</P>
</TD>
<TD>
<P>addSound('sound1', '/../Sounds/buzzLow.wav');</P>
</TD>
</TR>
<TR>
<TD>
<P>playSound(soundID, playLength)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Plays a sound that has been added to the device. soundID
references the ID the sound was added with, playLength is how many
times the sound should run. -1 will make the sound loop
forever.</P>
</TD>
<TD>
<P>playSound('sound1', 2);</P>
</TD>
</TR>
<TR>
<TD>
<P>stopSound(soundID)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Stops a sound. soundID references the ID the sound
played.</P>
</TD>
<TD>
<P>stopSound('sound1');</P>
</TD>
</TR>
<TR>
<TD>
<P>destroySounds()</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Stops any sounds playing in the devices and removes them.
They can't be played again unless re-added.</P>
</TD>
<TD>
<P>destroySounds();</P>
</TD>
</TR>
<TR>
<TD>
<P>setParentGraphicFromComponent(componentName, index)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the parent container of both physical and logical view to
a graphic from component.</P>
</TD>
<TD>
<P>setParentGraphicFromComponent("name", 0)</P>
</TD>
</TR>
<TR>
<TD>
<P>setLogicalParentGraphicFromComponent(componentName, index)</P>
</TD>
<TD>
<P>N/A
</P>
</TD>
<TD>
<P>Sets the parent container of logical view to a graphic from
component.</P>
</TD>
<TD>
<P>setLogicalParentGraphicFromComponent("name", 0)</P>
</TD>
</TR>
<TR>
<TD>
<P>setPhysicalParentGraphicFromComponent(componentName, index)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the parent container of physical view to a graphic from
component.</P>
</TD>
<TD>
<P>setPhysicalParentGraphicFromComponent("name", 0)</P>
</TD>
</TR>
<TR>
<TD>
<P>setLogicalBackgroundPath(path)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the logical view background to an image at path.</P>
</TD>
<TD>
<P>setLogicalBackgroundPath("path")</P>
</TD>
</TR>
<TR>
<TD>
<P>getAttributeOfDeviceAtSlot(attribute, slot)</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Returns the attribute value of the device connected at the
specified slot.</P>
</TD>
<TD>
<P>value = getAttributeOfDeviceAtSlot("name", 0)</P>
</TD>
</TR>
<TR>
<TD>
<P>getAttributeOfDevice(attribute)</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Returns the attribute value of this device.</P>
</TD>
<TD>
<P>value = getAttributeOfDevice("name")</P>
</TD>
</TR>
<TR>
<TD>
<P>getSlotsCount()</P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the number of slots this device has.</P>
</TD>
<TD>
<P>slots = getSlotsCount()</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<COL WIDTH=243>
<COL WIDTH=63>
<COL WIDTH=511>
<COL WIDTH=326>
<TR>
<TD WIDTH=243>
<H3 CLASS="western"><A NAME="PythonAPI-Environment"></A>Environment</H3>
</TD>
<TD COLSPAN=3 WIDTH=907>
<H3 CLASS="western"><A NAME="PythonAPI-Package=environment(fromenvironmentimport*)or(fromenvironmentimportEnvironment)"></A>
Package = environment (from environment import *) or (from
environment import Environment)</H3>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>Function</P>
</TD>
<TD WIDTH=63>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD WIDTH=511>
<P>Description</P>
</TD>
<TD WIDTH=326>
<P>Example</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>get(environmentID)</P>
</TD>
<TD WIDTH=63>
<P>float</P>
</TD>
<TD WIDTH=511>
<P>Gets the value of the environment by its ID. You can get the ID
by placing your mouse over the environment name in the Environment
GUI.</P>
<P>If the environment does not exist, it will return -1.</P>
</TD>
<TD WIDTH=326>
<P>Environment.get("Ambient Temperature")</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>setGlobalProperty(propertyName, value) </P>
</TD>
<TD WIDTH=63>
<P>N/A</P>
</TD>
<TD WIDTH=511>
<P>Sets a global property with a value. Both are strings.</P>
</TD>
<TD WIDTH=326>
<P>Environment.setGlobalProperty("CLOCK", "12:00:00
pm")</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>getGlobalProperty(propertyName)</P>
</TD>
<TD WIDTH=63>
<P>string</P>
</TD>
<TD WIDTH=511>
<P>Returns the global property value.</P>
</TD>
<TD WIDTH=326>
<P>Environment.getGlobalProperty("CLOCK")</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>hasGlobalProperty(propertyName)</P>
</TD>
<TD WIDTH=63>
<P>boolean</P>
</TD>
<TD WIDTH=511>
<P>Returns true if the property name exists, otherwise false.</P>
</TD>
<TD WIDTH=326>
<P>Environment.hasGlobalProperty("CLOCK")</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>setContribution(environmentID, rate, limit, bCumulative)</P>
</TD>
<TD WIDTH=63>
<P> </P>
</TD>
<TD WIDTH=511>
<P>Set the things contribution to an environment based on it's
environment ID. You do not need to worry about how much time has
passed and you only need to call this function when you need
different parameters.</P>
<P>rate: the rate to add or subtract from the total environment
value in value/second. Value should be in metric.</P>
<P>limit: the maximum or minimum this thing is allowed to
contribute. The limit should be in metric.</P>
<P>bCumulative: add up contributed values over time. For
environments like light sources that disappear when off,
bCumulative should be set to false.</P>
</TD>
<TD WIDTH=326>
<P>// increase the Ambient Temperature at 0.05C/second until 100C.</P>
<P>Environment.setContribution("Ambient Temperature",
0.05, 100, true)</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>removeCumulativeContribution(environmentID)</P>
</TD>
<TD WIDTH=63>
<P> </P>
</TD>
<TD WIDTH=511>
<P>Remove the overall cumulative contribution from the Thing. In
most cases, you do not need to do this. Rather, you should set up
the container to use transference or other things to remove
accumulated contributions.</P>
</TD>
<TD WIDTH=326>
<P>Environment.removeCumulativeContribution("Ambient
Temperature")</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>setTransferenceMultiplier(environmentID, multiplier)</P>
</TD>
<TD WIDTH=63>
<P> </P>
</TD>
<TD WIDTH=511>
<P>Increase or decrease the current transference value by
multiplier.</P>
<P>For example, if you open the door to the house, you may want to
speed up the Ambient Temperature convergence with the outside by
increasing the container's transference by the multiplier.</P>
</TD>
<TD WIDTH=326>
<P>Environment.setTransferenceMultiplier("Ambient
Temperature", 2)</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>getTotalContributions(environmentID)</P>
</TD>
<TD WIDTH=63>
<P>float</P>
</TD>
<TD WIDTH=511>
<P>Returns the total value of contributions by all things</P>
</TD>
<TD WIDTH=326>
<P>Environment.getTotalContributions("Wind Speed")</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>getCumulativeContribution(environmentID)</P>
</TD>
<TD WIDTH=63>
<P> </P>
</TD>
<TD WIDTH=511>
<P>Returns the cumulativeContribution for just the thing that is
calling the function</P>
</TD>
<TD WIDTH=326>
<P>Environment.getCumulativeContribution("Wind Speed")</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>getMetricValue(environmentID)</P>
</TD>
<TD WIDTH=63>
<P>float</P>
</TD>
<TD WIDTH=511>
<P>Returns the metric value of the environmentID regardless of
user preference</P>
</TD>
<TD WIDTH=326>
<P>Environment.getMetricValue("Ambient Temperature")</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>getValueWithUnit(environmentID)</P>
</TD>
<TD WIDTH=63>
<P>string</P>
</TD>
<TD WIDTH=511>
<P>Returns the value in metric or imperial based on the user
preference and also append the unit</P>
</TD>
<TD WIDTH=326>
<P>Environment.getValueWithUnit("Ambient Temperature")</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>getUnit(environmentID)</P>
</TD>
<TD WIDTH=63>
<P>string</P>
</TD>
<TD WIDTH=511>
<P>Returns the unit for the environmentID. The unit can be metric
or imperial based on the user preferences</P>
</TD>
<TD WIDTH=326>
<P>Environment.getUnit("Ambient Temperature")</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>getVolume()</P>
</TD>
<TD WIDTH=63>
<P>float</P>
</TD>
<TD WIDTH=511>
<P>Returns the volume size of the container in meters^3 that
caller of the function is in</P>
</TD>
<TD WIDTH=326>
<P>Environment.getVolume()</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>getTimeInSeconds()</P>
</TD>
<TD WIDTH=63>
<P>int</P>
</TD>
<TD WIDTH=511>
<P>Returns the current time</P>
</TD>
<TD WIDTH=326>
<P>Environment.getTimeInSeconds();</P>
</TD>
</TR>
<TR>
<TD WIDTH=243>
<P>getElapsedTime(lastTime)</P>
</TD>
<TD WIDTH=63>
<P>int</P>
</TD>
<TD WIDTH=511>
<P>Returns the time passed since the lastTime value</P>
</TD>
<TD WIDTH=326>
<P>var time = Environment.getTimeInSeconds();</P>
<P>delay(1000);</P>
<P>Environment.getElapsedTime(time);</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE WIDTH=1137 CELLPADDING=2 CELLSPACING=2 >
<COL WIDTH=206>
<COL WIDTH=103>
<COL WIDTH=141>
<COL WIDTH=281>
<COL WIDTH=386>
<TR>
<TD WIDTH=206>
<H3 CLASS="western">Real HTTP Server (External Network Access)</H3>
</TD>
<TD COLSPAN=4 WIDTH=923>
<H3 CLASS="western">Package = realhttp</H3>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P><STRONG>Function</STRONG></P>
</TD>
<TD WIDTH=141>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD WIDTH=281>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD WIDTH=386>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>RealHTTPServer() </P>
</TD>
<TD WIDTH=141>
<P>RealHTTPServer</P>
</TD>
<TD WIDTH=281>
<P>Creates a Real HTTP Server. </P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>http =
RealHTTPServer()</FONT></FONT></P>
<P> </P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>start( port )</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Start server listening on <I>port</I>.</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>http.start(
8765 )</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>stop( )</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Stop server listening.</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>http.stop()</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>isListening( )</P>
</TD>
<TD WIDTH=141>
<P>boolean</P>
</TD>
<TD WIDTH=281>
<P>Returns the listening status of the server.</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>if
http.isListening() :<BR> ...</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>route( url-pattern, request-types, callback, context=None)</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Adds <I>callback</I> to be run for all <I>request-types</I>
matching <I>url-pattern</I>.</P>
<P>callback: f<I>unction ( context, request, reply);<BR></I><SPAN STYLE="font-style: normal">requst:</SPAN>
<I>RealHttpServerRequest<BR></I><SPAN STYLE="font-style: normal">response:</SPAN>
<I>RealHttpServerResponse</I></P>
<P>url-pattern: <I>string</I><BR>request-types: <I>array of
strings (“GET”, “POST”, “PUT”,
“UPDATE”, “DELETE”)<BR><BR></I><SPAN STYLE="font-style: normal">context:
</SPAN><I>object</I><SPAN STYLE="font-style: normal">. <BR>If </SPAN><I>None</I><SPAN STYLE="font-style: normal">
the </SPAN><I>server</I><SPAN STYLE="font-style: normal"> </SPAN><I>object</I><SPAN STYLE="font-style: normal">
will be passed in as context.</SPAN></P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>def
on_get_files( context, request, reply ):<BR> ...<BR>def
on_posts( context, request, reply ):<BR> ...<BR>def
on_everything( context, request, reply ):<BR> ...<BR>http.route(
“/files/*”, [“GET”],
on_get_files)<BR>http.route( “*”, [“POST”],
on_posts)<BR>http.route( “*”, <SPAN STYLE="font-style: normal">[]</SPAN>,
on_everything)</FONT></FONT></P>
</TD>
</TR>
<tr>
<TD COLSPAN=2 WIDTH=313>
websocket(
<span style="color: rgb(57,57,59);">url-pattern, callback)</span>
</td>
<TD WIDTH=141>
N/A</td>
<TD WIDTH=281>
<p>Adds
<em>callback</em> to be run for incoming websocket connections matching
<em>url-pattern</em>.</p>
<p>callback:
<em>function (client);
<br>
</em>
<em>client</em>:
<em>RealWSClient</em>
</p>
<p>url-pattern:
<em>string</em>
</p>
</td>
<TD WIDTH=386>
<pre><span style="color: rgb(57,57,59);">def callback( client ):<br></span> pass</pre>
<pre><span style="color: rgb(57,57,59);">server.websocket("/ws", callback)</span></pre>
</td>
</tr>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P><BR>
</P>
</TD>
<TD WIDTH=141>
<P><BR>
</P>
</TD>
<TD WIDTH=281>
<P><BR>
</P>
</TD>
<TD WIDTH=386>
<P><BR>
</P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P><B>RealHTTPServerRequest</B></P>
</TD>
<TD WIDTH=141>
<P><BR>
</P>
</TD>
<TD WIDTH=281>
<P>Request object passed to routing callbacks.</P>
</TD>
<TD WIDTH=386>
<P><BR>
</P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>headers( )</P>
</TD>
<TD WIDTH=141>
<P>object</P>
</TD>
<TD WIDTH=281>
<P>Returns object containing request headers.</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>headers =
request.headers( )<BR>... headers[“Content-Type”] ...</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>method( )</P>
</TD>
<TD WIDTH=141>
<P>string</P>
</TD>
<TD WIDTH=281>
<P>Returns request's method (“GET”, etc.)</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>if
request.method() == “POST”:<BR> ...<BR></FONT></FONT><BR>
</P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>body( )</P>
</TD>
<TD WIDTH=141>
<P>string</P>
</TD>
<TD WIDTH=281>
<P>Returns the body of the request.</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>request.body();</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>url( )</P>
</TD>
<TD WIDTH=141>
<P>string</P>
</TD>
<TD WIDTH=281>
<P>Returns requested URL.</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>request.url();</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>ip( )</P>
</TD>
<TD WIDTH=141>
<P>string</P>
</TD>
<TD WIDTH=281>
<P>Returns IP address of the request origin.</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>if
request.ip() == “1.1.1.1”: <BR> ...</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P><BR>
</P>
</TD>
<TD WIDTH=141>
<P><BR>
</P>
</TD>
<TD WIDTH=281>
<P><BR>
</P>
</TD>
<TD WIDTH=386>
<P><BR>
</P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P><B>RealHTTPServerResponse</B></P>
</TD>
<TD WIDTH=141>
<P><BR>
</P>
</TD>
<TD WIDTH=281>
<P>Response object passed to routing callbacks.</P>
</TD>
<TD WIDTH=386>
<P><BR>
</P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>setStatus( code )</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Sets response status to <I>code</I><SPAN STYLE="font-style: normal">.<BR><BR>code:
number</SPAN></P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2><BR>response.setCode(
200 ) # for OK response</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>setHeaders( headers )</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Sets response headers in bulk. Object properties define header
names and values.<BR><BR>headers: object</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.setHeaders({<BR>
“Authorization”: “basic”,<BR>
“Cookie”: “Id=1234; Group=users”<BR>})</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>addHeader( name, value )</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Sets header <I>name</I> <SPAN STYLE="font-style: normal">to
</SPAN><I>value</I><SPAN STYLE="font-style: normal">.<BR><BR>name:
string<BR>value: string</SPAN></P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.addHeader(
“Cookie”, “Group=inner” )</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>appendContent( content )</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Appends <I>content</I> <SPAN STYLE="font-style: normal">to
response body.</SPAN></P>
<P STYLE="font-style: normal">content: string</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.appendContent(
“more stuff“ )</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>resetContent( )</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Resets the body of the response to empty.</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.resetContent()</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>end( )</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Initiates network transfer for the response.</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.setContent(
“Hello, world!” )<BR>response.end()</FONT></FONT></P>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.setToPath(
“my-file.txt” )<BR>response.end()</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>setContent( content )</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Sets the body of the response to <I>content</I><SPAN STYLE="font-style: normal">.</SPAN></P>
<P STYLE="font-style: normal">content: string</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.setContent(
“Hello, world!” )</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>setToFile( path )</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Sets content of the response to the contents of the file at
<I>path.</I> <SPAN STYLE="font-style: normal">The path must be
local to the device running the server.</SPAN></P>
<P STYLE="font-style: normal">path: string</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.setToFile(
“intro.html” )</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>setToNotFound( )
</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Canned response for when a requested resource can not be
located.</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.setToNoFound()</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>send( content )
</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Sends <I>content</I> <SPAN STYLE="font-style: normal">as plain
text.</SPAN></P>
<P STYLE="font-style: normal">content: string</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.send(
“Hello, world!” )</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>setContentType( type )
</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Sets <I>Content-Type</I> <SPAN STYLE="font-style: normal">header
to </SPAN><I>type</I><SPAN STYLE="font-style: normal">.</SPAN></P>
<P STYLE="font-style: normal">type: string</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.setContentType(
“text/html” )</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>sendFile( path )</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Sends the contents of the file at <I>path</I><SPAN STYLE="font-style: normal">.</SPAN></P>
<P STYLE="font-style: normal">path: file path local to the device
running the server.</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.send(
“my-file.txt” )</FONT></FONT></P>
</TD>
</TR>
<TR>
<TD COLSPAN=2 WIDTH=313>
<P>sendNotFound( )
</P>
</TD>
<TD WIDTH=141>
<P>N/A</P>
</TD>
<TD WIDTH=281>
<P>Sends canned response for when a requested resource can not be
located.</P>
</TD>
<TD WIDTH=386>
<P><FONT FACE="Courier New, monospace"><FONT SIZE=2>response.sendNotFound()</FONT></FONT></P>
</TD>
</TR>
</TABLE>
</div>
<div tabindex="0">
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><BR>
</P>
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-RealHTTP(ExternalNetworkAccess)"></A>
Real HTTP Client<BR>(External Network Access)</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=realhttp"></A>Package
= realhttp</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>RealHTTPClient() </P>
</TD>
<TD>
<P>RealHTTPClient</P>
</TD>
<TD>
<P>Creates a Real HTTP Client. </P>
</TD>
<TD>
<P>http = RealHTTPClient()</P>
</TD>
</TR>
<TR>
<TD>
<P>get(url) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Gets an URL. </P>
</TD>
<TD>
<P>http.get(“<A HREF="http://www.cisco.com/">http://www.cisco.com</A>”)</P>
</TD>
</TR>
<TR>
<TD>
<P>post(url, data)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Posts data to an URL.</P>
<P>data can be a string or a dictionary; if dictionary, it will be
URL-encoded into the body.</P>
</TD>
<TD>
<P>http.post(url, {"num":1, "str":"hello"})</P>
</TD>
</TR>
<TR>
<TD>
<P>put(url, data)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Puts data to an URL.</P>
<P>data can be a string or a dictionary; if dictionary, it will be
URL-encoded into the body.</P>
</TD>
<TD>
<P>http.put(url, {"num":1, "str":"hello"})</P>
</TD>
</TR>
<TR>
<TD>
<P>deleteResource(url) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sends a delete to an URL.</P>
</TD>
<TD>
<P>http.deleteResource(url)</P>
</TD>
</TR>
<TR>
<TD>
<P>getWithHeader(url, header)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Gets an URL with custom header fields as a dictionary.</P>
</TD>
<TD>
<P>http.getWithHeader("<A HREF="https://api.ciscospark.com/v1/people/me">https://api.ciscospark.com/v1/people/me</A>",
{"Authorization": "Bearer xxyyzz"})</P>
</TD>
</TR>
<TR>
<TD>
<P>postWithHeader(url, data, header)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Posts data to an URL with custom header fields as a dictionary.</P>
<P>data can be a string or a dictionary; if dictionary and custom
header field has "application/json" as the
"content-type", it will be json-encoded, otherwise it
will be URL-encoded into the body.</P>
</TD>
<TD>
<P>http.postWithHeader("<A HREF="https://api.ciscospark.com/v1/messages">https://api.ciscospark.com/v1/messages</A>",
{"toPersonId": "722bb271-d7ca-4bce-a9e3-471e4412fa77",
"text": "Hi Sparky"}, {"Authorization":
"Bearer xxyyzz", "Content-Type":
"application/json"})</P>
</TD>
</TR>
<TR>
<TD>
<P>putWithHeader(url, data, header)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Puts data to an URL with custom header fields as a dictionary.</P>
<P>data can be a string or a dictionary; if dictionary and custom
header field has "application/json" as the
"content-type", it will be json-encoded, otherwise it
will be URL-encoded into the body.</P>
</TD>
<TD>
<P>http.putWithHeader("<A HREF="https://api.ciscospark.com/v1/rooms/">https://api.ciscospark.com/v1/rooms/</A>xxyyzz",
{"title": "New room name"}, {"Authorization":
"Bearer xxyyzz"})</P>
</TD>
</TR>
<TR>
<TD>
<P>deleteResourceWithHeader(url, header)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sends a delete to an URL with custom header fields as a
dictionary.</P>
</TD>
<TD>
<P>http.deleteResourceWithHeader("<A HREF="https://api.ciscospark.com/v1/messages/">https://api.ciscospark.com/v1/messages/</A>xxyyzz",
{"Authorization": "Bearer xxyyzz"})</P>
</TD>
</TR>
<TR>
<TD>
<P>onDone(callback)
</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for when the request is done.</P>
<P>replyHeader is a dictionary of header fields in the reply. It
is added to 7.1 and is optional.</P>
</TD>
<TD>
<P>def onHTTPDone(status, data, replyHeader): print(data)</P>
<P>...</P>
<P>http.onDone(onHTTPDone)</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western">
<A NAME="PythonAPI-RealWebSocketClient(ExternalNetworkAccess)"></A>
Real WebSocket Client
<BR>(External Network Access)</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western">
<A NAME="PythonAPI-Package=realhttp"></A>Package = realhttp</H3>
</TD>
</TR>
<TR>
<TD>
<P>
<STRONG>Function</STRONG> </P>
</TD>
<TD>
<P>
<STRONG>Return Type</STRONG>
</P>
</TD>
<TD>
<P>
<STRONG>Description</STRONG> </P>
</TD>
<TD>
<P>
<STRONG>Example</STRONG> </P>
</TD>
</TR>
<tr>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>RealWSClient()</span>
<span> </span>
</p>
</div>
</div>
</td>
<td colspan="1">RealWSClient</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>Creates a Real WebSocket Client.</span>
<span> </span>
</p>
</div>
</div>
</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>client = RealWSClient()</span>
</p>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>connect(url)</span>
<span> </span>
</p>
</div>
</div>
</td>
<td colspan="1">N/A</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>Connects to a server URL</span>
</p>
</div>
</div>
</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>client</span>
<span>.connect(</span>
<span>"ws://1.1.1.1:2000")</span>
</p>
</div>
</div>
</td>
</tr>
<tr>
<td colspan="1">connected()</td>
<td colspan="1">bool</td>
<td colspan="1">Returns true if connected.</td>
<td colspan="1">client.connected()</td>
</tr>
<tr>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>close</span>
<span>()</span>
<span> </span>
</p>
</div>
</div>
</td>
<td colspan="1">N/A</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>Disconnects.</span>
<span> </span>
</p>
</div>
</div>
</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>client</span>
<span>.</span>
<span>close</span>
<span>()</span>
</p>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>
<span>state</span>
<span>()</span>
</span>
<span> </span>
</p>
</div>
</div>
</td>
<td colspan="1">int</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>Returns the state of the connection.</span>
<span> </span>
</p>
</div>
</div>
</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>client.state()</span>
</p>
</div>
</div>
</td>
</tr>
<tr>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>
<span>remoteIP</span>
<span>()</span>
</span>
<span> </span>
</p>
</div>
</div>
</td>
<td colspan="1">str</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>Returns the remote IP.</span>
<span> </span>
</p>
</div>
</div>
</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>client</span>
<span>.remoteIP()</span>
</p>
</div>
</div>
</td>
</tr>
<tr>
<td colspan="1">remoteHost()</td>
<td colspan="1">str</td>
<td colspan="1">Returns the remote server host name.</td>
<td colspan="1">client.remoteHost()</td>
</tr>
<tr>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>remotePort()</span>
<span> </span>
</p>
</div>
</div>
</td>
<td colspan="1">int</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>Returns the remote port.</span>
<span> </span>
</p>
</div>
</div>
</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>client</span>
<span>.remotePort()</span>
</p>
</div>
</div>
</td>
</tr>
<tr>
<td colspan="1">localIP()</td>
<td colspan="1">str</td>
<td colspan="1">Returns the local IP.</td>
<td colspan="1">client.localIP()</td>
</tr>
<tr>
<td colspan="1">localPort()</td>
<td colspan="1">int</td>
<td colspan="1">Returns the local port.</td>
<td colspan="1">client.localPort()</td>
</tr>
<tr>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>send(data)</span>
<span> </span>
</p>
</div>
</div>
</td>
<td colspan="1">N/A</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>Sends data to remote connection.</span>
</p>
</div>
</div>
</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>client</span>
<span>.send("hello")</span>
</p>
</div>
</div>
</td>
</tr>
<tr>
<td colspan="1">error()</td>
<td colspan="1">int</td>
<td colspan="1">Returns the last error code.</td>
<td colspan="1">client.error()</td>
</tr>
<tr>
<td colspan="1">errorString()</td>
<td colspan="1">str</td>
<td colspan="1">Returns the last error in string.</td>
<td colspan="1">client.errorString()</td>
</tr>
<tr>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>onReceive(callback)</span>
</p>
</div>
</div>
</td>
<td colspan="1">N/A</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>Sets the callback for when data is received.</span>
<span> </span>
</p>
</div>
</div>
</td>
<td>
<div>
<div style="margin-left: 0.0px;">def onWSReceive(data):
<br> print(data)</div>
<div style="margin-left: 0.0px;">...</div>
<div style="margin-left: 0.0px;">client.onReceive(onWSReceive)</div>
</div>
</td>
</tr>
<tr>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>onConnectionChange(callback)</span>
<span> </span>
</p>
</div>
</div>
</td>
<td colspan="1">N/A</td>
<td>
<div>
<div style="margin-left: 0.0px;">
<p>
<span>Sets the callback for when the connection changes.</span>
<span> </span>
</p>
</div>
</div>
</td>
<td>
<div>def onWSConnectionChange(type):
<br> print(type)</div>
<div>...</div>
<div>
<div style="margin-left: 0.0px;">client.onConnectionChange(onWSConnectionChange)</div>
</div>
</td>
</tr>
</TABLE>
</div>
<div tabindex="0">
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><BR>
</P>
<P ALIGN=LEFT STYLE="margin-bottom: 0in"><BR>
</P>
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-RealTCP(ExternalNetworkAccess)"></A>
Real TCP<BR>(External Network Access) </H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=realtcp"></A>Package
= realtcp</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>RealTCPClient() </P>
</TD>
<TD>
<P>RealTCPClient</P>
</TD>
<TD>
<P>Creates a Real TCP Client. </P>
</TD>
<TD>
<P>client = RealTCPClient()</P>
</TD>
</TR>
<TR>
<TD>
<P>connect(ip, port) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Connects to ip and port. </P>
</TD>
<TD>
<P>client.connect("1.1.1.1", 2000)</P>
</TD>
</TR>
<TR>
<TD>
<P>connected()</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Returns true if connected.</P>
</TD>
<TD>
<P>client.connected()</P>
</TD>
</TR>
<TR>
<TD>
<P>close() </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Disconnects. </P>
</TD>
<TD>
<P>client.close()</P>
</TD>
</TR>
<TR>
<TD>
<P>state() </P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the state of the connection. </P>
</TD>
<TD>
<P>client.state()</P>
</TD>
</TR>
<TR>
<TD>
<P>remoteIP() </P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the remote IP. </P>
</TD>
<TD>
<P>client.remoteIP()</P>
</TD>
</TR>
<TR>
<TD>
<P>remoteHost()</P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the remote server host name.</P>
</TD>
<TD>
<P>client.remoteHost()</P>
</TD>
</TR>
<TR>
<TD>
<P>remotePort() </P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the remote port. </P>
</TD>
<TD>
<P>client.remotePort()</P>
</TD>
</TR>
<TR>
<TD>
<P>localIP()</P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the local IP.</P>
</TD>
<TD>
<P>client.localIP()</P>
</TD>
</TR>
<TR>
<TD>
<P>localPort()</P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the local port.</P>
</TD>
<TD>
<P>client.localPort()</P>
</TD>
</TR>
<TR>
<TD>
<P>send(data) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sends data to remote connection.</P>
</TD>
<TD>
<P>client.send("hello")</P>
</TD>
</TR>
<TR>
<TD>
<P>error()</P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the last error code.</P>
</TD>
<TD>
<P>client.error()</P>
</TD>
</TR>
<TR>
<TD>
<P>errorString()</P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the last error in string.</P>
</TD>
<TD>
<P>client.errorString()</P>
</TD>
</TR>
<TR>
<TD>
<P>onReceive(callback)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for when data is received. </P>
</TD>
<TD>
<P STYLE="margin-bottom: 0in">def onTCPReceive(data): <BR> print(data)</P>
<P STYLE="margin-bottom: 0in">...</P>
<P>client.onReceive(onTCPReceive)</P>
</TD>
</TR>
<TR>
<TD>
<P>onConnectionChange(callback) </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for when the connection changes. </P>
</TD>
<TD>
<P STYLE="margin-bottom: 0in">def
onTCPConnectionChange(type): <BR> print(type)</P>
<P STYLE="margin-bottom: 0in">...</P>
<P>client.onConnectionChange(onTCPConnectionChange)</P>
</TD>
</TR>
<tr>
<td>
<br>
</td>
<td>
<br>
</td>
<td>
<br>
</td>
<td>
<br>
</td>
</tr>
<tr>
<td>RealTCPServer()</td>
<td>RealTCPServer</td>
<td>Creates a Real TCP Server.</td>
<td>server = RealTCPServer()</td>
</tr>
<tr>
<td>
<div>
<div>
<p>
<span>listen(port)</span>
<span> </span>
</p>
</div>
</div>
</td>
<td>bool</td>
<td>
<div>
<div>
<p>Listens on port on host device and returns whether it was successful.</p>
</div>
</div>
</td>
<td>
<div>
<div>
<p>server.listen(1234)</p>
</div>
</div>
</td>
</tr>
<tr>
<td>isListening()</td>
<td>bool</td>
<td>Returns true if listening.</td>
<td>server.isListening()</td>
</tr>
<tr>
<td>
<div>
<div>
<p>
<span>stop</span>
<span>()</span>
<span> </span>
</p>
</div>
</div>
</td>
<td>N/A</td>
<td>
<div>
<div>
<p>
<span>Stops listening. All connections remain open.</span>
<span> </span>
</p>
</div>
</div>
</td>
<td>
<div>
<div>
<p>server.stop()</p>
</div>
</div>
</td>
</tr>
<tr>
<td>listeningIP()</td>
<td>str</td>
<td>Returns the listening IP.</td>
<td>server.listeningIP()</td>
</tr>
<tr>
<td>listeningPort()</td>
<td>int</td>
<td>Returns the listening port.</td>
<td>server.listeningPort()</td>
</tr>
<tr>
<td>error()</td>
<td>int</td>
<td>Returns the last error code.</td>
<td>
<span>server</span>.error()</td>
</tr>
<tr>
<td>errorString()</td>
<td>str</td>
<td>Returns the last error in string.</td>
<td>
<span>server</span>.errorString()</td>
</tr>
<tr>
<td>
<div>
<div>
<p>
<span>onNewClient(callback)</span>
</p>
</div>
</div>
</td>
<td>N/A</td>
<td>
<div>
<div>
<p>
<span>Sets the callback for when a new client is connected.</span>
<span> </span>
</p>
</div>
</div>
</td>
<td>
<div>
<div>def onTCPNewClient(client):
<br> print("new client")</div>
<div>...</div>
<div>server.onNewClient(
<span>onTCPNewClient</span>)</div>
</div>
</td>
</tr>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-RealUDP(ExternalNetworkAccess)"></A>
Real UDP<BR>(External Network Access) </H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=realudp"></A>Package
= realudp</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>RealUDPSocket() </P>
</TD>
<TD>
<P>RealUDPSocket</P>
</TD>
<TD>
<P>Creates an Real UDP Socket. </P>
</TD>
<TD>
<P>udp = RealUDPSocket() </P>
</TD>
</TR>
<TR>
<TD>
<P>begin(port) </P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Starts listening on port. </P>
</TD>
<TD>
<P>udp.begin(2000)</P>
</TD>
</TR>
<TR>
<TD>
<P>stop() </P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Stops listening. </P>
</TD>
<TD>
<P>udp.stop()</P>
</TD>
</TR>
<TR>
<TD>
<P>joinMulticastGroup(ip)</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Joins a multicast group. Must call begin() first.</P>
</TD>
<TD>
<P>udp.joinMulticastGroup("224.0.0.1")</P>
</TD>
</TR>
<TR>
<TD>
<P>leaveMulticastGroup(ip)</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Leaves a multicast group.</P>
</TD>
<TD>
<P>udp.leaveMulticastGroup("224.0.0.1")</P>
</TD>
</TR>
<TR>
<TD>
<P>localIP()</P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the local IP.</P>
</TD>
<TD>
<P>udp.localIP()</P>
</TD>
</TR>
<TR>
<TD>
<P>localPort()</P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the local port.</P>
</TD>
<TD>
<P>udp.localPort()</P>
</TD>
</TR>
<TR>
<TD>
<P>send(ip, port, data) </P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Sends data. </P>
</TD>
<TD>
<P>udp.send("1.1.1.1", 2000, "hello")</P>
</TD>
</TR>
<TR>
<TD>
<P>onReceive(callback)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the callback for when data is received. </P>
</TD>
<TD>
<P STYLE="margin-bottom: 0in">def onUDPReceive(ip, port, data):</P>
<P STYLE="margin-bottom: 0in">print(data)</P>
<P>...</P>
<P>udp.onReceive(onUDPReceive)</P>
</TD>
</TR>
<TR>
<TD>
<P>error()</P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the last error code.</P>
</TD>
<TD>
<P>udp.error()</P>
</TD>
</TR>
<TR>
<TD>
<P>errorString()</P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the last error in string.</P>
</TD>
<TD>
<P>udp.errorString()</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-JSON"></A>JSON</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=json"></A>Package =
json</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>dumps(obj) </P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Serializes a Python object into JSON string. </P>
</TD>
<TD>
<P>jsonStr = json.dumps({"num":1, "s":"str"})</P>
</TD>
</TR>
<TR>
<TD>
<P>loads(jsonStr) </P>
</TD>
<TD>
<P>python object</P>
</TD>
<TD>
<P>Converts a JSON string into a Python object.</P>
</TD>
<TD>
<P>obj = json.loads(s)</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-GUI(SBCandThing,someEndDevices)"></A>
GUI <FONT COLOR="#ff0000">(SBC and Thing</FONT> <FONT COLOR="#ff0000">,
some End Devices</FONT>)</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=gui"></A>Package =
gui</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>GUI.setup()</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Initializes the GUI and tells the GUI to display the html file
configured in the manifest file. If the app is not installed, it
throws an error.</P>
</TD>
<TD>
<P>GUI.setup()</P>
</TD>
</TR>
<TR>
<TD>
<P>GUI.update(type, args)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Asynchronously calls the html file's update() function passing
in type and args. Type is a string and args can be any JSON valid
object.</P>
</TD>
<TD>
<P>GUI.update("status", "playing")</P>
</TD>
</TR>
<TR>
<TD>
<P>guiEvent(type, args)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>If defined, this function is called asynchronously when the
html file calls guiEvent(type, args). Type is a string and args
can be any JSON valid object.</P>
</TD>
<TD>
<PRE CLASS="western">def guiEvent(type, args): print('guiEvent: ' + type + ',' + dumps(args));</PRE>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<COL WIDTH=0>
<COL WIDTH=0>
<COL WIDTH=0>
<COL WIDTH=0>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-CLI(SBCandThing,someEndDevices)"></A>
CLI <FONT COLOR="#ff0000">(SBC and Thing</FONT> <FONT COLOR="#ff0000">,
some End Devices</FONT>)</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=cli"></A>Package =
cli</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>CLI.setup()</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Initializes the CLI and will call the cliEvent() function if
the app was started from a command in the Command Prompt.</P>
</TD>
<TD>
<P>CLI.setup()</P>
</TD>
</TR>
<TR>
<TD>
<P>CLI.exit()</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Exits the CLI mode and returns back to the Command Prompt.</P>
</TD>
<TD>
<P>CLI.exit()</P>
</TD>
</TR>
<TR>
<TD>
<P>cliEvent(type, args)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>If defined, this function is called synchronously when
different CLI events happen. Type is a string and args can be any
JSON valid object.</P>
<P>Type can be:</P>
<UL>
<LI><P STYLE="margin-bottom: 0in">"invoked" - this is
called when the command is invoked from the Command Prompt; args
is a list of command arguments where the first element is the
command name.
</P>
<LI><P>"interrupted" - this is called when the user
uses break shortcut (Ctrl+C) while this app is running in CLI
mode.
</P>
</UL>
</TD>
<TD>
<PRE CLASS="western">def cliEvent(type, args): print('cliEvent: ' + type + ',' + dumps(args));</PRE>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-Simulation"></A>Simulation</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=simulation"></A>Package
= simulation</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>Simulation.isInSimulationMode()</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Returns whether PT is currently in Simulation Mode.</P>
</TD>
<TD>
<P>if Simulation.isInSimulationMode(): print("In sim mode")
</P>
</TD>
</TR>
<TR>
<TD>
<P>Simulation.addCustomProtocolType(protocol)</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Adds a new protocol type to the current file/network. The
protocol will show up in the Event List Filters. Returns true if
successful, false otherwise.
</P>
</TD>
<TD>
<P>Simulation.addCustomProtocolType("MyProtocol")</P>
</TD>
</TR>
<TR>
<TD>
<P>Simulation.hasCustomProtocolType(protocol)</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Returns whether the protocol type is already added to the
current file/network.
</P>
</TD>
<TD>
<P>if not Simulation.hasCustomProtocolType("MyProtocol"):
Simulation.addCustomProtocolType("MyProtocol")</P>
</TD>
</TR>
<TR>
<TD>
<P>Simulation.addCustomPDU(protocol, pduType, definition)</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Adds a new protocol type and PDU type to the current
file/network. The protocol will show up in the Event List Filters,
and the PDU with its definition will show up in PDU details.
Returns true if successful, false if the definition is invalid. It
will replace existing definitions if using the same protocol and
PDU type names.</P>
<P>The definition argument is an object with the following
properties describing the layout and fields of the PDU:</P>
<UL>
<LI><P STYLE="margin-bottom: 0in">title - a string that shows up
as the title in PDU Details
</P>
<LI><P STYLE="margin-bottom: 0in">units - a string
</P>
<LI><P STYLE="margin-bottom: 0in">unit_marks - an array of
numbers indicating where the marks are to show up
</P>
<LI><P STYLE="margin-bottom: 0in">width - an integer indicating
the width of PDU
</P>
<LI><P STYLE="margin-bottom: 0in">fields - an array of objects
representing each field in the PDU; each object must contain the
following properties:
</P>
<UL>
<LI><P>value - a label that can contain a variable inside curly
braces; the variable will be replaced with a value in the
PDUInfo fields object</P>
<LI><P>size - an integer indicating the size of the field
</P>
</UL>
</UL>
</TD>
<TD>
<PRE CLASS="western">Simulation.addCustomPDU("MyProtocol", "MyPDU", { "title": "My PDU", "units": "Bits", "unit_marks": [16], "width": 32, "fields": [ { "value": "TYPE: {type}", "size": 32 }, { "value": "DATA: {data}", "size": 32 } ]})</PRE>
</TD>
</TR>
<TR>
<TD>
<P>Simulation.hasCustomPDU(protocol, pduType)</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Returns whether the protocol and PDU type is already added to
the current file/network.</P>
</TD>
<TD>
<P>if not Simulation.hasCustomPDU("MyProtocol",
"MyPDU"): # add it
</P>
</TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD>
<P>PDUInfo(color)</P>
</TD>
<TD>
<P>PDUInfo</P>
</TD>
<TD>
<P>Creates a PDU Info object with the pdu color. A PDUInfo is
required to show PDU with more details in Simulation Mode.</P>
</TD>
<TD>
<P>pduInfo = PDUInfo(0xffff00)</P>
</TD>
</TR>
<TR>
<TD>
<P>setOutFormat(protocol, pduType, fields)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the outgoing PDU to be displayed in a custom PDU
definition. The fields argument is an object with the variables
defined in the PDU definition fields property.</P>
</TD>
<TD>
<P>pduInfo.setOutFormat("MyProtocol", "MyPDU",
{"type": "REPLY", "data": data})</P>
</TD>
</TR>
<TR>
<TD>
<P>addOutMessage(message)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Adds a message to the outgoing OSI layer 7.</P>
</TD>
<TD>
<P>pduInfo.addOutMessage("I am sending some data.")</P>
</TD>
</TR>
<TR>
<TD>
<P>addInMessage(message)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Adds a message to the incoming OSI layer 7.</P>
</TD>
<TD>
<P>pduInfo.addInMessage("I received some data.")</P>
</TD>
</TR>
<TR>
<TD>
<P>setAccepted()</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the PDU as accepted.</P>
</TD>
<TD>
<P>pduInfo.setAccepted()</P>
</TD>
</TR>
<TR>
<TD>
<P>setDropped()</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets the PDU as dropped.</P>
</TD>
<TD>
<P>pduInfo.setDropped()</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-Workspace"></A>Workspace</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=workspace"></A>Package
= workspace</H3>
</TD>
</TR>
<TR>
<TD>
<P><STRONG>Function</STRONG> </P>
</TD>
<TD>
<P><STRONG>Return Type</STRONG></P>
</TD>
<TD>
<P><STRONG>Description</STRONG> </P>
</TD>
<TD>
<P><STRONG>Example</STRONG> </P>
</TD>
</TR>
<TR>
<TD>
<P>getPhysicalObject()</P>
</TD>
<TD>
<P>PhysicalObject</P>
</TD>
<TD>
<P>Returns the current device's physical object.
</P>
</TD>
<TD>
<P>po = getPhysicalObject()</P>
</TD>
</TR>
<TR>
<TD>
<P>getName()</P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the name of this physical object.</P>
</TD>
<TD>
<P>print(po.getName())</P>
</TD>
</TR>
<TR>
<TD>
<P>getType()</P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the type of this physical object. Valid values are:</P>
<P>INTER_CITY = 0CITY = 1BUILDING = 2WIRING_CLOSET = 3RACK =
4TABLE = 5DEVICE = 6MULTIUSER = 7GENERIC_CONTAINER = 8</P>
</TD>
<TD>
<P>print(po.getType())</P>
</TD>
</TR>
<TR>
<TD>
<P>getX()
</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Returns the x coordinate relative to its parent in meters.</P>
</TD>
<TD>
<P>print(po.getX())</P>
</TD>
</TR>
<TR>
<TD>
<P>getY()
</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Returns the y coordinate relative to its parent in meters.</P>
</TD>
<TD>
<P>print(po.getY())</P>
</TD>
</TR>
<TR>
<TD>
<P>getCenterX()
</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Returns the center x coordinate relative to its parent in
meters.</P>
</TD>
<TD>
<P>print(po.getCenterX())</P>
</TD>
</TR>
<TR>
<TD>
<P>getCenterY()
</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Returns the center y coordinate relative to its parent in
meters.</P>
</TD>
<TD>
<P>print(po.getCenterY())</P>
</TD>
</TR>
<TR>
<TD>
<P>getGlobalX()
</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Returns the global x coordinate of this physical object in
meters.</P>
</TD>
<TD>
<P>print(po.getGlobalX())</P>
</TD>
</TR>
<TR>
<TD>
<P>getGlobalY()
</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P><FONT COLOR="#000000">Returns the global y coordinate of this
physical object in meters.</FONT>
</P>
</TD>
<TD>
<P>print(po.getGlobalX())</P>
</TD>
</TR>
<TR>
<TD>
<P>getWidth()
</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Returns the width of this physical object in meters.</P>
</TD>
<TD>
<P>print(po.getWidth())</P>
</TD>
</TR>
<TR>
<TD>
<P>getHeight()
</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Returns the height of this physical object in meters.</P>
</TD>
<TD>
<P>print(po.getHeight())</P>
</TD>
</TR>
<TR>
<TD>
<P>moveTo(x, y)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Moves this physical object's top left corner to the specified
coordinates in meters relative to its parent.</P>
</TD>
<TD>
<P>po.moveTo(10, 20)</P>
</TD>
</TR>
<TR>
<TD>
<P>moveCenterTo(x, y)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Moves this physical object's center to the specified
coordinates in meters relative to its parent.</P>
</TD>
<TD>
<P>po.moveCenterTo(10, 20)</P>
</TD>
</TR>
<TR>
<TD>
<P>moveBy(x, y)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Moves this physical object by the specified coordinates in
meters.</P>
</TD>
<TD>
<P>po.moveBy(10, 20)</P>
</TD>
</TR>
<TR>
<TD>
<P>setVelocity(x, y)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets this physical object's velocity in meters. This physical
object then moves automatically.</P>
</TD>
<TD>
<P>po.setVelocity(1, 2)</P>
</TD>
</TR>
<TR>
<TD>
<P>getXVelocity()
</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P>Returns the x velocity of this physical object in meters.</P>
</TD>
<TD>
<P>print(po.getXVelocity())</P>
</TD>
</TR>
<TR>
<TD>
<P>getYVelocity()
</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P><FONT COLOR="#000000">Returns the y velocity of this physical
object in meters.</FONT>
</P>
</TD>
<TD>
<P>print(po.getYVelocity())</P>
</TD>
</TR>
<TR>
<TD>
<P>getParent()</P>
</TD>
<TD>
<P>PhysicalObject</P>
</TD>
<TD>
<P>Returns this physical object's parent.</P>
</TD>
<TD>
<P>parentPO = po.getParent()</P>
</TD>
</TR>
<TR>
<TD>
<P>moveOutOfParent()</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Moves this physical object out of its parent to the same level
as the parent, and returns whether it was successful.</P>
</TD>
<TD>
<P>po.moveOutOfParent()</P>
</TD>
</TR>
<TR>
<TD>
<P>moveInto(name)</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Moves this physical object into a container with the specified
name that is in the same level as this physical object, and
returns whether it was successful.</P>
</TD>
<TD>
<P>po.moveInto("Corporate Office")</P>
</TD>
</TR>
<TR>
<TD>
<P>getChildCount()</P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the number of children this physical object has.</P>
</TD>
<TD>
<P>print(po.getChildCount())</P>
</TD>
</TR>
<TR>
<TD>
<P>getChildAt(index)</P>
</TD>
<TD>
<P>PhysicalObject</P>
</TD>
<TD>
<P>Returns the child physical object at the specified index.</P>
</TD>
<TD>
<P>childPO = po.getChildAt(0)</P>
</TD>
</TR>
<TR>
<TD>
<P>getChild(name)</P>
</TD>
<TD>
<P>PhysicalObject</P>
</TD>
<TD>
<P>Returns the child physical object with the specified name.</P>
</TD>
<TD>
<P>childPO = po.getChild("Wiring Closet")</P>
</TD>
</TR>
<TR>
<TD></TD>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD>
<P>getLogicalObject()</P>
</TD>
<TD>
<P>LogicalObject</P>
</TD>
<TD>
<P>Returns the current device's logical object.
</P>
</TD>
<TD>
<P>lo = getLogicalObject()</P>
</TD>
</TR>
<TR>
<TD>
<P>getName()</P>
</TD>
<TD>
<P>str</P>
</TD>
<TD>
<P>Returns the name of this logical object.</P>
</TD>
<TD>
<P>print(lo.getName())</P>
</TD>
</TR>
<TR>
<TD>
<P>getType()</P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the type of this logical object. Valid values are:</P>
<P>ROOT = 1099DEVICE = 1100CLUSTER = 1104MULTIUSERITEM = 1108</P>
</TD>
<TD>
<P>print(lo.getType())</P>
</TD>
</TR>
<TR>
<TD>
<P>getX()
</P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the x coordinate relative to its parent in pixels.</P>
</TD>
<TD>
<P>print(lo.getX())</P>
</TD>
</TR>
<TR>
<TD>
<P>getY()
</P>
</TD>
<TD>
<P><FONT COLOR="#000000">int</FONT>
</P>
</TD>
<TD>
<P><FONT COLOR="#000000">Returns the y coordinate relative to its
parent in pixels.</FONT>
</P>
</TD>
<TD>
<P>print(lo.getY())</P>
</TD>
</TR>
<TR>
<TD>
<P>getCenterX()
</P>
</TD>
<TD>
<P><FONT COLOR="#000000">int</FONT>
</P>
</TD>
<TD>
<P><FONT COLOR="#000000">Returns the center x coordinate relative
to its parent in pixels.</FONT>
</P>
</TD>
<TD>
<P>print(lo.getCenterX())</P>
</TD>
</TR>
<TR>
<TD>
<P>getCenterY()
</P>
</TD>
<TD>
<P><FONT COLOR="#000000">int</FONT>
</P>
</TD>
<TD>
<P><FONT COLOR="#000000">Returns the center y coordinate relative
to its parent in pixels.</FONT>
</P>
</TD>
<TD>
<P>print(lo.getCenterY())</P>
</TD>
</TR>
<TR>
<TD>
<P>getWidth()
</P>
</TD>
<TD>
<P><FONT COLOR="#000000">int</FONT>
</P>
</TD>
<TD>
<P><FONT COLOR="#000000">Returns the width of this logical object
in pixels.</FONT>
</P>
</TD>
<TD>
<P>print(lo.getWidth())</P>
</TD>
</TR>
<TR>
<TD>
<P>getHeight()
</P>
</TD>
<TD>
<P><FONT COLOR="#000000">int</FONT>
</P>
</TD>
<TD>
<P><FONT COLOR="#000000">Returns the height of this logical object
in pixels.</FONT>
</P>
</TD>
<TD>
<P>print(lo.getHeight())</P>
</TD>
</TR>
<TR>
<TD>
<P>moveTo(x, y)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Moves this logical object's top left corner to the specified
coordinates in <FONT COLOR="#000000">pixels</FONT> relative to its
parent.</P>
</TD>
<TD>
<P>lo.moveTo(10, 20)</P>
</TD>
</TR>
<TR>
<TD>
<P>moveCenterTo(x, y)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Moves this logical object's center to the specified coordinates
in <FONT COLOR="#000000">pixels</FONT> relative to its parent.</P>
</TD>
<TD>
<P>lo.moveCenterTo(10, 20)</P>
</TD>
</TR>
<TR>
<TD>
<P>moveBy(x, y)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Moves this logical object by the specified coordinates in
<FONT COLOR="#000000">pixels</FONT>.</P>
</TD>
<TD>
<P>lo.moveBy(10, 20)</P>
</TD>
</TR>
<TR>
<TD>
<P>setVelocity(x, y)</P>
</TD>
<TD>
<P>N/A</P>
</TD>
<TD>
<P>Sets this logical object's velocity in <FONT COLOR="#000000">pixels</FONT>.
This logical object then moves automatically.</P>
</TD>
<TD>
<P>lo.setVelocity(1, 2)</P>
</TD>
</TR>
<TR>
<TD>
<P>getXVelocity()
</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P><FONT COLOR="#000000">Returns the x velocity of this logical
object in pixels.</FONT>
</P>
</TD>
<TD>
<P>print(lo.getXVelocity())</P>
</TD>
</TR>
<TR>
<TD>
<P>getYVelocity()
</P>
</TD>
<TD>
<P>float</P>
</TD>
<TD>
<P><FONT COLOR="#000000">Returns the y velocity of this logical
object in pixels.</FONT>
</P>
</TD>
<TD>
<P>print(lo.getYVelocity())</P>
</TD>
</TR>
<TR>
<TD>
<P>getParent()</P>
</TD>
<TD>
<P>LogicalObject</P>
</TD>
<TD>
<P>Returns this logical object's parent.</P>
</TD>
<TD>
<P>parentLO = lo.getParent()</P>
</TD>
</TR>
<TR>
<TD>
<P>moveOutOfParent()</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Moves this logical object out of its parent to the same level
as the parent, and returns whether it was successful.</P>
</TD>
<TD>
<P>lo.moveOutOfParent()</P>
</TD>
</TR>
<TR>
<TD>
<P>moveInto(name)</P>
</TD>
<TD>
<P>bool</P>
</TD>
<TD>
<P>Moves this logical object into a container with the specified
name that is in the same level as this logical object, and returns
whether it was successful.</P>
</TD>
<TD>
<P>lo.moveInto("Cluster0")</P>
</TD>
</TR>
<TR>
<TD>
<P>getChildCount()</P>
</TD>
<TD>
<P>int</P>
</TD>
<TD>
<P>Returns the number of children this logical object has.</P>
</TD>
<TD>
<P>print(lo.getChildCount())</P>
</TD>
</TR>
<TR>
<TD>
<P>getChildAt(index)</P>
</TD>
<TD>
<P>LogicalObject</P>
</TD>
<TD>
<P>Returns the child logical object at the specified index.</P>
</TD>
<TD>
<P>childlo = lo.getChildAt(0)</P>
</TD>
</TR>
<TR>
<TD>
<P>getChild(name)</P>
</TD>
<TD>
<P>LogicalObject</P>
</TD>
<TD>
<P>Returns the child logical object with the specified name.</P>
</TD>
<TD>
<P>childlo = lo.getChild("Cluster0")</P>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-BluetoothManager"></A>Bluetooth Manager</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=bluetooth"></A>Package
= bluetooth</H3>
</TD>
</TR>
<TR>
<TD><P><STRONG>Function</STRONG></P></TD>
<TD><P><STRONG>Return Type</STRONG></P></TD>
<TD><P><STRONG>Description</STRONG> </P></TD>
<TD><P><STRONG>Example</STRONG> </P></TD>
</TR>
<TR>
<TD>init()</TD>
<TD>N/A</TD>
<TD>Initialize Bluetooth functionality for the device.</TD>
<TD><pre>
def main():
Bluetooth.init()
</pre></TD>
</TR>
<TR>
<TD><P>onDeviceDiscovered(macAddress, deviceName)</P></TD>
<TD><P>N/A</P></TD>
<TD>This event handler is called when a device is discovered.</TD>
<TD><P>def handleDeviceDiscovered(macAddress, deviceName):...</P>
<P>Bluetooth.onDeviceDiscovered(handleDeviceDiscovered)</P>
<P>Bluetooth.discover()</P>
<P> </P></TD>
</TR>
<TR>
<TD>onDevicePaired(macAddress)</TD>
<TD>N/A</TD>
<TD>This event handler is called when a device is paired.</TD>
<TD><p>def handleDevicePaired(macAddress):...</p>
<p>Bluetooth.onDevicePaired(handleDevicePaired)</p></TD>
</TR>
<TR>
<TD>onDeviceUnPaired(macAddress)</TD>
<TD>N/A</TD>
<TD>This event handler is called when a device is unpaired.</TD>
<TD><p>def handleDeviceUnpaired(macAddress):...</p>
<p>Bluetooth.onDeviceUnpaired(handleDeviceUnpaired)</p></TD>
</TR>
<TR>
<TD>onDeviceConnected(macAddress)</TD>
<TD>N/A</TD>
<TD>This event handler is called when a device is connected.</TD>
<TD><p>def handleDeviceConnected(macAddress):...</p>
<p>Bluetooth.onDeviceConnected(handleDeviceConnected)</p></TD>
</TR>
<TR>
<TD>onDeviceDisconnected(macAddress)</TD>
<TD>N/A</TD>
<TD>This event handler is called when a device is disconnected.</TD>
<TD><p>def BandleDeviceDisconnected(macAddress):...</p>
<p>Bluetooth.onDeviceDisconnected(handleDeviceDisconnected)</p></TD>
</TR>
<TR>
<TD>setDiscoverable(discoverable)</TD>
<TD>N/A</TD>
<TD>Sets the Bluetooth device to discoverable or not.</TD>
<TD>Bluetooth.setDiscoverable(true)</TD>
</TR>
<TR>
<TD>isDiscoverable()</TD>
<TD>bool</TD>
<TD>Returns true if discoverable otherwise false.</TD>
<TD>Bluetooth.isDiscoverable()</TD>
</TR>
<TR>
<TD>discover()</TD>
<TD>N/A</TD>
<TD>Starts the discovering process. If devices are discovered, the onDeviceDiscovered() event will trigger.</TD>
<TD>Bluetooth.discover()</TD>
</TR>
<TR>
<TD>pair(mac)</TD>
<TD>N/A</TD>
<TD>Starts pairing with mac address.</TD>
<TD>Bluetooth.pair(macAddress)</TD>
</TR>
<TR>
<TD>unpair(mac)</TD>
<TD>N/A</TD>
<TD>Starts unpairing with mac address.</TD>
<TD>Bluetooth.unpair(macAddress)</TD>
</TR>
<TR>
<TD>onPairRequest(macAddress, deviceName)</TD>
<TD>N/A</TD>
<TD>This event handler is called if there's a pair request and the Bluetooth manager is set to accept pair requests.</TD>
<TD><p>Bluetooth.setAcceptingPairRequest(true)</p>
def handlePairRequest(macAddress, deviceName):...<br>
Bluetooth.onPairRequest = handlePairRequest</TD>
</TR>
<TR>
<TD>setAcceptingPairRequest(accepting)</TD>
<TD>N/A</TD>
<TD>Sets the Bluetooth manager to accept pair requests</TD>
<TD>Bluetooth.setAcceptingPairRequest(true)</TD>
</TR>
<TR>
<TD>acceptPairRequest(macAddress, deviceName)</TD>
<TD>N/A</TD>
<TD>Accepts the pair request with macAddress and deviceName</TD>
<TD>Bluetooth.acceptPairRequest(macAddress, deviceName)</TD>
</TR>
<TR>
<TD>getPairedDevices()</TD>
<TD>Array</TD>
<TD>Returns an array of paired Bluetooth devices.</TD>
<TD>var devices = Bluetooth.getPairedDevices()</TD>
</TR>
<TR>
<TD>getConnectedDevices()</TD>
<TD>Array</TD>
<TD>Returns an array of connected devices.</TD>
<TD>var devices = Bluetooth.getConnectedDevices()</TD>
</TR>
<TR>
<TD>enableBroadcast()</TD>
<TD>N/A</TD>
<TD>Enables Bluetooth broadcast.</TD>
<TD>Bluetooth.enableBroadcast()</TD>
</TR>
<TR>
<TD>isBroadcastEnabled()</TD>
<TD>bool</TD>
<TD>Returns true if broadcast is enabled.</TD>
<TD>Bluetooth.isBroadcastEnabled()</TD>
</TR>
<TR>
<TD>broadcastBeacon(beaconUuid, data)</TD>
<TD>bool</TD>
<TD>Broadcast beacon with beaconUuid and data.</TD>
<TD>Bluetooth.broadcastBeacon(uuid, data)</TD>
</TR>
</TABLE>
</div>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-BluetoothService"></A>Bluetooth Service</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=bluetooth"></A>Package
= bluetooth</H3>
</TD>
</TR>
<TR>
<TD><P><STRONG>Function</STRONG></P></TD>
<TD><P><STRONG>Return Type</STRONG></P></TD>
<TD><P><STRONG>Description</STRONG> </P></TD>
<TD><P><STRONG>Example</STRONG> </P></TD>
</TR>
<TR>
<TD><P>start(uuid)</P></TD>
<TD><P>N/A</P></TD>
<TD>Starts the Bluetooth service.</TD>
<TD><P>bts = BluetoothService()</P>
<P>dstService = "{00000000-0000-0000-0000-000000000001}"</P>
<P>bts.start(dstService)</P>
<P> </P></TD>
</TR>
<TR>
<TD>connect(dstMac, dstServiceUuid)</TD>
<TD>bool</TD>
<TD>Returns true if connected to dstMac and dstServiceUuid; false otherwise.</TD>
<TD>bts.connect(dstMac, dstServiceUuid)</TD>
</TR>
<TR>
<TD>stop()</TD>
<TD>N/A</TD>
<TD>Stops the Bluetooth service.</TD>
<TD>bts.stop()</TD>
</TR>
<TR>
<TD>send(dstMac, dstServiceUuid, data)</TD>
<TD>N/A</TD>
<TD>Sends data to dstMac and dstServiceUuid with data.</TD>
<TD>bts.send(dstMac, dstServiceUuid, "hello")</TD>
</TR>
<TR>
<TD>sendToConnected(data)</TD>
<TD>N/A</TD>
<TD>Sends data to connected device.</TD>
<TD>bts.sendToConnected("hello")</TD>
</TR>
<TR>
<TD>onReceive(srcMac, srcService, dstMac, dstService, data)</TD>
<TD>N/A</TD>
<TD>This event handler receives data from srcMac, srcService, dstMac and dstService with data.</TD>
<TD><p>def handleReceive(srcmac, srcData, dstMac, dstService, data){...}</p>
<p>bts.onReceive(handleReceive)</p></TD>
</TR>
</TABLE>
</div>
<P> </P>
<div tabindex="0">
<TABLE CELLPADDING=2 CELLSPACING=2>
<TR>
<TD>
<H3 CLASS="western"><A NAME="PythonAPI-BluetoothService"></A>Requests Module</H3>
</TD>
<TD COLSPAN=3>
<H3 CLASS="western"><A NAME="PythonAPI-Package=bluetooth"></A>Package
= requests</H3>
</TD>
</TR>
<TR>
<TD><P><STRONG>Function</STRONG></P></TD>
<TD><P><STRONG>Return Type</STRONG></P></TD>
<TD><P><STRONG>Description</STRONG> </P></TD>
<TD><P><STRONG>Example</STRONG> </P></TD>
</TR>
<TR>
<TD><P>get(url, params=None, **options)</P></TD>
<TD><P>Response</P></TD>
<TD>Make a GET request.<br/>
Supported options: timeout, headers, params.<br/>
<em>params</em> parameter/option can be in the following forms:
<ol>
<li>{key: value, key: value, ...} </li>
<li>[(key, value), (key, value), ...] </li>
<li>((key, value), (key, value), ...) </li>
<li>key=value&key=value&... # NOTE! this is a string, where keys and values must be URL-encoded </li>
</ol>
</TD>
<TD><P>reply = requests.get(url)</P>
<P> </P></TD>
</TR>
<TR>
<TD><P>post(url, data=None, json=None, **options)</P></TD>
<TD><P>Response</P></TD>
<TD>Make a POST request.<br/>
Supported options: timeout, headers, json, data.<br/>
<em>data</em> parameter/option Examples:
<ol>
<li> any structure suitable for params for get above. In this case it will be sent in the body </li>
<li> a string - will be sent AS IS </li>
</ol>
<em>json</em> parameter/option Examples:
<ol>
<li> a valid(!) JSON string </li>
<li> any Python structure that <em>json</em> library <em>dumps()</em> can work with </li>
</ol>
</TD>
<TD><P>reply = requests.post(url, json={"username":"admin", "password":"hello"})</P>
<P>reply = requests.post(url, data=(("username","admin"), ("password","hello")))</P>
<P>reply = requests.post(url, data="whatever data needs sending as a string")</P>
<P> </P></TD>
</TR>
<TR>
<TD><P>put(url, data=None, **options)</P></TD>
<TD><P>Response</P></TD>
<TD>Make a PUT request.<br/>
Supported options: timeout, headers, data.<br/>
<em>data</em> parameter/option - see post method above.
</TD>
<TD><P>reply = requests.put(url, data="whatever data needs to be stored as a string", headers=..., timeout=10)</P>
<P> </P></TD>
</TR>
<TR>
<TD><P>delete(url, **options)</P></TD>
<TD><P>Response</P></TD>
<TD>Make a DELETE request.<br/>
Supported options: timeout, headers.<br/>
<em>data</em> parameter/option - see post method above.
</TD>
<TD><P>reply = requests.delete(url, headers=...)</P>
<P> </P></TD>
</TR>
<TR>
<TD><P>request(method, url, **options)</P></TD>
<TD><P>Response</P></TD>
<TD>Make an HTTP request using a given <em>method</em>.<br/>
Supported options: timeout, headers, json, data, params. Depending on the method used.<br/>
<em>data</em> parameter/option - see post method above.
</TD>
<TD><P>reply = requests.request("POST", url, data=..., headers=...)</P>
<P> </P></TD>
</TR>
<TR>
<TD><P>urlencode(data)</P></TD>
<TD><P>string</P></TD>
<TD>URL-encodes <em>data</em> in a way suitable for using with GET parameters<br/>
Returns input data encoded.
</TD>
<TD><P>reply = requests.urlencode("hello world")</P>
<P>is expected to return "hello%20world"</P>
<P> </P></TD>
</TR>
<TR>
<TD><P>Response</P></TD>
<TD><P>class</P></TD>
<TD>
Properties:
<ul>
<li> <em>request</em>: original <em>Request</em> object. </li>
<li> <em>status_code</em>: integer HTTP status code (200 is OK, 404 is Not Found, etc). </li>
<li> <em>data</em> : data returned as a string. NOTE: this value is NOT in bytes. </li>
<li> <em>ok</em> : True for success, False - otherwise. </li>
<li> <em>text</em> : same as <em>data</em>. </li>
<li> <em>content</em> : same as <em>data</em>. </li>
<li> <em>url</em> : original request url. </li>
</ul>
Methods:
<ul>
<li> <em>json()</em> : Returns a Python object representing JSON result when applicable. </li>
</ul>
</TD>
<TD>
</TD>
</TR>
<TR>
<TD><P>Request</P></TD>
<TD><P>class</P></TD>
<TD>
Properties:
<ul>
<li> <em>url</em>: HTTP request url. </li>
<li> <em>method</em>: string - one of GET, DELETE, POST, PUT. </li>
<li> <em>headers</em> : dictionary containing request headers. </li>
<li> <em>timeout</em> : request timeout in seconds. Default value of 0 means - no timeout. </li>
<li> <em>data</em> : data as per API specification. </li>
<li> <em>json</em> : JSON data as per API specification. </li>
<li> <em>params</em> : a dictionary containing request URL parameters. </li>
</ul>
</TD>
<TD>
</TD>
</TR>
</TABLE>
</div>
<P> </P>
<P></P>
</BODY>
</HTML>