Introduction: BeatBox: Shock Tracking for Packets With Intel Edison - Intel IOT

Hi everybody

we just came back home after participating to Intel IoT Roadshow (and hackathon) in London.

It was amazing and full of ideas and creative pulls. A very good experience. You should try.

We came as an already formed team and with a very good, but probably too ambitious idea. our team's name was "saveTheWorld".

We had completely no preparation on the board setup, programming and general use, so all we knew, we have learnt during the last weekend.

At the end of saturday we realised that it would be impossible to go on with our project, mainly because we were missing special hardware needed. So we decided to go to sleep. Early next morning another idea came in. It was too late to present it within the roadshow but we decided to complete it and present it through this instructable.

So here we go...

General description

Having worked in companies where fragile good were sent via couriers to customers, one of the problems we faced was the packet "health". Some packets should not be opened, shocked, go beyond or below certain temperatures, and so on.

This device could be included in the expedition to verify whether the package has been wrongly manipulated, and so to refuse the package if tracks of bad handling appear at destination. The version of software we have included now is thought for a express courier company that wants to offer this kind of service to their customer as for quality expeditions.

Step 1: What's the Hardware. Edison Setup Guides and Links

To make our project we had the possibility to use (for prototyping):

The guide to follow to setup the intel edison is the one on the intel site that you can find at the link:

https://software.intel.com/en-us/iot/library/edison-getting-started

It has been very helpful to us. We tested it on the Windows and Mac part, as we had two different laptops with the two different operating systems.

Assemble the board

Install drivers

Update firmware with Flash Tool Lite

Setup a serial terminal

Connect to a network

we stopped here, as we decided to program Edison using Python language, which is embedded in the Yocto Linux environment.

Step 2: Setup Grove Sensor Shield

Grove Sensor Shield is very easy to install from the hardware side.

Just disconnect the board from power, plug the shield and reconnect.

Based on the sensors you are using you must select which voltage you are going to use to power sensors. You can do this by selecting the right voltage on the switch at the bottom right of the board.

From the software point of view this requires a bit more work, but not that much, as the libraries are available for these sensors on the standard "upm" repository for Edison.

  1. Connect to the serial terminal
  2. Login
  3. to see which is the list of available packages type the command
    • opkg list
  4. to install/update the needed package type the following command and hit enter:
    • opkg install upm

Now you are ready to use the grove shield and its sensors.

Step 3: Setup Grove Sensors

It's very simple to set up Grove sensors to the Grove shield. The only thing that should be put attention to is that Analog, Digital or I2C sensors have the same connectors, so it's easy to connect something in the wrong port.

As you can see from the image of the Grove shield you have different names for the available ports.

  • A0...A3 are the analog ports
  • D2...D8 are the digital ports
  • UART is the serial port. Same as available on the digital pins D0 and D1 on the Arduino.
  • I2C are four ports dedicated to the I2C bus

It's very easy to connect sensors, as easy as snapping in the connectors. After connecting the sensors they already have power and ground already connected.

Step 4: Programming With Python

Well... we came to the juicy thing.

First of all ensure yourself that you have correctly installed the last version of firmware and specifically the upgrade of libraries for sensors (last part of stage 1, opkg install upm).

When you have installed everything you can start programming.

I have a windows system, so:

  • I use putty on the COM port found at step 1 (mine is COM3) to launch commands on the Edison board and see outputs on the serial port.
  • I use Notepad++ to write Python code
    • I love the description of this tool that's found on their website (https://notepad-plus-plus.org/): Notepad++ is a free (as in "free speech" and also as in "free beer") source code editor

There are a few additions that can make life easier when programming with Python on the Edison using Notepad++. Especially you can find it useful to have NppFTP, to upload directly using SFTP your code to the Edison board. You can get this extension by clicking on the menu Plugin -> Plugin Manager -> Show Plugin Manager. Then click on the box next to the plugin and install it.

Then you need to connect your SFTP client (now incorporated in Notepad++) to the Edison board.

Find the IP address assigned to your Edison by the WiFi network you are connected to, by using the command ifconfig. Results are shown in the picture. Look for the IP address and put it into the profile settings window.

