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


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

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 "" -O m2x-uptime.rb


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.


Though Raspbian has Python installed, it does not have setuptools ( installed.
So the first step is to install setuptools:

$ wget -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.


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
$ 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 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.js Raspberry Pi 2 & 3 compatible build: 

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[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.