|
| 1 | +# Close Call Reporter in Python* |
| 2 | + |
| 3 | +## Introduction |
| 4 | + |
| 5 | +This Close Call Reporter application is part of a series of how-to Intel® Internet of Things (IoT) code sample exercises using the Intel® IoT Developer Kit, Intel® Edison development platform, cloud platforms, APIs, and other technologies. |
| 6 | + |
| 7 | +From this exercise, developers will learn how to:<br> |
| 8 | +- Connect the Intel® Edison development platform, a computing platform designed for prototyping and producing IoT and wearable computing products.<br> |
| 9 | +- Interface with the Intel® Edison platform IO and sensor repository using MRAA and UPM from the Intel® IoT Developer Kit, a complete hardware and software solution to help developers explore the IoT and implement innovative projects.<br> |
| 10 | +- Store the Close Call Reporter data using Azure Redis Cache\* from Microsoft\* Azure\*, Redis Store\* from IBM\* Bluemix\*, or ElastiCache\* using Redis\* from Amazon Web Services\* (AWS), different cloud services for connecting IoT solutions including data analysis, machine learning, and a variety of productivity tools to simplify the process of connecting your sensors to the cloud and getting your IoT project up and running quickly. |
| 11 | +- Set up a MQTT-based server using IoT Hub from Microsoft\* Azure\*, IoT from IBM\* Bluemix\*, or IoT from Amazon Web Services\* (AWS), different cloud machine to machine messaging services based on the industry standard MQTT protocol. |
| 12 | + |
| 13 | +## What it is |
| 14 | + |
| 15 | +Using an Intel® Edison board, this project lets you create a close call fleet driving reporter that:<br> |
| 16 | +- monitors the Grove* IR Distance Interrupter.<br> |
| 17 | +- monitors the Grove* GPS.<br> |
| 18 | +- keeps track of close calls and logs them using cloud-based data storage. |
| 19 | + |
| 20 | +## How it works |
| 21 | + |
| 22 | +This close call reporter system monitors the direction the IR Distance sensor is pointed to. |
| 23 | + |
| 24 | +It also keeps track of the GPS position of the Intel® Edison board, updating the position frequently to ensure accurate data. |
| 25 | + |
| 26 | +If a close call is detected (that is, the IR Distance sensor is tripped), the Intel® Edison board, if configured, notifies the Intel® IoT Examples Datastore or an MQTT server running in your own Microsoft\* Azure\*, IBM\* Bluemix\*, or AWS account. |
| 27 | + |
| 28 | +## Hardware requirements |
| 29 | + |
| 30 | +Grove* Transportation and Safety Kit, containing: |
| 31 | + |
| 32 | +1. Intel® Edison with an Arduino* breakout board |
| 33 | +2. [Grove\* IR Distance Interrupter](http://iotdk.intel.com/docs/master/upm/node/classes/rfr359f.html) |
| 34 | +3. [Grove\* GPS](http://iotdk.intel.com/docs/master/upm/node/classes/ublox6.html) |
| 35 | + |
| 36 | +DFRobot* Starter Kit for Intel® Edison, containing: |
| 37 | + |
| 38 | +1. Intel® Edison with an Arduino* breakout board |
| 39 | +2. [IR Distance Sensor](http://www.dfrobot.com/index.php?route=product/product&product_id=572) |
| 40 | +3. [GPS](http://iotdk.intel.com/docs/master/upm/node/classes/ublox6.html) |
| 41 | +4. [I/O Expansion Shield](http://www.dfrobot.com/index.php?route=product/product&product_id=1009) |
| 42 | + |
| 43 | +## Software requirements |
| 44 | + |
| 45 | +1. Microsoft\* Azure\*, IBM\* Bluemix\*, or AWS account (optional) |
| 46 | + |
| 47 | +### How to set up |
| 48 | + |
| 49 | +To begin, clone the **How-To Intel IoT Code Samples** repository with Git* on your computer as follows: |
| 50 | + |
| 51 | + $ git clone https://github.com/intel-iot-devkit/how-to-code-samples.git |
| 52 | + |
| 53 | +To download a .zip file, in your web browser go to <a href="https://github.com/intel-iot-devkit/how-to-code-samples">https://github.com/intel-iot-devkit/how-to-code-samples</a> and click the **Download ZIP** button at the lower right. Once the .zip file is downloaded, uncompress it, and then use the files in the directory for this example. |
| 54 | + |
| 55 | +### Connecting the Grove\* sensors |
| 56 | + |
| 57 | + |
| 58 | + |
| 59 | +You need to have a Grove\* Shield connected to an Arduino\*-compatible breakout board to plug all the Grove devices into the Grove\* Shield. Make sure you have the tiny VCC switch on the Grove\* Shield set to **5V**. |
| 60 | + |
| 61 | +1. Plug one end of a Grove\* cable into the Grove\* PIR Motion Sensor, and connect the other end to the D4 port on the Grove\* Shield. |
| 62 | + |
| 63 | +2. Plug one end of a Grove\* cable into the Grove RGB LCD, and connect the other end to any of the I2C ports on the Grove\* Shield. |
| 64 | + |
| 65 | +### Connecting the DFRobot\* sensors |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +You need to have a LCD Display Shield connected to an Arduino\*-compatible breakout board to plug all the DFRobot\* devices into the LCD Display Shield. |
| 70 | + |
| 71 | +1. Plug one end of a DFRobot\* cable into the PIR (Motion) Sensor, and connect the other end to the A2 port on the LCD Display Shield. |
| 72 | + |
| 73 | +### Intel® Edison board setup |
| 74 | + |
| 75 | +If you're running this code on your Intel® Edison board, you need to install some dependencies by establishing an SSH session to the Edison and run the commands in the sections below. |
| 76 | + |
| 77 | +#### Update the opkg repo |
| 78 | + |
| 79 | +To add the Intel opkg repository: |
| 80 | + |
| 81 | + $ echo "src mraa-upm http://iotdk.intel.com/repos/3.5/intelgalactic/opkg/i586" > /etc/opkg/mraa-upm.conf |
| 82 | + $ opkg update |
| 83 | + |
| 84 | +You'll only need to perform this step once. |
| 85 | + |
| 86 | +#### Git |
| 87 | + |
| 88 | +To install Git\* on the Intel® Edison board (if you don’t have it yet): |
| 89 | + |
| 90 | + $ opkg update |
| 91 | + $ opkg install git |
| 92 | + |
| 93 | +#### MRAA and UPM Dependencies |
| 94 | + |
| 95 | +To install the latest versions of the MRAA\* and UPM\* libraries: |
| 96 | + |
| 97 | + $ opkg update |
| 98 | + $ opkg install mraa |
| 99 | + $ opkg install upm |
| 100 | + |
| 101 | +#### Python Package Manager (pip) |
| 102 | + |
| 103 | +To install the Python\* package manager needed to install and run the example: |
| 104 | + |
| 105 | + $ pip install --upgrade pip setuptools |
| 106 | + |
| 107 | + |
| 108 | +#### Install the example |
| 109 | + |
| 110 | +Once all dependencies are installed you can install the example itself with the following command: |
| 111 | + |
| 112 | + $ pip install --src ~/python/examples/ -e "git+https://github.com/intel-iot-devkit/how-to-code-samples.git#egg=iot_close_call_reporter&subdirectory=close-call-reporter/python" |
| 113 | + |
| 114 | +The `pip` command will install required Python dependencies, save the source code for the example in `~/python/examples/iot_close_call_reporter/` and link the package to the global Python `site-packages` folder. |
| 115 | + |
| 116 | +### Intel® IoT Gateway setup |
| 117 | + |
| 118 | +You can run this example using an Intel® IoT Gateway connected to an Arduino\*/Genuino\* 101. |
| 119 | + |
| 120 | +Make sure your Intel® IoT Gateway is setup, by following the directions on the web site here: |
| 121 | + |
| 122 | +https://software.intel.com/en-us/node/633284 |
| 123 | + |
| 124 | +You must install the Intel® XDK on the Intel® IoT Gateway, by following the directions on the above link, under the section "Connecting to the Intel® XDK". |
| 125 | + |
| 126 | +The Arduino\*/Genuino\* 101 needs to have the Firmata\* firmware installed. If you have IMRAA installed on your gateway, this will be done automatically. Otherwise, install the StandardFirmata or ConfigurableFirmata sketch manully on to your Arduino\*/Genuino\* 101. |
| 127 | + |
| 128 | +You will also need to configure the `config.json` in the example to use the Arduino\*/Genuino\* 101. See the section "Configuring the example" below. |
| 129 | + |
| 130 | +### Data store server setup |
| 131 | + |
| 132 | +Optionally, you can store the data generated by this sample program in a back-end database deployed using Microsoft\* Azure\*, IBM\* Bluemix\*, or AWS, along with Node.js\*, and a Redis\* data store. |
| 133 | + |
| 134 | +For information on how to set up your own cloud data server, go to: |
| 135 | + |
| 136 | +[https://github.com/intel-iot-devkit/intel-iot-examples-datastore](https://github.com/intel-iot-devkit/intel-iot-examples-datastore) |
| 137 | + |
| 138 | +### MQTT server setup |
| 139 | + |
| 140 | +You can also optionally store the data generated by this sample program using MQTT, a machine-to-machine messaging server. You can use MQTT to connect to Microsoft\* Azure\*, IBM\* Bluemix\*, or AWS. |
| 141 | + |
| 142 | +For information on how to connect to your own cloud MQTT messaging server, go to: |
| 143 | + |
| 144 | +[https://github.com/intel-iot-devkit/intel-iot-examples-mqtt](https://github.com/intel-iot-devkit/intel-iot-examples-mqtt) |
| 145 | + |
| 146 | +## Configuring the example |
| 147 | + |
| 148 | +When the example is installed through `pip` the `config.json` file that holds the configuration for the example lives in `~/python/examples/iot_close_call_reporter/close-call-reporter/python/iot_close_call_reporter/config.json`. |
| 149 | + |
| 150 | +To configure the example for the Grove* kit, just leave the `kit` key in the `config.json` set to `grove`. To configure the example for the DFRobot* kit, change the `kit` key in the `config.json` to `dfrobot` as follows: |
| 151 | + |
| 152 | +```JSON |
| 153 | +{ |
| 154 | + "kit": "dfrobot" |
| 155 | +} |
| 156 | +``` |
| 157 | + |
| 158 | +To configure the example for the optional Microsoft\* Azure\*, IBM\* Bluemix\*, or AWS data store, add the `SERVER` and `AUTH_TOKEN` keys in the `config.json` file below the "CODE" key as follows: |
| 159 | + |
| 160 | +```JSON |
| 161 | +{ |
| 162 | + "kit": "grove", |
| 163 | + "SERVER": "http://intel-examples.azurewebsites.net/logger/access-control", |
| 164 | + "AUTH_TOKEN": "s3cr3t" |
| 165 | +} |
| 166 | +``` |
| 167 | + |
| 168 | +For information on how to configure the example for the optional Microsoft\* Azure\*, IBM\* Bluemix\*, or AWS MQTT messaging server, go to: |
| 169 | + |
| 170 | +[https://github.com/intel-iot-devkit/intel-iot-examples-mqtt/](https://github.com/intel-iot-devkit/intel-iot-examples-mqtt/) |
| 171 | + |
| 172 | +## Running the program manually |
| 173 | + |
| 174 | +Once the example is installed through `pip` you can run the program by running the following command in an SSH session to the board: |
| 175 | + |
| 176 | + $ python -m iot_close_call_reporter |
| 177 | + |
| 178 | +### Determining the Intel® Edison board's IP address |
| 179 | + |
| 180 | +You can determine what IP address the Intel® Edison board is connected to by running the following command: |
| 181 | + |
| 182 | + ip addr show | grep wlan |
| 183 | + |
| 184 | +You will see the output similar to the following: |
| 185 | + |
| 186 | + 3: wlan0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 |
| 187 | + inet 192.168.1.13/24 brd 192.168.1.255 scope global wlan0 |
| 188 | + |
| 189 | +The IP address is shown next to `inet`. In the example above, the IP address is `192.168.1.13`. |
| 190 | + |
| 191 | +IMPORTANT NOTICE: This software is sample software. It is not designed or intended for use in any medical, life-saving or life-sustaining systems, transportation systems, nuclear systems, or for any other mission-critical application in which the failure of the system could lead to critical injury or death. The software may not be fully tested and may contain bugs or errors; it may not be intended or suitable for commercial release. No regulatory approvals for the software have been obtained, and therefore software may not be certified for use in certain countries or environments. |
0 commit comments