When you click the "Save" button on the Notepad++ you will save your document right in the folder of your choice and whatever you modify, when you save it you'll save it to its location on the board.

Step 5: Intel IoT Analytics

To get the data automatically saved to the cloud we chose to save them to Intel IoT Analytics.

Instructions to get started with this nice tool can be found at https://software.intel.com/en-us/intel-iot-developer-kit-cloud-based-analytics-user-guide

Once you have set up your account, you can follow the instructions at https://software.intel.com/en-us/node/530661 to:

  • verify that agent is working on your device
  • activate your device
  • register your sensors.

In our case to register sensors I used the following commands:

iotkit-admin register tempMax temperature.v1.0<br>iotkit-admin register tempMin temperature.v1.0 <br>iotkit-admin register micMax micsensor.v1.0<br>iotkit-admin register micMin micsensor.v1.0<br>iotkit-admin register piezoMax piezosensor.v1.0
iotkit-admin register piezoMin piezosensor.v1.0
iotkit-admin register lightMax lightsensor.v1.0
iotkit-admin register lightMin lightsensor.v1.0
iotkit-admin register accMax accelerationmodulesensor.v1.0
iotkit-admin register accMin accelerationmodulesensor.v1.0

Once your sensors are registered you are able to see them in the IoT dashboard.

You will see the list of all the active components for your device.

One thing I found that I think is not very smart for this system is that I have not found a way to delete the registered sensor from the cloud.

You can reset components on the board, but the only way to delete components from the cloud is to delete the board and re-register it from the start. I'd say that this is a point of improvement. In effect you probably noted from my images that I have three piezo components and one of them is clearly wrong (piezoMa is wrong, piezoMax and piezoMin are right).

Just one more thing before you run the code.

Verify that your agent on the Intel Edison board is enabled and the correct ports are started by using the following command

systemctl status iotkit-agent -l

if the agent is correctly activated you will get a response similar to this one:

● iotkit-agent.service - iotkit-agent<br>   Loaded: loaded (/lib/systemd/system/iotkit-agent.service; disabled)
   Active: active (running) since Sun 2015-06-21 07:54:53 UTC; 4s ago
 Main PID: 601 (node)
   CGroup: /system.slice/iotkit-agent.service
           └─601 node /usr/bin/iotkit-agent

Jun 21 07:54:53 edison systemd[1]: Started iotkit-agent.<br>Jun 21 07:54:57 edison iotkit-agent[601]: 2015-06-21T07:54:57.567Z - info: Device has already been activated. Updating ...<br>Jun 21 07:54:57 edison iotkit-agent[601]: 2015-06-21T07:54:57.604Z - info: Updating metadata...<br>Jun 21 07:54:57 edison iotkit-agent[601]: 2015-06-21T07:54:57.657Z - info: Metadata updated.

if it is not activated, you can can see a response like

● iotkit-agent.service - iotkit-agent<br>   Loaded: loaded (/lib/systemd/system/iotkit-agent.service; disabled)
   Active: inactive (dead)

Jun 21 07:25:30 edison systemd[1]: Stopped iotkit-agent.

all you need to do is to start it again by running this command

systemctl start iotkit-agent

Well, now you are ready to start logging.

Step 6: The Code and the Cloud

You can find the Python code at http://pastebin.com/kWW2kHHK

I will complete this part with an in-depth description of the code as soon as possible

When running the code, the system will upload data directly to the cloud. If there is no connection to the cloud, the system will save data from sensors locally with a time stamp and when connection comes back it will send all the saved data to the cloud.

At this point you have your data. They are on the cloud. You can now set an alert if any of the monitored parameters goes beyond its threshold.

You can do this by setting up a rule on the Intel IoT Analytics dashboard.

From the menu in the upper left corner, choose Rules.

You will get a list of the actual rules for the project. I need to point out that if you create a rule and unfortunately you want to delete it after you have deleted the components referred to by that rule, then it's impossible. to do that.

IMHO, the most interesting feature as per the rules is that you can have three types of notifications:

  • email notifications. You will get an email advising that you have had a problem (and which problem)
  • HTTP endpoint. In this way you can send http headers, to update your own control system
  • Actuations. You can instruct any other actuator in your account to do something special

Well... that's all mates.

Enjoy