How to connect to the AT&T M2X
service from a Raspberry Pi

Introduction

Raspberry Pi normally runs a slightly modified version of Linux, so you are free to use our Ruby Client, Python Client, C Client or even Node.js Client. We will walk through the steps for each client below.

NOTE: The following instructions are tested on a Raspberry Pi 1, 2 & 3 running Raspbian Jessie Lite. If you are using other distributions, the steps may vary.

Getting Started

  1. 1 Signup for an M2X Account.
  2. 2 Obtain your Master Key from the Master Keys tab of your Account Settings screen.
  3. 3 Create your first Device and copy its Device ID.
  4. 4 Review the M2X API Documentation.
  5. 5 Update Linux distribution packages:
    $ sudo apt-get update && sudo apt-get dist-upgrade
  6. 6 Depending on your language preference, setup the Ruby, Python, C, or Node.js M2X client library on your Raspberry Pi.

Downloading Examples

Each client library contains a subfolder of example scripts which demonstrate how to use the library to interact with the M2X API. Download one or more example scripts to your Raspberry Pi using one of the following methods:

OPTION 1 Download all examples by cloning the client library repository using git:

The following command will clone (ie. download) the Ruby client library, note: git must be installed:

$ git clone https://github.com/attm2x/m2x-ruby.git

OPTION 2 Download a single example script using wget:

The following command demonstrates downloading a single example script (m2x-uptime.rb) from the Ruby client library repository using wget and the file URL that can be obtained from the GitHub UI via the "Raw" link:

$ wget "https://raw.githubusercontent.com/attm2x/m2x-ruby/master/examples/m2x-uptime.rb" -O m2x-uptime.rb

Ruby

First, install Ruby if it is not already installed:

$ sudo apt-get install ruby-full

Next, install the M2X Ruby client via Rubygems:

$ sudo gem install m2x

Please refer to the documentation for the M2X Ruby Client for more details, and try out our example scripts.

Python

Though Raspbian has Python installed, it does not have setuptools (https://pypi.python.org/pypi/setuptools) installed.
So the first step is to install setuptools:

$ wget https://bootstrap.pypa.io/ez_setup.py -O - | sudo python

Install the M2X python client with easy_install:

$ sudo easy_install m2x

Please refer to the documentation for for the M2X Python client for more details, and try out our example scripts.

C

The M2X C client uses libcurl as a dependency and git to clone the client to your Raspberry Pi. So, you'll need to install libcurl and git first:

$ sudo apt-get install libcurl4-openssl-dev git

Then you can clone and build the M2X C library:

$ git clone https://github.com/attm2x/m2x-c
$ cd m2x-c
$ git submodule update --init
$ make

Please refer to the documentation for the M2X C Client for more details, and try out our example scripts.

Node.js

Node.js is not installed by default on Raspbian, but luckily, the official Node.js distribution contains a set of compatible ARM builds. In this example we are using Node.js version 6.3.1, feel free to browse the available Node.js releases if you require a different version.

  • Node.js Raspberry Pi 1 compatible build: 
    node-v6.3.1-linux-armv6l
  • Node.js Raspberry Pi 2 & 3 compatible build: 
    node-v6.3.1-linux-armv7l

Run the following commands, replacing "[node-build]" with the Node.js build that is compatible with the Raspberry Pi generation you are using:

$ sudo mkdir /opt/node
$ wget https://nodejs.org/download/release/v6.3.1/[node-build].tar.gz
$ tar xzf [node-build].tar.gz
$ sudo cp -r [node-build]/* /opt/node
$ echo 'export NODE_JS_HOME="/opt/node"' >> ~/.bashrc
$ echo 'export PATH="$PATH:$NODE_JS_HOME/bin"' >> ~/.bashrc
$ exec $SHELL

Then you can install the M2X Node.js client via npm in the root directory of your project:

$ npm install m2x

Please refer to the documentation for the M2X Node.js Client for more details, and try out our example scripts.