This guide contains steps to create a touch monitoring application using an Intel® Galileo board or Intel® Edison board. Users of this app can monitor the status of a touch sensor in a remote location with a companion app on their mobile devices. When the sensor is touched, the companion app displays a notification on the mobile device and a buzzer connected to the board sounds. The source code used to read sensor data can be found here: https://github.com/gomobile/iotapp-touch-notifier.

The Touch Notifier sample application code is distributed with the Intel® XDK. It showcases how to read digital data from a Grove* - Touch Sensor, start a web server, and periodically send updates to connected mobile clients using WebSockets. A buzzer alerts the user when the sensor has been touched. This sample application communicates with sensors using the MRAA sensor communication library, which is designed to make it easier for developers and sensor manufacturers to map their sensors and actuators on top of supported hardware and to allow control of low level communication protocol by high level languages and constructs. For more information on MRAA, see https://github.com/intel-iot-devkit/mraa.

The Touch Notifier Companion app is an HTML5 + Cordova* app that communicates with the Touch Notifier application using the WebSockets API. It allows a user to monitor the touch sensor using a mobile device and displays notifications when the sensor is touched. This example uses components from the Grove* - Starter Kit; if you use different components, your code and setup may vary slightly.

Requirements

  • You have installed the Intel XDK and connected it to your board. For steps, see Getting started with the Intel® XDK.
  • Your board must be connected to the Internet.
  • Your Android*, Apple iOS*, or Microsoft Windows* mobile device must be connected to the same network as your board.
  • You must have a Grove* - Base Shield, Grove* - Touch Sensor, Grove* - Buzzer, and two Grove* - Cables.

Assembling your board and sensor components

This section contains steps to connect your board to the touch sensor and buzzer.

  1. Line up the male header pins on the bottom of your base shield with the female pins on the expansion board, as shown in the image below. Once aligned, gently push the base shield down firmly and evenly towards your board until it is securely attached.

    Attaching the base shield to your board
  2. Check that the voltage toggle switch (which is marked VCC and located next to the A0 socket) on the base shield is set to 5V.
  3. Slide the connector on one end of the Grove cable into the socket on your touch sensor until you feel the cable snap into place.

    Attaching the touch sensor to a cable

  4. Slide the other end of the cable into the D2 socket on your base shield until you feel the cable snap into place.

    Attaching the cable to the base shield
  5. Slide the connector on one end of the Grove cable into the socket on your buzzer until you feel the cable snap into place.

    Attaching the buzzer to a cable

  6. Slide the other end of the cable into the D6 socket on your base shield until you feel the cable snap into place.

    Attaching the cable to the base shield

Creating a new project for reading touch sensor data

This section contains steps to use sample code to read data from the touch sensor attached to your board. When someone touches the sensor, you will receive a notification on your mobile device.

  1. Run the Intel XDK.
  2. In the top left, click the Projects tab.
  3. Click Start a New Project.

    Starting a new project

  4. Under Internet of Things Embedded Application, click Templates.

    Creating a project from a template

  5. From the right, click Touch Notifier. Click Continue.

    Select Touch Notifier.

  6. Type a name for the project in the Project Name field, then click Create. Your new project opens.

    Naming your project

  7. Note the IP address of your board, which is displayed in the IoT Device drop-down list at the bottom of the Intel XDK screen.

Uploading the touch sensor code to your board

This section contains steps to build, upload, and run the code to monitor data from the touch sensor.

  1. In the bottom toolbar, click the Upload icon Upload icon to upload the project to your board.

  2. Click the Run icon Run icon to run your project.

Note: If the bottom console window displays a message about being unable to find MRAA, you must update the MRAA library on your board. Do the following:

  1. Open a serial communication session with your board.
  2. Type the following commands:

    echo "src mraa-upm http://iotdk.intel.com/repos/1.1/intelgalactic" > /etc/opkg/mraa-upm.conf
    opkg update
    opkg upgrade

Creating the Touch Notifier Companion app

This section contains steps to create the Touch Notifier Companion app, which allows you to use your mobile device to monitor the touch sensor's readings.

  1. Click the Projects tab.
  2. At the bottom of the left menu, click Start a New Project.
  3. Under HTML5 Companion Hybrid Mobile or Web App, expand Samples and Demos. Click General.

    Creating an HTML5 with Cordova app

  4. From the right under General, select HTML5 and Cordova. Select Touch Notifier Companion App. Click Continue.

    Creating the Touch Notifier Companion app

  5. Type a name for the project in the Project Name field, then click Create. Your new project opens.

Testing the Touch Notifier Companion app in the Intel® XDK

This section contains steps to test your companion app using the Intel XDK's built-in emulator. For steps to test your app directly on a mobile device, see the Testing the Touch Notifier app on your mobile device section.

  1. Click the Emulate tab.
  2. From the Devices drop-down list, select the mobile device that you want to test on. Your app opens.

    Testing an app on the Emulate tab

  3. In the Enter your IoT dev platform's IP Address field, type the IP address of your board.
  4. In the Enter your corresponding port number field, type 1337. Click Submit.
  5. Apply pressure to the touch sensor. The mobile device displays a notification and the buzzer sounds.

Testing the Touch Notification Companion app on your mobile device

This section contains steps to test the companion app on your mobile device. After completing the steps, you will be able to monitor touch sensor readings using your mobile device.

  1. Download and install the Intel® App Preview app on your mobile device using the appropriate link below:
    Google Play icon App Store icon Windows Store icon
  2. In the Intel XDK, click the Test tab.
  3. Click I Have Installed App Preview.

    The Intel App Preview message

  4. If a message is displayed asking you to sync with the testing server, click Sync.

    Syncing with the test server

  5. On your mobile device, run Intel App Preview.

    Intel App Preview welcome screen

  6. On the Welcome screen, choose Login.
  7. Enter the user name and password for your Intel XDK account, then choose Submit to log in.
  8. On the bottom menu bar, choose Server Apps. Select your app, then click the launch button to run the app.

    Launching the app

  9. In the Enter your IoT dev platform's IP Address field, type the IP address of your board.
  10. In the Enter your corresponding port number field, type 1337. Choose Submit.
  11. Apply pressure to the touch sensor. The mobile device displays a notification and the buzzer sounds.

    The mobile device displays notifications when the touch sensor is touched.

Para obter informações mais completas sobre otimizações do compilador, consulte nosso aviso de otimização.