Getting started with AGILE V2
- 1 UNDER CONSTRUCTION
This is an easy step-by-step guide to build, install and run the AGILE software on your Raspberry Pi 3. We will present:
- How to create an image of AGILE based on the last stable code,
- How to install an image of AGILE on a Raspberry Pi (RPi),
- How to discover and connect a BLE (Bluetooth Low Energy) device to the AGILE gateway,
- Finally, we will test the resulting connection by designing and deploying a Node-RED flow.
This document should work on Mac, Linux or Windows. We made our best to always choose a feature or an application available on all 3 platforms.
What do you need to be able to install an run this Getting Started?
- a PC or a laptop
- a Raspberry Pi 3 Model B (or a Pi 2 with a BLE dongle)
- a microSD reader (or an SD reader and a microSD to SD adapter)
- a good 32GB microSD card, like a Samsung EVO+ or a SanDisk Ultra
- a TI SensorTag
- a LAN that assigns IP addresses through DHCP, to which you are allowed to attach both the laptop and the Raspberry Pi.
Create an AGILE image
Install an AGILE image
We have prepared an image of the AGILE software that contains all the software you need to run this Getting Started and can directly be deployed on a microSD card. Another article will explain how to create such an image, but for now let's use the prepared image.
- Download an AGILE image from the following list . For your information this Getting Started has been tested with the image v0.4.1. It is based on ResinOS.
- Google Drive will inform you that it can't scan this file for viruses. So you will have to trust us on this one ;-), and press the button Download anyway.
- The AGILE image is compressed on a GZip format. Once the image is downloaded, uncompress it with your favorite tool.
- Connect your SD Reader containing your microSD card to your PC/laptop
- To flash your microSD card, you can either
- use your favorite microSD flashing tool,
- learn from this page RPi Easy SD Card Setup,
- use Etcher by Resin.io, the great open source SD burner developed by our project partner Resin.io.
In the next steps, we will describe how to use Etcher to flash your microSD card.
- Download and install Etcher by Resin.io on your PC/laptop. This tool works on Mac, Linux and Windows.
- Launch the Etcher application
- The Etcher UI will ask you first to select the image (.img) you want to flash. Select the image you previously unzipped
- Then the UI will ask you to select the SD Reader. Unless you have several SD readers connected to your machine, you should only have one choice.
- Finally, press the Flash! button to start the transfer.
- Your OS will ask you, at least on MacOS, the Admin credential of your PC/laptop. Complete it to proceed with the burning process.
- Go and grab a coffee. flashing your microSD card will take some time... ;-) Be patient.
Once the flash is complete, close the Etcher app and eject the SD card.
- Once the the flashing is completed, eject the SD reader from your PC/laptop and remove the microSD card from the reader.
- Verify that your RPi is turned OFF
- Slide the microSD card into the RPi microSD driver.
Run the sample
Setup your configuration
- Connect your RPi to the power supply.
You can directly connect it a USB port of your PC/laptop; the RPi will not consume too much power in this case.
- Connect your RPi to your LAN.
You can connect it to your router/switch or, if you have the adapter, you can directly connect it to the RJ45 attached to your PC/laptop
- Once your RPi is started, you should be able to find it on your network under the logical name agilegw.local.
- Open a terminal console
- Ping it:
- $ ping agilegw.local
- Connect to it: > ssh firstname.lastname@example.org ,
- $ ssh email@example.com
- firstname.lastname@example.org's password: agileiot
If it works, you are all set. Else you must investigate your network setup or contact our agile-dev mailing list
Access to the AGILE Web UI
- Open a web browser and access to the following URL: http://agilegw.local:8000
- The web browser will display the AGILE Welcome page. If it doesn't, wait for few more seconds, your image is certainly booting.
- Once you are redirected to the login page. You can use the default user agile and password secret. If by any chance you get some error during login please check https://github.com/Agile-IoT/agile-security/wiki/TroubleShooting
Congratulations! You are connected to your AGILE image!
Discover and connect to the BLE Sensor Tag
- From the top left menu, launch the Device Manager by selecting the menu item Agile > Device Manager
It will open the Device Manager view on the devices currently registered on the platform.
- Click on the Device Manager Setting button and turn on the Device Discovery switch:
- Close the Settings
- It is time to use the TI SensorTag!
Press the PowerOn button on your sensor tag.
The green led should start blinking on the TI SensorTag indicating it is on the Service Discovery mode.
- From the Device Manager view, click on the DISCOVER tab to display all devices AGILE is able to detect.
- Find a device named CC2650 SensorTag. It is your TI SensorTag.
- Press the REGISTER link to connect your Sensor to the AGILE gateway.
It will automatically switch back to the DEVICES list and you should be able to see in the list your tag listed.
- Click on the name CC2650 SensorTag to view the currently available features.
As you can see, the current implementation of this device covers only a subset of the feature actually provided by TI:
- Pressure, and
Build a sample with Node-RED
Node-RED is the developer environment currently used to create AGILE apps.
Now, create a Node-RED flow from scratch by connecting to a Web Socket gathering data from your BLE Sensor and sending them to a MQTT broker to be displayed on a web UI.
- From the AGILE web UI, launch the Node-RED editor by selecting the menu item Agile > NodeRed.
- Look for the websocket input node, on the left section.
- Drag & Drop the websocket node into the current flow.
- Double-click on the node you just dropped to edit it.
- Select Connect to on the Type combo-box field.
- To edit the Path, click on the pencil button; it will open a second editor to specify the WebSocket URL.
- Type the following URL in the Path field:
- replace <rpi.ip> by the IP of your RPi
- and <device ID> by the ID of your TI SensorTag.
You can retrieve the ID of your sensor on the Device Manager. Actually, this is the ID specified in the header of the device:
- Press the Add button to return to the node editor
- Type in the Name field, for example, Temperature
- Press the Done button to save your changes.
- Now you'll add a debug node to display the content of the message payload produced by the websocket node.
- Look for the debug out node, on the left section.
- Drag & Drop the debug node into the current flow.
- Double-click on the debug node to name it Log.
- Connect the output port of the websocket node to the input port of the debug node by dragging between the output port of one to the input port of the other.
- You can already test this flow:
- Press the Deploy button on the top right of the Node-RED editor.
- The flow will have changed a bit: the websocket node informs you it is connected and the debug node is turned ON:
- To see the log, click on the debug tab on the right part of the editor and you will see the displayed trace.
- You can interrupt the log, not the flow, anytime by switching the debug node OFF and re-deploy the flow.
- Proceed by extracting the value of the temperature from the JSON message. For that a function node is needed.
- Once you have drag & dropped a function node into your flow, connect the output port of the websocket (e.g. Temperature) to the input port of the function node.
- Double-click on the function node to edit it.
- Name the node Extract Temperature.
- var json = JSON.parse(msg.payload);
- msg.payload = json.value;
- return msg;
- Press the Done button to close the function editor.
- Feel free to redirect the output port to the debug node to verify that the code you wrote extracts properly the value of the temperature.
- This value will now be pushed to an MQTT broker on the cloud to be able to subscribe to this data stream from any MQTT client. To do that, an MQTT out node needs to be added to our current flow.
- Double-click on the MQTT out node to edit it.
- For the Server field, click on the pencil button to specify the MQTT broker you want to reach.
- For the purpose of this Getting Started, we will designate the Eclipse IoT MQTT broker by specifying iot.eclipse.org in the Server field.
- Leave the port number (1883) unchanged and close this dialog by pressing the Add button.
- You should be back at the MQTT out node editor. On the Topic field, type the following topic name:
This ID could be simpler but we wanted to be able to reuse an existing ID. MQTT client demo, we have to use this syntax.
- At this point name the node, for example, iot.eclipse.org, and close the editor by pressing the Done button.
- You still need to connect to output port of your function node to the input port of the MQTT out node and you should be all set.
- Now you can deploy the resulting flow by clicking Deploy on the top right and you should be all set.
Connect to the MQTT brokerAt this point, the sample is collecting temperature data from the Sensor and it is sending them to a MQTT broker on the cloud.
- You can directly test if the sample works properly by opening this page from any web browser: https://iot.eclipse.org/java/demo/app/#/greenhouses/remote/agile. It will open a web page with the following dashboard:
- If you warm up your TI SensorTag, the dashboard should display a new value.
- You can also test this URL from your smartphone, you will be able to access to the same realtime value
If the UI doesn't behave as expected, maybe somebody else is already running this Getting Started. In this case, we recommend you to change the MQTT broker topic we defined in the previous section for something else. Actually, the only token you can really change in the provided syntax will be the "agile" name in "javaonedemo/agile/sensors/temperature". For example, you could change to "javaonedemo/agile-01/sensors/temperature". In this case, the URL to reach your temperature sensor will have to change as well for https://iot.eclipse.org/java/demo/app/#/greenhouses/remote/agile-01. Don't forget to re-deploy your flow.