'''If you do not have a Raspberry Pi, you may still work through this tutorial. Connect your Arduino UNO to your computer that has an Internet connection and run the Node.js script on the computer instead of the Raspberry Pi.'''

Step 1: Create and Connect a New Device Type

Go to the Developer Portal to create a private device type.

First, sign into the SAMI Developer Portal. If you don't have a Samsung account, you can create one at this step.

Click "+ New Device Type".

Name this device type "Flame Sensor" and give it the unique name such as "com.example.iot.flame".

Click "Create Device Type". This creates the device type and takes you to the device types page.

Now let's create a Manifest for our "Flame Sensor" device type.

Click "Flame Sensor" in the left column.

Click "Manifest" and then "+ New Version".

Enter "onFire" as the Field Name and "Boolean" for Data Type.

Click "Save" and then "Next: Actions".

Bypass Actions for this tutorial and click "Save New Manifest".

'''A Simple Manifest is automatically approved. Do not publish this device type, since it is for tutorial purposes only.'''

Click the Settings icon of the device you just added. In the pop-up, click "GENERATE DEVICE TOKEN…".

Copy the device ID and device token on this screen. You will use these in the code.

Step 2: Set Up the Arduino

Now let's wire the sensors to the Arduino.

The two sensors are wired as in the Frizting image above.

Next, upload the Sketch program (read_flame_sensor.ino) to the Arduino UNO using the Arduino IDE. This code reads one digital value from the IR flame sensor, and then sends it to the serial port every 5 seconds (you can change this parameter in the code later, since SAMI has rate limits for the number of messages per day). For the digital readings, "0" means that a fire is detected and "1" means no fire.

Step 3: Set Up the Raspberry Pi

Connect your Raspberry Pi to a monitor, mouse and keyboard. Ensure that an Ethernet or WiFi connection is working, and make sure the OS is up-to-date:

$ sudo apt-get update

$ sudo apt-get upgrade

If not already installed, install Node.js for ARM, then add the packages serialport and ws via npm:

$ npm install serialport

$ npm install ws

Now connect the serial port from the Arduino to the USB on the Raspberry Pi.

Finally, download the Node.js code (send_data_to_sami.js) to the Raspberry Pi. Replace the placeholders in the code with the device token and device ID you collected from the User Portal.

The Node.js code is also given below. It establishes a bi-directional WebSocketconnection between the Raspberry Pi and SAMI. After the WebSocket connection is open, register() method registers the device with the WebSocket. Each time, the code reads one data point from the serial port, and then wraps it in a message and sends the message to SAMI via WebSocket.