1
0
mirror of https://github.com/taigrr/arduinolibs synced 2025-01-18 04:33:12 -08:00
arduinolibs/shell_telnet.html
Rhys Weatherley 11f16a223a Update docs
2016-03-13 08:28:23 +10:00

174 lines
11 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.6"/>
<title>ArduinoLibs: Telnet server example</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
$(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td style="padding-left: 0.5em;">
<div id="projectname">ArduinoLibs
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.6 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
<div id="navrow1" class="tabs">
<ul class="tablist">
<li><a href="index.html"><span>Main&#160;Page</span></a></li>
<li class="current"><a href="pages.html"><span>Related&#160;Pages</span></a></li>
<li><a href="modules.html"><span>Modules</span></a></li>
<li><a href="annotated.html"><span>Classes</span></a></li>
<li><a href="files.html"><span>Files</span></a></li>
<li>
<div id="MSearchBox" class="MSearchBoxInactive">
<span class="left">
<img id="MSearchSelect" src="search/mag_sel.png"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
alt=""/>
<input type="text" id="MSearchField" value="Search" accesskey="S"
onfocus="searchBox.OnSearchFieldFocus(true)"
onblur="searchBox.OnSearchFieldFocus(false)"
onkeyup="searchBox.OnSearchFieldChange(event)"/>
</span><span class="right">
<a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
</span>
</div>
</li>
</ul>
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Enumerations</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(7)"><span class="SelectionMark">&#160;</span>Enumerator</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(8)"><span class="SelectionMark">&#160;</span>Friends</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(9)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(10)"><span class="SelectionMark">&#160;</span>Pages</a></div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
</div><!-- top -->
<div class="header">
<div class="headertitle">
<div class="title">Telnet server example </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The <a class="el" href="classShell.html" title="Command-line shell access. ">Shell</a> class provides a Unix-like shell for issuing commands to the Arduino. The <a class="el" href="classLoginShell.html" title="Command-line shell access via a login shell. ">LoginShell</a> class extends <a class="el" href="classShell.html" title="Command-line shell access. ">Shell</a> to also include login functionality. The user is prompted for username and password before access is granted to shell commands.</p>
<p>This example shows how to use <a class="el" href="classLoginShell.html" title="Command-line shell access via a login shell. ">LoginShell</a> to provide command-line access over the Internet via the telnet protocol. The example has one command "led" for turning the status LED on D13 on and off.</p>
<p>The full source code for the example follows:</p>
<div class="fragment"><div class="line"></div>
<div class="line"><span class="comment">/*</span></div>
<div class="line"><span class="comment">This example demonstrates how to create a simple telnet server.</span></div>
<div class="line"><span class="comment"></span></div>
<div class="line"><span class="comment">This example is placed into the public domain.</span></div>
<div class="line"><span class="comment">*/</span></div>
<div class="line"></div>
<div class="line"><span class="preprocessor">#include &lt;SPI.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;Ethernet.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;Shell.h&gt;</span></div>
<div class="line"><span class="preprocessor">#include &lt;LoginShell.h&gt;</span></div>
<div class="line"></div>
<div class="line">byte macAddress[6] = {</div>
<div class="line"> 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED</div>
<div class="line">};</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">int</span> ledPin = 13;</div>
<div class="line"></div>
<div class="line">EthernetServer server(23);</div>
<div class="line">EthernetClient client;</div>
<div class="line"><span class="keywordtype">bool</span> haveClient = <span class="keyword">false</span>;</div>
<div class="line"></div>
<div class="line"><a class="code" href="classLoginShell.html">LoginShell</a> shell;</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> cmdLed(<a class="code" href="classShell.html">Shell</a> &amp;shell, <span class="keywordtype">int</span> argc, <span class="keyword">const</span> <a class="code" href="classShellArguments.html">ShellArguments</a> &amp;argv)</div>
<div class="line">{</div>
<div class="line"> <span class="keywordflow">if</span> (argc &gt; 1 &amp;&amp; !strcmp(argv[1], <span class="stringliteral">&quot;on&quot;</span>))</div>
<div class="line"> digitalWrite(ledPin, HIGH);</div>
<div class="line"> <span class="keywordflow">else</span></div>
<div class="line"> digitalWrite(ledPin, LOW);</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><a class="code" href="classShell.html#a809d96cf913bf11d02f3c0d51a120740">ShellCommand</a>(led, <span class="stringliteral">&quot;Turns the status LED on or off&quot;</span>, cmdLed);</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> setup()</div>
<div class="line">{</div>
<div class="line"> <span class="comment">// Configure I/O.</span></div>
<div class="line"> pinMode(ledPin, OUTPUT);</div>
<div class="line"> digitalWrite(ledPin, LOW);</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Start the serial port for status messages.</span></div>
<div class="line"> Serial.begin(9600);</div>
<div class="line"> Serial.println();</div>
<div class="line"> Serial.print(<span class="stringliteral">&quot;Acquiring IP address ... &quot;</span>);</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Start Ethernet running and get an IP address via DHCP.</span></div>
<div class="line"> <span class="keywordflow">if</span> (Ethernet.begin(macAddress))</div>
<div class="line"> Serial.println(Ethernet.localIP());</div>
<div class="line"> <span class="keywordflow">else</span></div>
<div class="line"> Serial.println(<span class="stringliteral">&quot;failed&quot;</span>);</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Listen on port 23 for incoming telnet connections.</span></div>
<div class="line"> server.begin();</div>
<div class="line"> shell.setMachineName(<span class="stringliteral">&quot;Arduino&quot;</span>);</div>
<div class="line">}</div>
<div class="line"></div>
<div class="line"><span class="keywordtype">void</span> loop()</div>
<div class="line">{</div>
<div class="line"> <span class="comment">// Maintain the DHCP lease over time.</span></div>
<div class="line"> Ethernet.maintain();</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Handle new/disconnecting clients.</span></div>
<div class="line"> <span class="keywordflow">if</span> (!haveClient) {</div>
<div class="line"> <span class="comment">// Check for new client connections.</span></div>
<div class="line"> client = server.<a class="code" href="classTerminal.html#a111698c496d601ef7fe0ce4de8a6de9a">available</a>();</div>
<div class="line"> <span class="keywordflow">if</span> (client) {</div>
<div class="line"> haveClient = <span class="keyword">true</span>;</div>
<div class="line"> shell.<a class="code" href="classShell.html#ad9acba905b6e0b661cce19d57c067990">begin</a>(client, 5);</div>
<div class="line"> }</div>
<div class="line"> } <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!client.connected()) {</div>
<div class="line"> <span class="comment">// The current client has been disconnected. Shut down the shell.</span></div>
<div class="line"> shell.<a class="code" href="classShell.html#a8a654aadd0b6a379309bb1007749e41d">end</a>();</div>
<div class="line"> client.stop();</div>
<div class="line"> client = EthernetClient();</div>
<div class="line"> haveClient = <span class="keyword">false</span>;</div>
<div class="line"> }</div>
<div class="line"></div>
<div class="line"> <span class="comment">// Perform periodic shell processing on the active client.</span></div>
<div class="line"> shell.<a class="code" href="classShell.html#afc45cae4ccfc76321a254bb617dce08c">loop</a>();</div>
<div class="line">}</div>
</div><!-- fragment --> </div></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Sun Mar 13 2016 08:28:01 for ArduinoLibs by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.6
</small></address>
</body>
</html>