Creating WiFi Pineapple NANO/TETRA Modules
With the new WiFi Pineapple Interface, It is easy to create modules that use the new API. Modules use HTML, AngularJS and PHP to make requests and retrieve a response. The new interface and the modules also use Bootstrap.

ANATOMY OF A BASIC MODULE

A basic module will request information through AngularJS to PHP, and then the PHP will provide a response to AngularJS, where it will then be displayed on the HTML page for the user to see.
1
+-------------------+ +--------------+ +-----------+ +------+
2
| AngularJS Request | --> | PHP Response | --> | AngularJS | --> | HTML |
3
+-------------------+ +--------------+ +-----------+ +------+
Copied!
A module will contain at least four files required to function. A module.html that contains the HTML for the module, A module.infothat contains the name, description, version and author of the module in JSON format, a module.js file inside of the js/ folder that contains the AngularJS, and finally a module.php file inside of the api/ folder. It is structured like this:
1
.
2
├── js
3
│ └── module.js
4
├── module.html
5
├── module.info
6
└── api
7
└── module.php
Copied!
Modules are stored on the WiFi Pineapple at /pineapple/modules/.

CREATING A MODULE

You can create the module files on the WiFi Pineapple with ease using the Module Maker module. It will create the initial files for you (with an example included), and will also allow you to package the module for distribution when you are finished.After downloading the module, enter the correct information into the Name, Description, Version and Author fields and click "Generate". Your module will then be ready to download and edit. Open the module in your favorite text editor.
MODULE.HTML
The WiFi Pineapple modules make use of Bootstrap to provide a good mobile viewing experience and a clean look. Module developers are encouraged to make use of Bootstrap components, such as responsive tables and the grid system. To learn more about Bootstrap, visit the Bootstrap Website.In this example we will make a div that is the width of the webpage. To do this, we will create a row, and then our div element which will use the col-md-12 Bootstrap class.Your code should look like this:
1
<div class="row">
2
<div class="col-md-12">
3
4
</div>
5
</div>
Copied!
As the module is written with AngularJS, the HTML must be hooked up to a controller. For more information on AngularJS, visit the AngularJS website.To hook up the HTML to a controller, we will use our div element with the argument ng-controller="ControllerName". For this example, our controller will be referred to as ExampleController. This div is now able to interact with your AngularJS inside of the module.js file.Your code should now look like this:
1
<div class="row">
2
<div ng-controller="ExampleController" class="col-md-12">
3
4
</div>
5
</div>
Copied!
Finally, we will use an expression called hello. This is done with {{hello}}. Later, we will use this expression to display text from our PHP. You can learn more at AngularJS - Expression.Our HTML code should now look like this:
1
<div class="row">
2
<div ng-controller="ExampleController" class="col-md-12">
3
{{ hello }}
4
</div>
5
</div>
Copied!
MODULE.JS
The module.js contains the AngularJS for your module. As described above, this is the middle "layer" between the HTML and PHP. AngularJS is a Javascript framework created by Google, and allows you to create responsive and dynamic webpages. This is useful with the WiFi Pineapple interface because it lets us update the HTML with changing content.To start, we can use a built in API function, registerController(). This allows us to easily create controllers for our module. An empty controller would look like this:
1
registerController("ExampleController", ['$api', '$scope', function($api, $scope) {
2
3
}])
Copied!
Here we register the name of the controller, "ExampleController". Then we include our dependencies, usually the WiFi Pineapple API, with $api and then the scope of your module, with $scope.Now we will add a variable inside our scope called hello, like so:
1
registerController("ExampleController", ['$api', '$scope', function($api, $scope) {
2
$scope.hello = "Hello World!";
3
}])
Copied!
Our HTML will now output "Hello World!".We can however get dynamic data, passed from our PHP. To do this, we can use the $api.request() function:
1
registerController("ExampleController", ['$api', '$scope', function($api, $scope) {
2
$api.request({
3
module: 'ExampleModule',
4
action: 'getHello'
5
}, function(response) {
6
$scope.hello = response.text;
7
});
8
}])
Copied!
This will send a request to our module.php, and take its response and set $scope.hello to response.text.
MODULE.PHP
The module.php contains all PHP code and can directly interface with other modules, talk to the Javascript and access the WiFi Pineapple API. In this guide, we will finish our Example Module by making it reply to our AngularJS request and return a string containing "Hello World!".To start, we must extend the Module class inside of the pineapple namespace. We must then add the method to handle our requests.:
1
<?php namespace pineapple;
2
3
class ExampleModule extends Module
4
{
5
public function route()
6
{
7
switch ($this->request->action) {
8
case 'getHello':
9
$this->hello();
10
break;
11
}
12
}
13
}
Copied!
This snippet of code will loop over every action it receieves from the Javascript. In our case it is getHello. Once it finds getHello it will execute a function called hello() that we will define next. After the route() function:
1
private function hello()
2
{
3
$this->response = array('text' => "Hello World");
4
}
Copied!
Once this function is executed it will simply create an array with a property called text equaling "Hello World". All together, your code will look like this:
1
<?php namespace pineapple;
2
3
class ExampleModule extends Module
4
{
5
public function route()
6
{
7
switch ($this->request->action) {
8
case 'getHello':
9
$this->hello();
10
break;
11
}
12
}
13
14
private function hello()
15
{
16
$this->response = array('text' => "Hello World");
17
}
18
}
Copied!
Our PHP is now complete, and when the HTML is loaded, it will now display the "Hello World" string from your module.php.