This document will cover the design details of the jxmot/tessel-networking-example project.
Table of contents generated with markdown-toc
Related Documents:
The t2 init
command creates an index.js
file with the following -
'use strict';
// Import the interface to Tessel hardware
const tessel = require('tessel');
// Turn one of the LEDs on to start.
tessel.led[2].on();
// Blink!
setInterval(() => {
tessel.led[2].toggle();
tessel.led[3].toggle();
}, 100);
A variation of that code is used in this application for the purpose of indicating that it is running. Additions to it have included -
- Turning off the GPIO ports, which has the side effect of turning off the PORT A and PORT B LEDs.
- Increasing the blink interval to 500ms.
- Saving the timer id for a subsequent call to
clearInterval()
.
In addition, index.js
has been renamed to tessel-ap-test.js
.
The remainder of the code in tessel-ap-test.js
consistutes the remaining logic code for this application. Here is an overview of its operation :
This application initializes the access point programmatically. Here is an overview of how it's been accomplished :
After the access point has been created and enabled, a periodic call to os.networkInterfaces()
is made and its returned data is checked for the presence of an array labeled as "wlan0"
. When it is present and containing two elements it is evidence that the access point is running and available.
The HTTP server has been implemented as a class. This makes it possible to instantiate more than one server. After a server has been initialized and is listening it can serve resources from one of two locations :
- From the path to the
docroot
, wheredocroot
was one of the arguments used when instantiating this class - From a common path. This path is shared by all instantiated servers. Its purpose is to server up 404 pages and other common file resources.
The userPaths
argument to the httpsrv
class is optional and can be used for providing a function to the server that handles application specific paths and/or endpoints. If it detects and responds to a request the function must return true
. A return of false
will indicate to httpsrv
that the request was not handled and that it should satisfy the request.
When a signal(such as CTRL-C) is received by the application it will halt all interval timers and disable the access point. If this is not done the access point will continue to operate and accept connections even if the application is no longer running.
The following functionality has been added to the Tessel 2 firmware -
- Get/Set the WiFi channel
- Request a list of stations currently connected to the access point
The required modifications are detailed in jxmot/tessel-networking-example/t2mods.md.
© 2018 J.Motyl