Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / IoT

Mashery APIs with Intel Edison with Intel XDK

0.00/5 (No votes)
10 Dec 2014CPOL3 min read 5.1K  
In this article I will be demonstrating how to create a basic Node.js application using Intel Mashery's JamBase API with Intel Edison and XDK. You will find accompanying GitHub source in the provided repo.

This article is for our sponsors at CodeProject. These articles are intended to provide you with information on products and services that we consider useful and of value to developers

In this article I will be demonstrating how to create a basic Node.js application using Intel Mashery's JamBase API with Intel Edison and XDK. You will find accompanying GitHub source in the provided repo.

Getting Started

First, you will need to install the latest Intel XDK environment. Specifically, you will need the Intel XDK IoT Edition. Once you download and open the package, you will be prompted to create a login (register) or use your existing Intel XDK credentials to get into the application.

Once you have installed Intel XDK, you will need an Intel Edison. If you don't yet have one, you can buy either the Edison starter pack from SparkFun or a smaller breakout board with two Micro-USBs for use with development.

Connecting To Edison Over Your Local Network

Before we get started, we need to ensure that our Intel Edison device will be discoverable over the local network. I recommend making sure that (a) you are on an open wi-fi network with strong signal and (b) that the Wi-Fi you are using does not have "Isolation Mode" turned on, which will make it difficult to pair your computer with your Edison. I won't rehash the documentation for how to get your Intel Edison on the Wi-Fi network as this topic is already well documented online. XDK should automatically detect Edison and provide you with a drop down selection box which you can use to connect to it over the local network.

A Basic IoT Project With Intel XDK

In your Intel XDK environment, click "Start a New Project" -> "Work from an IoT with Node.js Template." This will create a brand new Intel XDK IoT project powered by Node.js. Select the blank template and name it whatever you want to call it. This will create a basic Node.js template for you to use.

Next, Add Useful Node.js Modules

We will need to add a couple Node.js dependencies to make network calls with our Intel Edison via Node.js. Double click and open the "package.json" in the left pane of the XDK workspace and modify it to look like this:

JavaScript
{
  "name": "TestProject",
  "description": "The best Intel Edison Node project ever made",
  "version": "0.0.0",
  "main": "main.js",
  "engines": {
    "node": ">=0.10.0"
  },
  "dependencies": {
      "request":"2.40.x",
      "moment":"2.8.x"
  }
}

Lets Make REST API Calls With Mashery APIs

Next, create a new file "jambase.js" file and edit it to look like this:

JavaScript
// Fetch nearby live music using the JamBase API
var request = require("request");
var moment = require("moment");

var url = "http://api.jambase.com/events"
var api_key = "XXXXXX"
var now = moment().format('YYYY-MM-DD')
var params = {"zipCode":"98102", "radius":"5","startDate":now, "api_key":api_key };

request({
    url: url,
    json: true,
    qs: params
}, function (error, response, body) {
    if (!error && response.statusCode === 200) {
        var entries = body["Events"]
        entries.forEach(function(value) {
          var artists = value["Artists"];
          artists.forEach(function(artist) {
            console.log(artist["Name"]);
          });
          console.log(value["Venue"]["Name"]);
          console.log(value["Date"]);
          console.log(value["TicketUrl"]);
        });
    }
});

Finally, navigate to the JamBase API page and either sign-in or register a new Mashery developer account. Click "My Account" and create a new application by following the provided instructions. Once you have done that, you will be able to swap your key into the above script.

Running Our New JamBase Application

The final step will be to run this program using Intel XDK. Click the "Hammer" aka "Install / Build" Icon to deploy your program to your Intel Edison.Using the terminal, SSH into your Intel Edison over the local network, navigate to the folder containing all your node source code and run "node jambase.js" in the directory. The results should be a list of venues near your current location where musicians are playing.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)