<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Austin Spivey</title>
    <description>The latest articles on DEV Community by Austin Spivey (@anspivey).</description>
    <link>https://dev.to/anspivey</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F49562%2F1b225489-35d3-4324-a888-a4b11a57be81.jpg</url>
      <title>DEV Community: Austin Spivey</title>
      <link>https://dev.to/anspivey</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/anspivey"/>
    <language>en</language>
    <item>
      <title>How to build your own security system using Android Things</title>
      <dc:creator>Austin Spivey</dc:creator>
      <pubDate>Wed, 15 Aug 2018 18:06:46 +0000</pubDate>
      <link>https://dev.to/wiaio/how-to-build-your-own-security-system-using-android-things-3n0m</link>
      <guid>https://dev.to/wiaio/how-to-build-your-own-security-system-using-android-things-3n0m</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-03%2F1533309078-317025-blog-06.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-03%2F1533309078-317025-blog-06.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we will send an event to Wia using Android Things.&lt;/p&gt;

&lt;h1&gt;
  
  
  Components
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Raspberry Pi (We used a Raspberry Pi 3 Model B) &lt;/li&gt;
&lt;li&gt;PIR Sensor&lt;/li&gt;
&lt;li&gt;USB Cable&lt;/li&gt;
&lt;li&gt;Jumper wires&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You will also need Android Studio and a Wia account. &lt;a href="https://developer.android.com/studio/" rel="noopener noreferrer"&gt;You can download the latest version of Android Studio here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Wia is a cloud platform to support your Internet of Things devices. &lt;a href="https://dashboard.wia.io/login" rel="noopener noreferrer"&gt;You can sign up or login here&lt;/a&gt;. &lt;/p&gt;

&lt;h1&gt;
  
  
  Getting Started
&lt;/h1&gt;

&lt;p&gt;First, we need to install Android Things onto the raspberry pi. &lt;a href="https://partner.android.com/things/console/u/0/#/" rel="noopener noreferrer"&gt;Click here&lt;/a&gt; to go to the Android Things console, and sign in using a google account. &lt;/p&gt;

&lt;p&gt;Create a product and choose &lt;strong&gt;Raspberry Pi&lt;/strong&gt; as the &lt;strong&gt;SOM&lt;/strong&gt;, name it what you like, and save. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533131995-548060-screen-shot-2018-08-01-at-25933-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533131995-548060-screen-shot-2018-08-01-at-25933-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You will be taken to this page. Click on your model: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132122-102564-screen-shot-2018-08-01-at-30010-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132122-102564-screen-shot-2018-08-01-at-30010-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click on &lt;strong&gt;NEW&lt;/strong&gt; and choose &lt;strong&gt;Start from scratch&lt;/strong&gt; from the drop down menu. &lt;/p&gt;

&lt;p&gt;Name your build. Keep all of the default settings by clicking &lt;strong&gt;Next&lt;/strong&gt; on each step. Then click &lt;strong&gt;create build&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;Your build is now available for download. Download the file and choose &lt;strong&gt;production&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132100-517306-screen-shot-2018-08-01-at-30103-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132100-517306-screen-shot-2018-08-01-at-30103-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once the file has downloaded, unzip it. The file will take a moment to expand. You will get a &lt;strong&gt;.img&lt;/strong&gt; file. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132176-964916-screen-shot-2018-08-01-at-30241-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132176-964916-screen-shot-2018-08-01-at-30241-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Burning the SD Card
&lt;/h1&gt;

&lt;p&gt;Next, burn the image to the SD card. We used Etcher to do this. &lt;a href="https://etcher.io/" rel="noopener noreferrer"&gt;You can download Etcher here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Insert the SD card into your computer and open Etcher. Select the image we just downloaded and select the SD card, then click &lt;strong&gt;Flash&lt;/strong&gt;. Then, remove the SD card from your computer and insert it into the raspberry pi. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132222-990367-screen-shot-2018-08-01-at-30326-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132222-990367-screen-shot-2018-08-01-at-30326-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connect the raspberry pi to an ethernet cable and use a USB to connect the raspberry pi to a 5V power source. Use an HDMI to connect the raspberry pi to a monitor and obtain the &lt;strong&gt;IP address.&lt;/strong&gt; You will need the IP address later. &lt;/p&gt;

&lt;h1&gt;
  
  
  Wiring the Hardware
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533134177-53230-screen-shot-2018-08-01-at-33529-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533134177-53230-screen-shot-2018-08-01-at-33529-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Use this diagram to help you connect the hardware: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132310-633379-download.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132310-633379-download.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Connect a USB to the raspberry pi and your computer. Connect the HDMI cable to a monitor and the raspberry pi. &lt;/p&gt;

&lt;h1&gt;
  
  
  Set up your space in Wia
&lt;/h1&gt;

&lt;p&gt;If you don't already have a Wia account, &lt;a href="https://dashboard.wia.io/login" rel="noopener noreferrer"&gt;you can sign up here, it's free&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;In the Wia dashboard, click &lt;code&gt;Create a New Space&lt;/code&gt;. In the left sidebar, navigate to &lt;code&gt;Devices&lt;/code&gt; and click &lt;code&gt;Add Device&lt;/code&gt;. We used the Raspberry Pi 3 Model B. Name your device anything you like. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132397-627866-screen-shot-2018-08-01-at-30609-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132397-627866-screen-shot-2018-08-01-at-30609-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once your device is added, navigate to the &lt;code&gt;Configuration&lt;/code&gt; tab. Here you will find your device's secret key, which starts with &lt;code&gt;d_sk&lt;/code&gt;. You will need this key later. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132433-657688-screen-shot-2018-08-01-at-30656-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132433-657688-screen-shot-2018-08-01-at-30656-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  Development
&lt;/h1&gt;

&lt;p&gt;Open Android Studio and start a new project. Fill in the required fields: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132537-600290-screen-shot-2018-08-01-at-30837-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132537-600290-screen-shot-2018-08-01-at-30837-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click next. For the target devices, select only &lt;strong&gt;Android Things&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132621-852102-screen-shot-2018-08-01-at-30923-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132621-852102-screen-shot-2018-08-01-at-30923-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click next. Choose &lt;strong&gt;Empty Activity&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132671-628979-screen-shot-2018-08-01-at-31037-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132671-628979-screen-shot-2018-08-01-at-31037-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click next and then Finish. &lt;/p&gt;

&lt;p&gt;In the left sidebar, click &lt;code&gt;Gradle Scripts &amp;gt; build.gradle (Module: app)&lt;/code&gt;, and enter this line of code in dependencies: &lt;/p&gt;

&lt;p&gt;&lt;code&gt;implementation 'io.wia:wia-android-sdk:0.3.1'&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Your screen should look like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132806-636386-screen-shot-2018-08-01-at-31308-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533132806-636386-screen-shot-2018-08-01-at-31308-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, it's time to connect the raspberry pi to our project. You need to know the IP address of the raspberry pi for this step. In the terminal, run this command:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;adb connect Your-Raspberry-Pi-IP-address)&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Open Android Studio. Copy and paste this code into MainActivity.java:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import android.app.Activity;
import android.os.Bundle;

import android.util.Log;

import com.google.android.things.pio.Gpio;
import com.google.android.things.pio.PeripheralManager;


import io.reactivex.Observable;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import io.wia.Wia;

import io.wia.WiaEvent;


public class MainActivity extends Activity implements MotionsSensor.Listener {

    private static final String GPIO_PIN = "BCM18";
    private PirMotionSensor motionSensor;
    private static final String TAG = "TEST";
    private Gpio mGpio;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        PeripheralManager pms = PeripheralManager.getInstance();
        try {
            mGpio = pms.openGpio(GPIO_PIN);
            motionSensor = new PirMotionSensor(mGpio, this);
            motionSensor.startup();
        } catch (Exception ex) {
            Log.d(TAG, "failing", ex);
        }
        Log.d(TAG, "IN ON CREATE FUNCTION.");

        Wia.initialize(new Wia.Configuration.Builder(this.getApplicationContext())
                .server("https://api.wia.io/v1")
                .build()
        );
        //replace this with your own device secret key 
        Wia.accessToken("your-device-secret-key");

    }

    @Override
    public void onMovement() {
        Log.d(TAG, "in onMovement");
        Log.d(TAG, "MOVEMENT DETECTED");
        Observable&amp;lt;WiaEvent&amp;gt; result = Wia.createEvent("motion");
        result.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(response -&amp;gt; {
                    Log.d(TAG, "In onMovement function");
                }, error -&amp;gt; {
                    Log.d(TAG, "ERROR IN MOVEMENT EVENT");
                });
    }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the code, locate this line, around line 45 in Android Studio:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//replace this with your own device secret key 
        Wia.accessToken("your-device-secret-key");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change &lt;code&gt;"your-device-secret-key"&lt;/code&gt; to your own device secret key. This can be found in the Wia Dashboard in your space &amp;gt; device &amp;gt; configurations. The key starts with &lt;code&gt;d_sk&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;In the left hand menu, navigate to &lt;code&gt;App &amp;gt; Java&lt;/code&gt; and right click on the package name. Choose &lt;code&gt;New &amp;gt; New Java Class&lt;/code&gt; and name it &lt;code&gt;PirMotionSensor&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533133032-750953-screen-shot-2018-08-01-at-31653-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533133032-750953-screen-shot-2018-08-01-at-31653-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, copy and paste this code into the class &lt;code&gt;PirMotionSensor&lt;/code&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
import android.util.Log;

import com.google.android.things.pio.Gpio;
import com.google.android.things.pio.GpioCallback;

import java.io.IOException;

public class PirMotionSensor implements MotionsSensor {
    private final Gpio bus;
    private final MotionsSensor.Listener listener;

    PirMotionSensor(Gpio bus, Listener listener) {
        this.bus = bus;
        this.listener = listener;
    }

    @Override
    public void startup() {
        try {
            bus.setDirection(Gpio.DIRECTION_IN);
            bus.setActiveType(Gpio.ACTIVE_HIGH);
            bus.setEdgeTriggerType(Gpio.EDGE_FALLING);
        } catch (IOException e) {
            throw new IllegalStateException("Sensor can't start", e);
        }
        try {
            bus.registerGpioCallback(callback);
        } catch (IOException e) {
            throw new IllegalStateException("Sensor can't register callback", e);
        }
    }

    private final GpioCallback callback = new GpioCallback() {
        @Override
        public boolean onGpioEdge(Gpio gpio) {
            listener.onMovement();
            return true; // True to continue listening
        }
    };

    @Override
    public void shutdown() {
        bus.unregisterGpioCallback(callback);
        try {
            bus.close();
        } catch (IOException e) {
            Log.e("TEST", "Failed to shut down. You might get errors next time you try to start.", e);
        }
    }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the lefthand menu, navigate again to &lt;code&gt;App &amp;gt; Java&lt;/code&gt; and right click on the package name. Choose &lt;code&gt;New &amp;gt; New Java Class&lt;/code&gt;. In the pop-up screen, change the field &lt;code&gt;Kind&lt;/code&gt; to &lt;code&gt;Interface&lt;/code&gt; instead of &lt;code&gt;Class&lt;/code&gt;. Name the interface &lt;code&gt;MotionsSensor&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533133111-288389-screen-shot-2018-08-01-at-31817-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533133111-288389-screen-shot-2018-08-01-at-31817-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, copy and paste this code into the interface:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface MotionsSensor {
    void startup();

    void shutdown();

    interface Listener {
        void onMovement();
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Click run and in the next screen choose &lt;code&gt;Google_Iot_rpi3&lt;/code&gt; as the device. &lt;/p&gt;

&lt;p&gt;Go back to the &lt;a href="https://dashboard.wia.io/login" rel="noopener noreferrer"&gt;Wia Dashboard&lt;/a&gt;. In the debugger tab, you can see your events appearing in real time! Each time motion is detected, and event is being sent to Wia. &lt;/p&gt;

&lt;p&gt;To take this a step farther, you can use the &lt;a href="https://dashboard.wia.io/login" rel="noopener noreferrer"&gt;Wia platform&lt;/a&gt; to send you a notification when motion is detected. &lt;/p&gt;

&lt;h1&gt;
  
  
  Wia Flows
&lt;/h1&gt;

&lt;p&gt;In the left sidebar, navigate to &lt;code&gt;Flows&lt;/code&gt; and add a new flow. Name it anything you like. From the &lt;code&gt;Trigger&lt;/code&gt; tab, drag over a &lt;code&gt;Create Event&lt;/code&gt; node. Name this node &lt;code&gt;motion&lt;/code&gt; and select your device. &lt;/p&gt;

&lt;p&gt;Next, in the &lt;code&gt;Logic&lt;/code&gt; tab, drag over a &lt;code&gt;run-function&lt;/code&gt; node. Copy and paste this code into the box:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (input.body.name == "motion") { 
  output.body.data = "motion detected"; 
}
else {
  output.body.data = "no motion"; 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Connect the nodes by dragging the orange dots. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533133364-116441-screen-shot-2018-08-01-at-32226-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533133364-116441-screen-shot-2018-08-01-at-32226-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, in the &lt;code&gt;Action&lt;/code&gt; tab, drag over a &lt;code&gt;Notification&lt;/code&gt; node. Enter "Motion detected!" as the message. When motion is detected, this flow will send a notification to the Wia mobile app. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533133387-403898-screen-shot-2018-08-01-at-32255-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-01%2F1533133387-403898-screen-shot-2018-08-01-at-32255-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  PIR Sensor Sensitivity Measures
&lt;/h4&gt;

&lt;p&gt;The PIR Sensor allows you to change the Delay Time as well as the Sensitivty Level.&lt;/p&gt;

&lt;p&gt;The PIR Sensor is a digital device. This means that it reads two values: HIGH and LOW. When the sensor detects movement, it reads HIGH. Otherwise, it reads LOW.&lt;/p&gt;

&lt;p&gt;The Delay setting determines how long the PIR Sensor will read HIGH after it has detected a motion. The Sensitivity Sensor determines the proximity at which the PIR Sensor will register a movement. This sensor is more accurate when it is set to a lower proximity level. You can control these settings using the orange panels located directly across from the pins you used to wire your device. &lt;/p&gt;

</description>
      <category>iot</category>
      <category>opensource</category>
      <category>tutorial</category>
      <category>platform</category>
    </item>
    <item>
      <title>How to connect a Sigfox Sens'It to Wia</title>
      <dc:creator>Austin Spivey</dc:creator>
      <pubDate>Wed, 15 Aug 2018 17:07:28 +0000</pubDate>
      <link>https://dev.to/wiaio/how-to-connect-a-sigfox-sensit-to-wia-338b</link>
      <guid>https://dev.to/wiaio/how-to-connect-a-sigfox-sensit-to-wia-338b</guid>
      <description>&lt;p&gt;In this tutorial, we will connect the Sigfox Sens'It to the &lt;a href="https://dashboard.wia.io/login" rel="noopener noreferrer"&gt;Wia platform&lt;/a&gt;. &lt;/p&gt;

&lt;h1&gt;
  
  
  Components
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Wia Account. &lt;a href="https://dashboard.wia.io/login" rel="noopener noreferrer"&gt;You can create one here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Sigfox Sens'It &lt;/li&gt;
&lt;li&gt;USB to Micro USB Cable &lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Connect the Sens'It to the Sigfox App
&lt;/h1&gt;

&lt;p&gt;First, plug in your Sens 'It to ensure it stays charged. Then, &lt;a href="https://www.sensit.io/" rel="noopener noreferrer"&gt;follow this link&lt;/a&gt; to Sigfox's platform for the Sens 'It. In the upper right corner, click &lt;code&gt;Launch App&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655169-784073-screen-shot-2018-08-07-at-41907-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655169-784073-screen-shot-2018-08-07-at-41907-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose to &lt;code&gt;Activate a Sens'It&lt;/code&gt;. The Device ID is written on the back of the Sens'It. Enter the Device ID into the box. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655215-294134-screen-shot-2018-08-07-at-41958-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655215-294134-screen-shot-2018-08-07-at-41958-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655285-442484-screen-shot-2018-08-07-at-42036-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655285-442484-screen-shot-2018-08-07-at-42036-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Continue and add your location. Follow the prompts to finish activating the Sens'It. &lt;/p&gt;

&lt;h1&gt;
  
  
  Get the PAC
&lt;/h1&gt;

&lt;p&gt;Once the Sens'It is activated, &lt;a href="https://www.sensit.io/app/sensit" rel="noopener noreferrer"&gt;launch the app&lt;/a&gt;. In the left side menu, select the name of your device. Then, in the upper right corner, select &lt;code&gt;Sens'It details&lt;/code&gt;  &lt;/p&gt;

&lt;p&gt;On the right bottom of the page, click the blue button for &lt;code&gt;Get my PAC&lt;/code&gt;. The next display will show your PAC. You will need this later. &lt;/p&gt;

&lt;h1&gt;
  
  
  Connect the Sens'It to the Sigfox Backend
&lt;/h1&gt;

&lt;p&gt;&lt;a href="https://buy.sigfox.com/activate" rel="noopener noreferrer"&gt;Follow this link&lt;/a&gt; to register your device so you can configure it in the Sigfox backend. Enter your location and click &lt;code&gt;Next&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;You will be prompted to enter your &lt;code&gt;Device ID&lt;/code&gt; and &lt;code&gt;PAC&lt;/code&gt;. The Device ID is the number on the back of the Sens'It. The PAC is the sequence we found in the last step. &lt;/p&gt;

&lt;p&gt;Continue to the &lt;code&gt;Account&lt;/code&gt; step and create an account. Finish and confirm.  &lt;/p&gt;

&lt;p&gt;Now, &lt;a href="https://backend.sigfox.com/auth/login" rel="noopener noreferrer"&gt;follow this link&lt;/a&gt; to the Sigfox backend. Enter your login details for the account you just created. &lt;/p&gt;

&lt;h1&gt;
  
  
  Send events to Wia
&lt;/h1&gt;

&lt;p&gt;Wia has a Sigfox integration available, so you can connect your sigfox device to the &lt;a href="https://dashboard.wia.io/login" rel="noopener noreferrer"&gt;Wia platform&lt;/a&gt;. &lt;/p&gt;

&lt;h3&gt;
  
  
  Create API Keys
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; In the Sigfox backend, go to &lt;code&gt;Group &amp;gt; [Your group name] &amp;gt; API Access &amp;gt; New&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Select &lt;code&gt;DEVICES_MESSAGES [R]&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655451-320043-screen-shot-2018-08-07-at-42341-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655451-320043-screen-shot-2018-08-07-at-42341-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once checked, an API login and password will be created for you.&lt;/p&gt;

&lt;h3&gt;
  
  
  Add API Keys to Wia
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; Go to the &lt;a href="https://dashboard.wia.io/login" rel="noopener noreferrer"&gt;Wia dashboard&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt; Open the Space dropdown, by clicking on the Space name in the top left corner, and click Settings. Select Integrations in the sidebar.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655515-324090-screen-shot-2018-08-07-at-42441-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655515-324090-screen-shot-2018-08-07-at-42441-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Enter your API Access Login and Password. Note: This is not the one you use to login to the Sigfox backend dashboard, it is the one you just created.&lt;/li&gt;
&lt;li&gt; You should now see your Inbound Key for Sigfox created.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655560-510857-screen-shot-2018-08-07-at-42535-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655560-510857-screen-shot-2018-08-07-at-42535-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Setup your Sigfox Callback
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt; Go back to the &lt;a href="https://backend.sigfox.com/auth/login" rel="noopener noreferrer"&gt;Sigfox backend&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt; Select &lt;code&gt;Device Type&lt;/code&gt;, then under name column of the device type list you would like to integrate&lt;/li&gt;
&lt;li&gt; On the left, select Callbacks (If there are any Wia callbacks already there, remove them)&lt;/li&gt;
&lt;li&gt; Click New in the top left corner to create a new callback&lt;/li&gt;
&lt;li&gt; Select Custom Callback&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655632-231271-screen-shot-2018-08-07-at-42649-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655632-231271-screen-shot-2018-08-07-at-42649-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Enter the values below in each of the fields: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Type: &lt;code&gt;DATA&lt;/code&gt; &lt;code&gt;UPLINK&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Channel: &lt;code&gt;URL&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Url pattern: &lt;code&gt;https://api.wia.io/v1/events&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Use HTTP method: &lt;code&gt;POST&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Headers &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655659-973650-screen-shot-2018-08-07-at-42725-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533655659-973650-screen-shot-2018-08-07-at-42725-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt; Content Type: &lt;code&gt;application/json&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt; Body: Copy and paste the text below.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
  "integrations":{
    "sigfox":{
      "id":"{device}"
    }
  },
  "name":"sigfoxDataUplink",
  "data":{
    "sigfoxData":"{data}",
    "time":"{time}",
    "duplicate":"{duplicate}",
    "snr":"{snr}",
    "station":"{station}",
    "avgSnr":"{avgSnr}",
    "lat":"{lat}",
    "lng":"{lng}",
    "rssi":"{rssi}",
    "seqNumber":"{seqNumber}"
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Click &lt;code&gt;OK&lt;/code&gt; to save the callback.&lt;/p&gt;

&lt;p&gt;Once your device sends an event it will automatically appear in the &lt;a href="https://dashboard.wia.io/login" rel="noopener noreferrer"&gt;Wia dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533656741-178661-screen-shot-2018-08-07-at-44456-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-08-07%2F1533656741-178661-screen-shot-2018-08-07-at-44456-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>iot</category>
      <category>opensource</category>
      <category>sigfox</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Build a smart mailbox with a Sigfox and Pycom</title>
      <dc:creator>Austin Spivey</dc:creator>
      <pubDate>Thu, 26 Jul 2018 14:50:09 +0000</pubDate>
      <link>https://dev.to/wiaio/build-a-smart-mailbox-with-a-sigfox-and-pycom-167</link>
      <guid>https://dev.to/wiaio/build-a-smart-mailbox-with-a-sigfox-and-pycom-167</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-13%2F1531496045-733399-smart-mailbox-sigfox-pycom.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-13%2F1531496045-733399-smart-mailbox-sigfox-pycom.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Hi folks,&lt;/p&gt;

&lt;p&gt;Today I’m going to show you how to create a Sigfox mail notifier using Wia and the Pycom SiPy.&lt;/p&gt;

&lt;p&gt;This tutorial assumes that you have already connected Sigfox to Wia if you haven’t, please click &lt;a href="https://developers.wia.io/v1.0/docs/pycom-sipy" rel="noopener noreferrer"&gt;here&lt;/a&gt; to find a tutorial for initial Sigfox setup and publishing data to Wia.&lt;/p&gt;

&lt;h1&gt;
  
  
  Components
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pycom.io/hardware/sipy-specs/" rel="noopener noreferrer"&gt;Pycom SiPy&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pycom.io/product/expansion-board-3-0/" rel="noopener noreferrer"&gt;Pycom Expansion Board&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Sigfox compatible antenna&lt;/li&gt;
&lt;li&gt;Mobile device (iOS or Android)&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.amazon.co.uk/ELEGOO-Ultrasonic-Raspberry-Datasheet-Available/dp/B01M0QL1F1/ref=sr_1_3?ie=UTF8&amp;amp;qid=1531485159&amp;amp;sr=8-3&amp;amp;keywords=hc-sr04" rel="noopener noreferrer"&gt;HC-SR04 ultrasonic sensor&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Setup your board
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Connect the SiPy to the Expansion board. (The Pycom logos should face the same way)&lt;/li&gt;
&lt;li&gt;Connect the Sigfox antenna to the SiPy. The connection is the small gold circle on the bottom left of the SiPy board. Simply snap the antenna in place.
[upl-image-preview url=&lt;a href="https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-07-13/1531486321-146149-sipy-antenna.png" rel="noopener noreferrer"&gt;https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-07-13/1531486321-146149-sipy-antenna.png&lt;/a&gt;]&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For the HC-SR04 ultrasonic sensor, you'll need to connect the following pins to the Pycom SiPy:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;HC-SR0 | Pycom&lt;/li&gt;
&lt;li&gt; Vcc -&amp;gt; Vin&lt;/li&gt;
&lt;li&gt; Trig -&amp;gt; G8&lt;/li&gt;
&lt;li&gt; echo -&amp;gt; G7&lt;/li&gt;
&lt;li&gt; Gnd -&amp;gt; GND&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Setup Your Project
&lt;/h1&gt;

&lt;p&gt;In Atom:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new folder for your project. I'm going to call mine sigfox-mailbox&lt;/li&gt;
&lt;li&gt;&lt;p&gt;In &lt;a href="https://atom.io/" rel="noopener noreferrer"&gt;Atom&lt;/a&gt;, go to &lt;code&gt;File &amp;gt; New Window&lt;/code&gt; to open a new window&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add your newly created folder by clicking &lt;code&gt;File &amp;gt; Add Project Folder&lt;/code&gt; and navigating to it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;If the &lt;a href="https://atom.io/packages/pymakr" rel="noopener noreferrer"&gt;Pymakr&lt;/a&gt; plugin is not open at the bottom of your Atom window, click on the arrow on the right hand side to open it&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Select &lt;code&gt;Settings &amp;gt; Project Settings&lt;/code&gt;. In the address field replace the value with the device name from the step above e.g. &lt;code&gt;/dev/tty.usbmodemPy343431&lt;/code&gt; (Mac OS X), &lt;code&gt;COM3&lt;/code&gt; (Windows), &lt;code&gt;/dev/ttyACM0&lt;/code&gt; (Linux) then save the file&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Publish a sigfox Event for our mail
&lt;/h1&gt;

&lt;p&gt;We'll need three files for our application:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;boot.py&lt;/code&gt; which is run when the device is powered up&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;main.py&lt;/code&gt; which is where our main code is&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ultrasonic.py&lt;/code&gt; is where is our functions for obtaining distance and calibration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Atom: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Right click on your project and click New File. Enter &lt;code&gt;boot.py&lt;/code&gt; as the filename&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy and paste the code below into the file&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from machine import UART
import machine
import os

uart = UART(0, baudrate=115200)
os.dupterm(uart)

machine.main('main.py')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Right click on your project and click New File. Enter &lt;code&gt;main.py&lt;/code&gt; as the filename&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy and paste the code below into the file&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import time
import pycom
import socket
from network import Sigfox
from machine import Pin, Timer
import ultrasonic


pycom.heartbeat(False)

echo = Pin(Pin.exp_board.G7, mode=Pin.IN)
trigger = Pin(Pin.exp_board.G8, mode=Pin.OUT)
trigger(0)

# Get the chronometer object
chrono = Timer.Chrono()

# init Sigfox for RCZ1 (Europe)
sigfox = Sigfox(mode=Sigfox.SIGFOX, rcz=Sigfox.RCZ1)
# create a Sigfox socket
s = socket.socket(socket.AF_SIGFOX, socket.SOCK_RAW)
# make the socket blocking
s.setblocking(True)
# configure it as uplink only
s.setsockopt(socket.SOL_SIGFOX, socket.SO_RX, False)


calibrated_distance = ultrasonic.calibration(chrono, trigger, echo, 1)
mailed_distance = 0
while True:
    time.sleep(30)
    distance = ultrasonic.getDistance(chrono, trigger, echo)
    print("distance: {}, calibration: {}".format(distance, calibrated_distance))
    if distance &amp;lt; calibrated_distance:
        if distance != mailed_distance:
            s.send('') # Send 1 bit
            print("you got mail")
            mailed_distance = ultrasonic.calibration(chrono, trigger, echo)

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Right click on your project and click New File. Enter &lt;code&gt;ultrasonic.py&lt;/code&gt; as the filename&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Copy and paste the code below into the file&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from machine import Pin, Timer
import pycom
import time
import socket

def calibration(chrono, trigger, echo, led = False):
    if led:
        pycom.rgbled(0x7f0000) # red
    prev_distance = 0
    distance = getDistance(chrono, trigger, echo)
    print("calibration distance is {}".format(distance))
    count = 0
    while True:
        prev_distance = distance
        distance = getDistance(chrono, trigger, echo)
        while prev_distance == distance:
            count+=1
            print("count: {}".format(count))
            if count &amp;gt; 5:
                if led:
                    pycom.rgbled(0x007f00) # green
                    time.sleep(1.5)
                    pycom.rgbled(0) # off
                return distance
            time.sleep(5)
            prev_distance = distance
            distance = getDistance(chrono, trigger, echo)
        else:
            count = 0

def getDistance(chrono, trigger, echo):
    chrono.reset()
    trigger(1)
    time.sleep_us(10)
    trigger(0)

    while echo() == 0:
        pass
    chrono.start()

    while echo() == 1:
        pass
    chrono.stop()

    distance = chrono.read_us() / 58.0
    if distance &amp;gt; 400:
        return -1
    else:
        return int(distance)

    time.sleep(1)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your folder structure should now look like this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ultrasonic.py&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;boot.py&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;main.py&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Click &lt;code&gt;Upload&lt;/code&gt; in the Pymakr plugin at the bottom of your window in Atom and send the code to your Pycom board. Now go to the Wia dashboard and you should see data appearing in the debugger section of your dashboard.&lt;/p&gt;

&lt;p&gt;In order for the sensor to operate correctly, it needs to calibrate the distance inside you mail box.&lt;/p&gt;

&lt;h3&gt;
  
  
  Calibration
&lt;/h3&gt;

&lt;p&gt;To calibrate the sensor, place the sensor in the mailbox where its suits best. Power the board; when the LED on the board is red, the sensor is calibrating; once the LED flashes green, the sensor has been calibrated. The sensor needs at-least 2cm of space in order for it to operate correctly. &lt;/p&gt;

&lt;p&gt;Now when mail is inserted into your mailbox, the distance will be reduced from the calibrated distance and the code will publish an Event via Sigfox to Wia.&lt;/p&gt;

&lt;h1&gt;
  
  
  Send a Push Notification
&lt;/h1&gt;

&lt;p&gt;Now for the next step, once we recieve the Sigfox event in Wia, we will send a notification to any connected phones that there is mail. For this we need to build a Flow.&lt;/p&gt;

&lt;p&gt;Head over to your Wia dashboard and in the Space where your Sigfox device is held. From there click on the Flow icon in the left hand menu to go your Flows.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-05-14%2F1526284386-778692-flow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-05-14%2F1526284386-778692-flow.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now to create your Flow, you can name it whatever you like. Once you have created a Flow, you should be taken to the Flow studio.&lt;/p&gt;

&lt;p&gt;In the Flow studio:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Drag the &lt;code&gt;trigger event node&lt;/code&gt; from the left hand side onto the canvas&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the node and enter &lt;code&gt;sigfoxDataUplink&lt;/code&gt; as the event name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enable your Sigfox Device as the event source&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we are going add a notification for the Sigfox Event so we get notified of our inbound mail. To do this, you will require the Wia mobile app. You can download it for iOS &lt;a href="https://itunes.apple.com/us/app/wia-talk-to-your-things/id1320616870?ls=1&amp;amp;mt=8" rel="noopener noreferrer"&gt;here&lt;/a&gt; and Android &lt;a href="https://play.google.com/store/apps/details?id=io.wia.wia" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-13%2F1531485931-970630-mail-notifier.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-13%2F1531485931-970630-mail-notifier.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Flow Studio editor:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Drag over a notification node and enter the following text
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;You've got Mail!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you should receive Sigfox data to your mobile device.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-13%2F1531490491-960647-screenshot-20180713-150002-2.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-13%2F1531490491-960647-screenshot-20180713-150002-2.jpeg" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>opensource</category>
      <category>iot</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Play Rock Paper Scissors Using the ESP8266</title>
      <dc:creator>Austin Spivey</dc:creator>
      <pubDate>Wed, 04 Jul 2018 11:04:43 +0000</pubDate>
      <link>https://dev.to/wiaio/play-rock-paper-scissors-using-the-esp8266-1h7</link>
      <guid>https://dev.to/wiaio/play-rock-paper-scissors-using-the-esp8266-1h7</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-04%2F1530701878-372923-blog-05.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-04%2F1530701878-372923-blog-05.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
In this tutorial, we will build an online rock, paper, scissors game using ESP8266, the Wia Dashboard, and Github.&lt;/p&gt;
&lt;h1&gt;
  
  
  What You Will Need
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;2x ESP8266&lt;/li&gt;
&lt;li&gt;2x Micro USB to USB cables&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Before you begin, you must have a Wia account. &lt;a href="https://dashboard.wia.io/login" rel="noopener noreferrer"&gt;You can create one here&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;If you have not set up your ESP8266 with Arduino yet, you will need to do that first. &lt;a href="https://developers.wia.io/v1.0/docs/espressif-esp8266" rel="noopener noreferrer"&gt;This tutorial&lt;/a&gt; will show you how.&lt;/p&gt;
&lt;h1&gt;
  
  
  Getting Started
&lt;/h1&gt;

&lt;p&gt;First, connect a USB cable to one of the ESP8266 and plug it into your computer or laptop. &lt;/p&gt;

&lt;p&gt;Open the Arduino IDE. You can download &lt;a href="https://www.google.ie/search?q=arduino&amp;amp;oq=arduino&amp;amp;aqs=chrome..69i57j69i60l4j69i59.1724j0j7&amp;amp;sourceid=chrome&amp;amp;ie=UTF-8" rel="noopener noreferrer"&gt;the latest version here&lt;/a&gt;. In Arduino IDE, create a new sketch and save it as &lt;code&gt;playerOne.ino&lt;/code&gt;. Create a second sketch and name it &lt;code&gt;playerTwo.ino&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, navigate to the Wia Dashboard, create a new &lt;code&gt;space&lt;/code&gt; and &lt;code&gt;add device&lt;/code&gt;. Name it something like "playerOne". &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-03%2F1530630222-32159-screen-shot-2018-07-03-at-40324-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-03%2F1530630222-32159-screen-shot-2018-07-03-at-40324-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you have added your device, navigate to the &lt;code&gt;Devices&lt;/code&gt; tab on the left-hand side of the page. Select your device, then navigate to the &lt;code&gt;configuration&lt;/code&gt; tab. You will see your device ID as well as your &lt;code&gt;device_secret_key&lt;/code&gt;. You will need need to device secret key later.&lt;/p&gt;
&lt;h1&gt;
  
  
  The Code
&lt;/h1&gt;

&lt;p&gt;Copy and paste the following code into your Arduino sketch named playerOne.ino.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
#include &amp;lt;Arduino.h&amp;gt;
#include &amp;lt;ESP8266WiFi.h&amp;gt;
#include &amp;lt;ESP8266WiFiMulti.h&amp;gt;
#include &amp;lt;ESP8266HTTPClient.h&amp;gt;

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;

const char* ssid     = "name-of-your-Wifi";
const char* password = "your-Wifi-Password";

// get this from the wia dashboard. it should start with `d_sk`

const char* device_secret_key = "your-device-secret-key";

boolean buttonState = HIGH;
boolean buttonDown = false;

void setup() {
  // put your setup code here, to run once:
  pinMode(0, INPUT);
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }
  WiFi.mode(WIFI_STA);
  WiFiMulti.addAP(ssid, password);
}

void loop() {
  // put your main code here, to run repeatedly:
  buttonState = digitalRead(0);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is LOW:
  if (buttonState == LOW) {
    if (buttonDown == false) {
      Serial.println("Button Pushed");
      buttonDown = true;
      postToWia();
      delay(750);
    }
  } else {
    buttonDown = false;
  }
}

void postToWia() {
  // wait for WiFi connection
  if((WiFiMulti.run() == WL_CONNECTED)) {
    HTTPClient http;
    USE_SERIAL.print("[HTTP] begin...\n");
    // configure wia rest api
    http.begin("http://api.wia.io/v1/events");
    USE_SERIAL.print("[HTTP] POST...\n");

    // set authorization token
    http.addHeader("Authorization", "Bearer " + String(device_secret_key));
    // set content-type to json
    http.addHeader("Content-Type", "application/json");
    // start connection and send HTTP headers. replace name and data values with your own.
    int httpCode = http.POST("{\"name\":\"buttonPress\"}");
    // httpCode will be negative on error

    if(httpCode &amp;gt; 0) {
        // HTTP header has been send and Server response header has been handled
        USE_SERIAL.printf("[HTTP] POST... code: %d\n", httpCode);
        // file found at server
        if(httpCode == HTTP_CODE_OK) {
            String payload = http.getString();
            USE_SERIAL.println(payload);
        }
    } else {
        USE_SERIAL.printf("[HTTP] POST... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }
    http.end();
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Change the following values:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;name-of-your-WiFi&lt;/code&gt; to the name of your WiFi. This must be the same WiFi network that your computer is using.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;your-WiFi-password&lt;/code&gt; to your WiFi network password&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;you-device-secret-key&lt;/code&gt; to your device secret key, found on the Wia Dashboard under &lt;code&gt;Devices &amp;gt; Configuration&lt;/code&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Upload the code to your device by clicking &lt;code&gt;upload&lt;/code&gt; in the Arduino IDE. Then, set your device aside. Remember that this device is &lt;code&gt;playerOne&lt;/code&gt; and contains the playerOne code.&lt;/p&gt;

&lt;p&gt;Connect the second device to your computer, and add it to your space in the Wia Dashboard. This device will have an entirely different &lt;code&gt;device-secret-key&lt;/code&gt;. Collect the key from the configuration tab. Copy and paste the code from before into the Arduino file  &lt;code&gt;playerTwo.ino&lt;/code&gt;, but change the &lt;code&gt;device-secret-key&lt;/code&gt; to match the second device.&lt;/p&gt;

&lt;p&gt;Upload the code from the file &lt;code&gt;playerTwo.ino&lt;/code&gt; onto your second device.&lt;/p&gt;

&lt;h1&gt;
  
  
  Wia Flows
&lt;/h1&gt;

&lt;p&gt;Now in your Wia dashboard, click &lt;code&gt;Flows&lt;/code&gt; in the left-hand sidebar. Create a new flow and name it whatever you like. &lt;/p&gt;

&lt;p&gt;Drag over an &lt;code&gt;Event&lt;/code&gt; from the trigger tab and name it buttonPress. Select both devices. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-03%2F1530630415-225803-screen-shot-2018-07-03-at-40602-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-03%2F1530630415-225803-screen-shot-2018-07-03-at-40602-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;logic&lt;/code&gt; tab, drag over a &lt;code&gt;run-function&lt;/code&gt; node. Drag the yellow dot from the &lt;code&gt;Event&lt;/code&gt; node to the &lt;code&gt;run-function&lt;/code&gt; node. In the box, copy and paste this code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  var items = [
    '🗿',
    '📜',
    '✂'
];

var item = items[Math.floor(Math.random()*items.length)];
output.body.data = item;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Your screen should look like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-03%2F1530630492-182475-screen-shot-2018-07-03-at-40737-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-03%2F1530630492-182475-screen-shot-2018-07-03-at-40737-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;code&gt;Update&lt;/code&gt;. &lt;br&gt;
  Then, in the &lt;code&gt;action&lt;/code&gt; tab, drag over an &lt;code&gt;event&lt;/code&gt; and name it &lt;code&gt;emoji&lt;/code&gt;. To connect the nodes, drag the orange dots. Your screen should look like this: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-03%2F1530630561-581691-screen-shot-2018-07-03-at-40904-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-03%2F1530630561-581691-screen-shot-2018-07-03-at-40904-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, navigate to &lt;code&gt;Devices &amp;gt; playerOne&lt;/code&gt;. This should take you to the overview page for your device. In the right hand corner, click &lt;code&gt;add a widget&lt;/code&gt;. Write &lt;code&gt;emoji&lt;/code&gt; for the title and &lt;code&gt;emoji&lt;/code&gt; for the event. Then, navigate back to &lt;code&gt;Devices&lt;/code&gt; on the sidebar and select your device for &lt;code&gt;playerTwo&lt;/code&gt;. Create a new widget and write &lt;code&gt;emoji&lt;/code&gt; for the title and &lt;code&gt;emoji&lt;/code&gt; for the event.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-03%2F1530630620-277373-screen-shot-2018-07-03-at-41007-pm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-03%2F1530630620-277373-screen-shot-2018-07-03-at-41007-pm.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Plug both devices into your computer. Press the &lt;code&gt;flash&lt;/code&gt; button on both devices. Your widgets will show whether the device chose rock, paper or scissors. &lt;/p&gt;

&lt;p&gt;However, navigating between the two devices is not an efficient way to play the game. So, we must make a webpage that will show us the result of each player's choice simultaneously.&lt;/p&gt;

&lt;p&gt;To do this, we will use Github. You &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;can create an account here&lt;/a&gt;.&lt;/p&gt;
&lt;h1&gt;
  
  
  Web Page
&lt;/h1&gt;

&lt;p&gt;Begin by logging into Github. Create a new repository and name it your-github-username.github.io. Check the box to &lt;code&gt;initialize with a README&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Once you have created your respository, open it. Click &lt;code&gt;create new file&lt;/code&gt;. Copy and paste the code below into a file called &lt;code&gt;index.html&lt;/code&gt;. The file &lt;strong&gt;must&lt;/strong&gt; be named index.html.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;title&amp;gt;Wia Game&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Wia Rock Paper Scissors&amp;lt;/h1&amp;gt;
  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is the HTML boilerplate. To see our game update in real time, we need to embed our widgets from Wia. Back in the Wia Dashboard, navigate to one of the two player devices. In the overview, you can see your widget. Click the box with an arrow in the upper right hand corner of the widget. Choose the setting &lt;code&gt;anyone can view this widget&lt;/code&gt;.  Copy the code of embed the widget. The code starts with  and ends with .&lt;/p&gt;

&lt;p&gt;Back in GitHub, edit the &lt;code&gt;index.html&lt;/code&gt; file. Paste the widget code below the header &lt;code&gt;&amp;lt;h1&amp;gt;Wia Rock Paper Scissors&amp;lt;/h1&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Repeat this with the widget for the other device. Now, your HTML file should look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
    &amp;lt;title&amp;gt;Wia Game&amp;lt;/title&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;
    &amp;lt;h1&amp;gt;Wia Rock Paper Scissors&amp;lt;/h1&amp;gt;
    &amp;lt;iframe&amp;gt; YOUR WIDGET &amp;lt;/iframe&amp;gt;
    &amp;lt;iframe&amp;gt; YOUR SECOND WIDGET &amp;lt;/iframe&amp;gt;
  &amp;lt;/body&amp;gt;
  &amp;lt;/html&amp;gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To view your new Web Page, navigate to &lt;code&gt;https://your-github-username.github.io/&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;And there is your game!&lt;/p&gt;

</description>
      <category>esp8266</category>
      <category>wia</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
    <item>
      <title>How to install Node.js on any Raspberry Pi</title>
      <dc:creator>Austin Spivey</dc:creator>
      <pubDate>Tue, 03 Jul 2018 12:39:40 +0000</pubDate>
      <link>https://dev.to/wiaio/how-to-install-nodejs-on-any-raspberry-pi-53fb</link>
      <guid>https://dev.to/wiaio/how-to-install-nodejs-on-any-raspberry-pi-53fb</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-03%2F1530621440-312950-blog-nodejs-9touvegvpm.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-03%2F1530621440-312950-blog-nodejs-9touvegvpm.jpeg" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
Hi All,&lt;br&gt;
Here's a quick tutorial showing you how to install Node.js on any Raspberry Pi. When logged into your Pi (either by SSH or desktop), run the following 5 commands one by one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd ~
wget https://nodejs.org/dist/v4.3.2/node-v4.3.2-linux-$(uname -m).tar.gz 
tar -xvf node-v4.3.2-linux-$(uname -m).tar.gz
cd node-v4.3.2-linux-$(uname -m)
sudo cp -R * /usr/local/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To check Node.js is installed correctly, run &lt;code&gt;node -v&lt;/code&gt;. It should return &lt;code&gt;v4.3.2&lt;/code&gt;. Run &lt;code&gt;npm -v&lt;/code&gt; to check if NPM (Node package Manager) has also been installed.&lt;/p&gt;

</description>
      <category>node</category>
      <category>raspberrypi</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>How to Build Your Own Weather Station Using a Raspberry Pi</title>
      <dc:creator>Austin Spivey</dc:creator>
      <pubDate>Tue, 03 Jul 2018 10:12:39 +0000</pubDate>
      <link>https://dev.to/wiaio/how-to-build-your-own-weather-station-using-a-raspberry-pi-415o</link>
      <guid>https://dev.to/wiaio/how-to-build-your-own-weather-station-using-a-raspberry-pi-415o</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-02%2F1530519961-733576-weather-station-1.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-02%2F1530519961-733576-weather-station-1.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we will show you how to create a Weather Station using a raspberry pi and send events to Wia.&lt;/p&gt;

&lt;p&gt;This is an updated version of our old tutorial. There have been several changes to the Wia dashboard and code since our last tutorial.&lt;/p&gt;

&lt;h1&gt;
  
  
  What You Will Need
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;Raspberry Pi 2 or Model 3 B+&lt;/li&gt;
&lt;li&gt;Raspberry Pi Sense HAT&lt;/li&gt;
&lt;li&gt;Node.js and NPM must both be installed on the raspberry pi.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you do not have it already installed, &lt;a href="https://community.wia.io/d/4-how-to-install-node-js-on-any-raspberry-pi" rel="noopener noreferrer"&gt;learn how to install node.js here&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Setting up the Raspberry Pi
&lt;/h1&gt;

&lt;p&gt;First, you have to set up the Raspberry Pi. &lt;a href="https://developers.wia.io/docs/raspberry-pi" rel="noopener noreferrer"&gt;Our tutorial will walk you through it!&lt;/a&gt; Be sure to follow each step carefully. When you're ready, run &lt;code&gt;ssh pi@('RASPBERRY-PI-IP-ADDRESS')&lt;/code&gt;. This will allow you to begin working in the raspberry pi terminal through your computer.&lt;/p&gt;

&lt;h1&gt;
  
  
  Setting up the Wia Node.js SDK
&lt;/h1&gt;

&lt;p&gt;First, we need to create a folder on the raspberry pi to store our files. Create a new folder called &lt;code&gt;wia-wether-device&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next, initialize the package by creating a packackge.json file using the command line &lt;code&gt;npm init&lt;/code&gt;. Hit &lt;code&gt;enter&lt;/code&gt; for each of the prompts, they are not important at this time.&lt;/p&gt;

&lt;p&gt;Once you are through that, you can install the Wia SDK onto the raspberry pi by using the command line &lt;code&gt;npm install --save wia&lt;/code&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Using the Sense HAT with Node.js
&lt;/h1&gt;

&lt;p&gt;Next, we must install nodeimu so that we can use the sensors. Use the command &lt;code&gt;npm install --save nodeimu&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Your package.json file should look like this:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-02%2F1530524205-205083-screen-shot-2018-07-02-at-103618-am.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-02%2F1530524205-205083-screen-shot-2018-07-02-at-103618-am.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Create Your Weather Device
&lt;/h1&gt;

&lt;p&gt;Go to the &lt;a href="https://dashboard.wia.io/" rel="noopener noreferrer"&gt;Wia Dashboard&lt;/a&gt; and select &lt;code&gt;Create a New Space&lt;/code&gt; then select &lt;code&gt;Devices&lt;/code&gt;. Add a device and give it a name. Now, in the &lt;code&gt;Configuration&lt;/code&gt; tab for your device, you will find &lt;code&gt;device_secret_key&lt;/code&gt; which should begin with &lt;code&gt;d_sk&lt;/code&gt;. This will be important later on.&lt;/p&gt;
&lt;h1&gt;
  
  
  The Code
&lt;/h1&gt;

&lt;p&gt;Create a file called &lt;code&gt;index.js&lt;/code&gt;. Then, copy the code from the example below and paste it into the &lt;code&gt;index.js&lt;/code&gt; file.&lt;/p&gt;

&lt;p&gt;Replace the &lt;code&gt;device_secret_key&lt;/code&gt; with your device's secret key.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use strict';
var wia = require('wia')('device-secret-key');
var util = require('util')
var nodeimu  = require('nodeimu');
var IMU = new nodeimu.IMU();
var tic = new Date();
var callback = function (error, data) {
 var toc = new Date();
 if (error) {
   console.log(error);
   return;
 }
 // Send temperature data
 wia.events.publish({
   name: "temperature",
   data: data.temperature.toFixed(4) // data received from temperature sensor
 });
 // Send pressure data
 wia.events.publish({
   name: "pressure",
   data: data.pressure.toFixed(4) // data received from pressure sensor
 });
 // Send humidity data
 wia.events.publish({
   name: "humidity",
   data: data.humidity.toFixed(4) // data received from humidity sensor
 });
 setTimeout(function() { tic = new Date(); IMU.getValue(callback); } , 250 - (toc - tic));
}
// Using the MQTT stream
wia.stream.on('connect', function() {
 IMU.getValue(callback);
});
wia.stream.connect();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To test your program, run &lt;code&gt;node index.js&lt;/code&gt;&lt;br&gt;
  Now, you should see events appearing in the &lt;code&gt;Events&lt;/code&gt; tab for your Device in the Wia Dashboard.&lt;/p&gt;
&lt;h1&gt;
  
  
  The App
&lt;/h1&gt;

&lt;p&gt;Next, we will make a few Widgets through Wia to present the data that the Weather Station collects. Log in to the Wia dashboard, and navigate to your Device. Select the &lt;code&gt;Widgets&lt;/code&gt; tab and create a new Widget. Name it &lt;code&gt;Humidity&lt;/code&gt;. For the &lt;code&gt;event&lt;/code&gt; box, type humidity exactly as it appears in the node.js code that you copy and pasted before. Select &lt;code&gt;done&lt;/code&gt; and you will see the latest update. Follow these steps for temperature and pressure to finish your Weather Station project.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-02%2F1530524302-521378-screen-shot-2018-07-02-at-103805-am.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-02%2F1530524302-521378-screen-shot-2018-07-02-at-103805-am.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Web Page
&lt;/h1&gt;

&lt;p&gt;Next, create a webpage and host it on GitHub so you can check the weather from your Weather Station any time!&lt;/p&gt;

&lt;p&gt;If you don't have a github account already, &lt;a href="https://github.com/" rel="noopener noreferrer"&gt;you can make one here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once you are set up with github, create a new repository and name it &lt;code&gt;your-username.github.io&lt;/code&gt;. Check the box to initialize with a README.&lt;/p&gt;

&lt;p&gt;Now, navigate to your new repository and create a new file. It &lt;strong&gt;must&lt;/strong&gt; be named &lt;code&gt;index.html&lt;/code&gt;. Copy and paste the following block of code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;

    &amp;lt;h1&amp;gt;Wia Weather Station&amp;lt;/h1&amp;gt;

  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So far, our webpage is pretty blank. Navigate back to your Wia Dashboard and in the overview for your Device, you can see your Widgets. In the upper right hand corner of the Widget, there should be a box with an arrow. Click the box and a screen like this should pop up.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-02%2F1530524388-230043-screen-shot-2018-07-02-at-103927-am.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-07-02%2F1530524388-230043-screen-shot-2018-07-02-at-103927-am.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Change the settings so that &lt;code&gt;Anyone can view this Widget and embed it in any website&lt;/code&gt;. You should also &lt;code&gt;Embed&lt;/code&gt; code, which will start with &lt;code&gt;&amp;lt;iframe&amp;gt;&lt;/code&gt; and end with &lt;code&gt;&amp;lt;/iframe&amp;gt;&lt;/code&gt;. Copy the entire code and paste it below the &lt;code&gt;&amp;lt;h1&amp;gt;Wia Weather Station&amp;lt;/h1&amp;gt;&lt;/code&gt; line and above the &lt;code&gt;&amp;lt;/body&amp;gt;&lt;/code&gt; line. Your full code should look something like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;!DOCTYPE html&amp;gt;
&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="UTF-8"&amp;gt;
  &amp;lt;/head&amp;gt;
  &amp;lt;body&amp;gt;

    &amp;lt;h1&amp;gt;Wia Weather Station&amp;lt;/h1&amp;gt;

    &amp;lt;iframe&amp;gt; YOUR WIDGET &amp;lt;/iframe&amp;gt;


  &amp;lt;/body&amp;gt;
&amp;lt;/html&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do this again with each Widget.&lt;/p&gt;

&lt;p&gt;Click commit changes and visit your site at &lt;a href="https://github.com/username/username.github.io" rel="noopener noreferrer"&gt;https://github.com/username/username.github.io&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You should be able to see the weather from your raspberry pi appear on your own webpage!&lt;/p&gt;

</description>
      <category>temperature</category>
      <category>raspberrypi</category>
      <category>tutorial</category>
      <category>wia</category>
    </item>
    <item>
      <title>Javascript - DOM Manipulation without jQuery</title>
      <dc:creator>Austin Spivey</dc:creator>
      <pubDate>Fri, 29 Jun 2018 09:57:09 +0000</pubDate>
      <link>https://dev.to/wiaio/javascript---dom-manipulation-without-jquery-5g3i</link>
      <guid>https://dev.to/wiaio/javascript---dom-manipulation-without-jquery-5g3i</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-06-29%2F1530273375-100728-blog-04.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fs3-eu-west-1.amazonaws.com%2Fwia-flarum-bucket%2F2018-06-29%2F1530273375-100728-blog-04.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Often, developers tend to rely on libraries like &lt;a href="https://jquery.com/" rel="noopener noreferrer"&gt;jQuery&lt;/a&gt; for basic DOM manipulation like querying elements, adding/removing classes, adding event listeners etc. A lot of resources point to jQuery as a solution for these things, but in reality, using it just for the basics is probably overkill for your website. The vanilla Javascript DOM API is more than capable of basic DOM manipulation, and being able to drop jQuery will mean a decrease in page load speed! Here's a run down of the basics in vanilla Javascript.&lt;/p&gt;

&lt;h1&gt;
  
  
  Querying DOM elements
&lt;/h1&gt;

&lt;p&gt;There are a few methods you can use to query a DOM element in vanilla Javascript, the most common being &lt;code&gt;document.querySelector()&lt;/code&gt;. This method takes a CSS selector as an argument, and returns the first match for that selector. Here's how to use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var mySelector = document.querySelector('.my-selector');
var paragraph = document.querySelector('p');
var hiddenInput = document.querySelector('input[type="hidden"]');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to get all occurrences of a selector (for example, all the &lt;code&gt;&amp;lt;h1&amp;gt;&lt;/code&gt; tags on the page), use &lt;code&gt;document.querySelectorAll()&lt;/code&gt;. This method returns a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/NodeList" rel="noopener noreferrer"&gt;NodeList&lt;/a&gt;. Here's how to use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var headings = document.querySelectorAll('h1');
var listLinks = document.querySelectorAll('li a');
var items = document.querySelectorAll('.my-selector &amp;gt; p strong');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To further manipulate them, you can simply iterate over them. There are a few ways to do this, the most straightforward being a &lt;code&gt;for&lt;/code&gt; loop or a &lt;code&gt;for of&lt;/code&gt; loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var headings = document.querySelectorAll('h1');

for (var i = 0; i &amp;lt; headings.length; i++) {
  var heading = headings[i];
  // do something with heading here
}

for (var heading of headings) {
  // do something with heading here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In recent browsers, you can also use the &lt;code&gt;forEach()&lt;/code&gt; method on NodeLists:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var headings = document.querySelectorAll('h1');

headings.forEach(function(heading) {
  // do something with heading here
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Other methods for querying DOM elements are &lt;code&gt;document.getElementById()&lt;/code&gt; for getting the first element that matches an ID, &lt;code&gt;document.getElementsByClassName()&lt;/code&gt; for getting a list of elements that match a class (returns a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection" rel="noopener noreferrer"&gt;HTMLCollection&lt;/a&gt;), and &lt;code&gt;document.getElementsByTagName()&lt;/code&gt; for getting a &lt;em&gt;live&lt;/em&gt; list of elements that match a selector (returns a &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLCollection" rel="noopener noreferrer"&gt;HTMLCollection&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;The difference between &lt;code&gt;getElementsByTagName()&lt;/code&gt; and &lt;code&gt;querySelectorAll()&lt;/code&gt; is that &lt;code&gt;getElementsByTagName()&lt;/code&gt; returns a &lt;em&gt;live&lt;/em&gt; list, meaning that it will update if an element is added dynamically.&lt;/p&gt;

&lt;h1&gt;
  
  
  Adding/removing classes
&lt;/h1&gt;

&lt;p&gt;A really common DOM manipulation is adding or removing a class from an element. Luckily, this is very easy to achieve with vanilla Javascript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var button = document.querySelector('button');

button.classList.add('small');
button.classList.remove('large');
button.classList.toggle('active'); // if element has class 'active' then remove it, otherwise add it
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Adding event listeners
&lt;/h1&gt;

&lt;p&gt;Adding an event listener (like 'click', 'scroll' etc) is quite simple with vanilla JS. Simply use the &lt;code&gt;addEventListener()&lt;/code&gt; method on a DOM element, passing in an event type and a callback function (similar to jQuery's &lt;a href="http://api.jquery.com/on/" rel="noopener noreferrer"&gt;&lt;code&gt;on&lt;/code&gt; method&lt;/a&gt;). Here's how to use it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var button = document.getElementById('button');

button.addEventListener('click', function(event) {
  // do something here
});
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  Putting it all together
&lt;/h1&gt;

&lt;p&gt;Now that we've learned the basics of DOM manipulation, let's put them all together:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Query all button elements
var buttons = document.querySelectorAll('button');

// Iterate through the buttons
for (var button of buttons) {
  // Add a 'click' event listener to each button
  button.addEventListener('click', function() {
    // Add a class to the clicked button
    this.classList.add('active');
  });
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>javascript</category>
      <category>beginners</category>
      <category>learning</category>
    </item>
    <item>
      <title>How we built our facial recognition ferris wheel</title>
      <dc:creator>Austin Spivey</dc:creator>
      <pubDate>Thu, 28 Jun 2018 15:18:04 +0000</pubDate>
      <link>https://dev.to/wiaio/how-we-built-our-facial-recognition-ferris-wheel-583a</link>
      <guid>https://dev.to/wiaio/how-we-built-our-facial-recognition-ferris-wheel-583a</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F29963bd-DSC_0292.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F29963bd-DSC_0292.jpg" alt="''"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At &lt;a href="http://coolestprojects.org/" rel="noopener noreferrer"&gt;Coolest Projects&lt;/a&gt; 2018, we showcased the &lt;a href="https://www.wia.io" rel="noopener noreferrer"&gt;Wia platform&lt;/a&gt; with a facial recognition ferris wheel - if you're smiling, the wheel turns, and if you're not smiling, it stops. Today we're going to talk about how we built this project, and maybe you'll be inspired to build something like it!&lt;/p&gt;

&lt;h2&gt;
  
  
  What we used
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Lego Ferris wheel kit&lt;/li&gt;
&lt;li&gt;Arduino MKR 1000&lt;/li&gt;
&lt;li&gt;L293D motor driver&lt;/li&gt;
&lt;li&gt;High torque DC motor&lt;/li&gt;
&lt;li&gt;Breadboard&lt;/li&gt;
&lt;li&gt;Raspberry Pi Zero W&lt;/li&gt;
&lt;li&gt;Raspberry Pi Camera Module (we used &lt;a href="https://www.raspberrypi.org/products/camera-module-v2/" rel="noopener noreferrer"&gt;this one&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Lego Ferris wheel
&lt;/h2&gt;

&lt;p&gt;For the Ferris wheel itself, we decided to go with &lt;a href="https://shop.lego.com/en-IE/Ferris-Wheel-10247" rel="noopener noreferrer"&gt;this Lego kit&lt;/a&gt;. It took about 7 hours or so to complete. This kit has an optional add-on motor, but we decided to create our own solution.&lt;/p&gt;

&lt;h2&gt;
  
  
  Driving the motor
&lt;/h2&gt;

&lt;p&gt;We used a high torque DC motor to turn the wheel, and the L293D motor driver to drive the motor. &lt;br&gt;
&lt;a href="https://community.wia.io/d/27-driving-a-dc-motor-with-an-arduino-and-the-l293d-motor-driver" rel="noopener noreferrer"&gt;Click here&lt;/a&gt; to read in depth about how we set this up, along with a basic code snippet for making the motor turn. We'll build upon this code later in this article, when we add in MQTT functionality to listen for Commands.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F3e68a3e-DSC_0351.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F3e68a3e-DSC_0351.jpg" alt="''"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F2f2418e-DSC_0357.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F2f2418e-DSC_0357.jpg" alt="''"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Attaching the motor to the wheel
&lt;/h2&gt;

&lt;p&gt;The next step was to hook up the DC motor to the Ferris wheel mechanism and make it turn. This proved to be quite challenging, and required some dismantling of the lower part of the structure to make space for the components. We found that the motor's shaft fit almost perfectly into one of the Lego pieces, all we had to do was mount the motor in the correct place and make sure it wouldn't move around. So, we built a little Lego enclosure for the motor out of spare pieces, leaving space at the back for connecting the wires to the motor's terminals.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F249d8a6-DSC_0327.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F249d8a6-DSC_0327.jpg" alt="''"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Listening for Commands
&lt;/h2&gt;

&lt;p&gt;Next, we wanted to create some &lt;a href="https://developers.wia.io/docs/add-a-command" rel="noopener noreferrer"&gt;Commands&lt;/a&gt; for the Arduino to listen for, and rotate the motor accordingly. The first step was to create the Commands in the Wia dashboard. As you can see, we created some basic Commands for manually controlling the wheel, as well as a 'take photo' Command, which we'll get to later.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F325afb3-ferris-wheel-commands-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F325afb3-ferris-wheel-commands-2.png" alt="''"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, we updated the Arduino code to use MQTT to listen for the Commands. Here's the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;WiFi101.h&amp;gt;
#include &amp;lt;MQTT.h&amp;gt;

const char WIFI_SSID[] = "wifi-ssid"; // WiFI ssid 
const char WIFI_PASS[] = "wifi-password"; //WiFI password

// get this from the wia dashboard. it should start with `d_sk`
const char* device_secret_key = "device-secret-key";

//WiFiSSLClient ipCloudStack;
WiFiClient wifiClient;
MQTTClient mqttClient;

int status = WL_IDLE_STATUS;

// Wia Cloud MQTT params
char mqttCloudServer[]     = "api.wia.io";
int  mqttCloudPort         = 1883;
char mqttCloudUsername[]   = "device_secret_key"; 
char mqttCloudPassword[]   = " "; 

// Wia API parameters
char server[] = "api.wia.io";
const int mqttPort = 1883;  // Default MQTT port

const String deviceId = "device-id";   // starts with dev_, found in Wia Dashboard
const String commandName = "take-photo";  // Configured in Wia Dashboard

// Topics
String takePhotoCommandTopic = "devices/" + deviceId + "/commands/take-photo/run";
String rotateForFiveCommandTopic = "devices/" + deviceId + "/commands/rotate-for-5-seconds/run";
String startMovingCommandTopic = "devices/" + deviceId + "/commands/start-moving/run";
String stopMovingCommandTopic = "devices/" + deviceId + "/commands/stop-moving/run";

//L293D
const int motorPin1  = 7;
const int motorPin2  = 6;


void messageReceived(String &amp;amp;topic, String &amp;amp;payload) {
  Serial.println("incoming: " + topic + " - " + payload);
  if (topic.equals(rotateForFiveCommandTopic)) {
    Serial.println("Rotating for 5 seconds.....");
    // Start rotating
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
    // wait 5 seconds for connection:
    delay(5000);
    // Stop rotating
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
  } else if (topic.equals(startMovingCommandTopic)) {
    Serial.println("Start rotating.....");
    // Start rotating
    digitalWrite(motorPin1, HIGH);
    digitalWrite(motorPin2, LOW);
  } else if (topic.equals(stopMovingCommandTopic)) {
     Serial.println("Stop rotating.....");
    // Stop rotating
    digitalWrite(motorPin1, LOW);
    digitalWrite(motorPin2, LOW);
  } else {
    Serial.println("Unhandled topic");
  }
}

void connect() {

 // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to WiFi network:
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(WIFI_SSID);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(WIFI_SSID, WIFI_PASS);

    // wait 5 seconds for connection:
    delay(5000);
  }
  Serial.print("\nconnecting...");

  Serial.println("\nconnected!\n");
  Serial.print("\nIP address: ");
  Serial.println(WiFi.localIP());

  // You need to set the IP address directly.
  mqttClient.begin(mqttCloudServer, mqttCloudPort, wifiClient);

  Serial.println("start wia connect"); Serial.println();

  while (!mqttClient.connect("wiatest", mqttCloudUsername, mqttCloudPassword)) {
    Serial.print("*");
    delay(500);    
  }

  Serial.println("Connected to MQTT");

  mqttClient.onMessage(messageReceived);

  mqttClient.subscribe(takePhotoCommandTopic);
  mqttClient.subscribe(rotateForFiveCommandTopic);
  mqttClient.subscribe(startMovingCommandTopic);
  mqttClient.subscribe(stopMovingCommandTopic);
}

void setup() {
  Serial.begin(115200);

  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);

  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, LOW);  

  connect();
}

void loop() {
  mqttClient.loop();
  delay(1000);

  if (!wifiClient.connected()) {
    connect();
  }

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After uploading that code to the Arduino, we could then simply click 'Run' on the Commands in the Wia dashboard, and the Ferris wheel would turn accordingly.&lt;/p&gt;

&lt;h2&gt;
  
  
  The facial recognition camera
&lt;/h2&gt;

&lt;p&gt;For the facial recognition camera, we used a Raspberry Pi Zero W with a Raspberry Pi camera module.&lt;br&gt;
Read in depth about how we set this up &lt;a href="https://community.wia.io/d/3-build-your-own-smile-detector-with-wia-amazon-rekognition-and-raspberry-pi" rel="noopener noreferrer"&gt;here&lt;/a&gt;. This covers setting up the Raspberry Pi with the camera module, using NodeJS to take a photo and post it as an Event to the Wia platform, and setting up a basic Flow to check if the subject of the photo is smiling or not.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fbc42f81-DSC_0316.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fbc42f81-DSC_0316.jpg" alt="''"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We built upon this setup a bit more, and added the ability for the Raspberry Pi to listen for the 'take photo' Command. Here's the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;'use strict';

var wia = require('wia')('device-secret-key');
var fs = require('fs');
var RaspiCam = require("raspicam");

wia.events.publish({
    name: "started"
});

// Setup the camera
var camera = new RaspiCam({
  mode: 'photo',
  output: __dirname + '/photo.jpg',
  encoding: 'jpg'
});

// Listen for the "start" event triggered when the start method has been successfully initiated
camera.on("start", function(){
  console.log("Starting to take photo.");
});

// Listen for the "read" event triggered when each new photo/video is saved
camera.on("read", function(err, timestamp, filename){
  console.log("New photo created.", timestamp, filename);

  // Publish the photo to Wia
  wia.events.publish({
    name: 'photo',
    file:  fs.createReadStream(__dirname + '/' + filename)
  });
});

wia.stream.on("connect", function() {
  console.log("Connected to stream.");
  wia.events.publish({name: "connected"});
});

setTimeout(function() {
  wia.commands.subscribe({
    slug: 'take-photo'
  }, function(err, data) {
    wia.events.publish({name:"gotCommand"});

    console.log("In command callback. Taking photo.");

    // Take a photo
    camera.start();
  });
}, 12500);

wia.stream.connect();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Building the Flow
&lt;/h2&gt;

&lt;p&gt;Our next step was to make the Raspberry Pi and Arduino work together over Wia, by creating a &lt;a href="https://developers.wia.io/docs/getting-started-flows" rel="noopener noreferrer"&gt;Flow&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the Wia dashboard, we created a new Flow. The trigger is the &lt;code&gt;photo&lt;/code&gt; Event created when the 'take photo' Command is run. This then goes through a 'Detect Faces' node, the output of which branches off into two logic nodes - one to output a string 'Smiling' if the subject is smiling, and one to output a string 'Not smiling' if the subject isn't smiling. &lt;br&gt;
Here's the code for the 'smiling' logic node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (input.body.faceDetails) {
  input.body.faceDetails.forEach(function(face) { 
    if (face.smile.value == true) {
        output.process = true; 
      output.body.data = "Smiling";
    } else {
        output.process = false; 
    }
  });
} else {
    output.process = false; 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;...and here's the code for the 'not smiling' logic node:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if (input.body.faceDetails) {
  input.body.faceDetails.forEach(function(face) { 
    if (face.smile.value == false) {
        output.process = true; 
        output.body.data = "Not smiling";
    } else {
        output.process = false; 
    }
  });
} else {
    output.process = false; 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the subject is smiling, the 'start moving' Command is run, triggering the Arduino to start turning the motor. If the subject isn't smiling, the 'stop moving' Command is run, stopping the motor from turning.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F9246690-ferris-wheel-flow.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F9246690-ferris-wheel-flow.png" alt="''"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating Widgets
&lt;/h2&gt;

&lt;p&gt;You'll notice that we also have 'create event' nodes at the end of the Flow. This is where we use the &lt;code&gt;output.body.data&lt;/code&gt; values from the logic nodes - to create &lt;a href="https://developers.wia.io/docs/widgets" rel="noopener noreferrer"&gt;Widgets&lt;/a&gt;!&lt;br&gt;
Each time a photo is taken, a new Event is created with the data equal to either 'Smiling' or 'Not smiling'. Over on the Device overview page of the dashboard, we were able to create a text Widget that would display this text and auto-update every time a new photo is taken. We also set up handy widgets for running the various Commands, as well as displaying the photo taken by the Raspberry Pi!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F16895f3-ferris-wheel-widgets.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F16895f3-ferris-wheel-widgets.png" alt="''"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F29e73b4-DSC_0288.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F29e73b4-DSC_0288.jpg" alt="''"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>iot</category>
      <category>beginners</category>
      <category>lego</category>
      <category>aws</category>
    </item>
    <item>
      <title>Connecting a LoRa device to Wia via The Things Network</title>
      <dc:creator>Austin Spivey</dc:creator>
      <pubDate>Tue, 26 Jun 2018 12:39:22 +0000</pubDate>
      <link>https://dev.to/wiaio/connecting-a-lora-device-to-wia-via-the-things-network-13lm</link>
      <guid>https://dev.to/wiaio/connecting-a-lora-device-to-wia-via-the-things-network-13lm</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GuEs53nn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530016343-835236-blog-02.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GuEs53nn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530016343-835236-blog-02.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In this tutorial, we are going to take two &lt;a href="https://docs.pycom.io/chapter/datasheets/development/lopy.html"&gt;Pycom LoPy's&lt;/a&gt;, set the first one as a LoRaWAN Gateway and register it as a Gateway with &lt;a href="https://www.thethingsnetwork.org"&gt;The Things Network&lt;/a&gt;. Then with  the second LoPy, we set it up  to talk to our LoRaWAN gateway and have the &lt;a href="https://www.thethingsnetwork.org"&gt;The Things Network&lt;/a&gt; push Events to Wia.&lt;/p&gt;

&lt;h1&gt;
  
  
  Components
&lt;/h1&gt;

&lt;ul&gt;
&lt;li&gt;2 x &lt;a href="https://pycom.io/product/lopy4/"&gt;Pycom LoPy&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;2 x &lt;a href="https://pycom.io/product/lora-antenna-kit/"&gt;LoRa compatible antenna&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Prerequisites
&lt;/h1&gt;

&lt;p&gt;If you are completely unfamiliar with the Pycom LoPy and Wia, you should try our getting started tutorial on how to connect the LoPy over WiFi and publish an Event to Wia &lt;a href="https://developers.wia.io/v1.0/docs/pycom-lopy"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h1&gt;
  
  
  Basic setup of the LoRaWAN Nano Gateway
&lt;/h1&gt;

&lt;p&gt;We are going to use Pycom's LoRaWAN Nano &lt;a href="https://docs.pycom.io/chapter/tutorials/lora/lorawan-otaa.html"&gt;Gateway&lt;/a&gt; example for our basic LoRa Gateway.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new folder in Atom and name it &lt;code&gt;lorawan-nano-gateway&lt;/code&gt;  this is the main folder for our Nano Gateway&lt;/li&gt;
&lt;li&gt;Go to the Pycom library examples in the &lt;code&gt;lorawan-nano-gateway&lt;/code&gt; folder, the files can be found &lt;a href="https://github.com/pycom/pycom-libraries/tree/master/examples/lorawan-nano-gateway"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Copy the &lt;code&gt;main.py&lt;/code&gt;, &lt;code&gt;config.py&lt;/code&gt; and &lt;code&gt;nanogateway.py&lt;/code&gt; into our main folder in Atom&lt;/li&gt;
&lt;li&gt;Copy the code below into a file named &lt;code&gt;boot.py&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The code is run on boot up of the Pycom board and starts the Nano Gateway automatically when the board is connected to the power.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from machine import UART
import machine
import os

uart = UART(0, baudrate=115200)
os.dupterm(uart)

machine.main('main.py')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your folder structure for your &lt;code&gt;LoRaWAN Nano Gateway&lt;/code&gt; should look like below:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;main.py&lt;/li&gt;
&lt;li&gt;boot.py&lt;/li&gt;
&lt;li&gt;config.py&lt;/li&gt;
&lt;li&gt;nanogateway.py&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9FO3gPaU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530009786-273166-selection-166.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9FO3gPaU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530009786-273166-selection-166.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Click &lt;code&gt;Upload&lt;/code&gt; in the Pymakr plugin at the bottom of your window in Atom and send the code to your Pycom board.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--j7s-nfzA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530009143-504206-nanogatewaypushack.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--j7s-nfzA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530009143-504206-nanogatewaypushack.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The Gateway ID will be used later when registering the Gateway with The Things Network&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Registering with The Things Network (TTN)
&lt;/h3&gt;

&lt;p&gt;To set up the Gateway with The Things Network, you'll need to register/create an account with them. The link to their registration page is &lt;a href="https://account.thethingsnetwork.org/register"&gt;here&lt;/a&gt;. Once registered, you'll be taken to the TTN console where you register Gateway's and Applications, monitor Device activity and set uplinks to push the data to other services. &lt;/p&gt;

&lt;h3&gt;
  
  
  Registering a Gateway with The Things Network (TTN)
&lt;/h3&gt;

&lt;p&gt;Inside the TTN Console, there are two options, Applications and Gateways. Select Gateways and then click on register Gateway. This will allow for the setup and registration of a new Gateway.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--F9wGrvgI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530003082-936235-ttn-register-gateway.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--F9wGrvgI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530003082-936235-ttn-register-gateway.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The tick box from &lt;code&gt;I'm using the legacy packet forwarder&lt;/code&gt; must be ticked&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Gateway EUI&lt;/code&gt; is from when we ran the Nano Gateway earlier&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Description&lt;/code&gt; can be what you like your Gateway to be used for&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Frequency Plan&lt;/code&gt; is for your region is the geographical area you are based&lt;/li&gt;
&lt;li&gt;The &lt;code&gt;Router&lt;/code&gt; that should be picked should be the closest to your area as well&lt;/li&gt;
&lt;li&gt;Once you are finished inputting all the fields, click on &lt;code&gt;Register Gateway&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On registering your Gateway, you should have everything you need to have your Gateway communicate with TTN.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--6Fl7LGWw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530003100-353257-gateway-overview.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--6Fl7LGWw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530003100-353257-gateway-overview.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Configuring your LoRaWAN nano Gateway with The Things Network (TTN)
&lt;/h3&gt;

&lt;p&gt;Now that your Gateway has been fully registered with TTN, you should see the push and pull acknowledgements in your atom terminal.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pBtlRZFn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530003137-632843-nanogatwayatompushpull.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pBtlRZFn--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530003137-632843-nanogatwayatompushpull.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Setting up an application with The Things Network (TTN)
&lt;/h1&gt;

&lt;p&gt;Applications are used to group a collection of device's that have similar functions. &lt;br&gt;
In the TTN Console, click on the &lt;code&gt;applications&lt;/code&gt; tab and click on &lt;code&gt;add application&lt;/code&gt;your application will need to have:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A random unique &lt;code&gt;Application ID&lt;/code&gt; which you just generate yourself&lt;/li&gt;
&lt;li&gt;A &lt;code&gt;Description&lt;/code&gt; of your application&lt;/li&gt;
&lt;li&gt;For the &lt;code&gt;Handler Registration&lt;/code&gt;, add the handler that best suits your geographical region&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Click on &lt;code&gt;Add application&lt;/code&gt; to add an Application to TTN.&lt;/p&gt;
&lt;h1&gt;
  
  
  Adding a Device to your Application in The Things Network (TTN)
&lt;/h1&gt;

&lt;p&gt;In the TTN Console, click on the Applications tab and click on the Application that we created earlier.&lt;/p&gt;

&lt;p&gt;In the Application overview tab:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on &lt;code&gt;register device&lt;/code&gt; on the Device's section&lt;/li&gt;
&lt;li&gt;Add a unique &lt;code&gt;Device ID&lt;/code&gt;(Device ID can only exist of lowercase alphanumeric characters, nonconsecutive - and _ and it cannot start or end with a - or a _)&lt;/li&gt;
&lt;li&gt;Click on the pencil icon for &lt;code&gt;Device EUI&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on the &lt;code&gt;Register&lt;/code&gt; button to add a Device &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--nt4r5voE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530003189-741093-register-device.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--nt4r5voE--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530003189-741093-register-device.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Activating The Things Network (TTN) integration in Wia
&lt;/h1&gt;

&lt;p&gt;In your Wia dashboard, click on the Space you would like to add you and click on the settings icon on the left manu bar to see your Space's settings page.&lt;br&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9QEuJLcm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530004257-935013-space-settings.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9QEuJLcm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530004257-935013-space-settings.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
Now click on the &lt;code&gt;Integrations&lt;/code&gt; tab to see a list of the available Integrations: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;FInd the &lt;code&gt;The Things Network&lt;/code&gt; integration and click to add it&lt;/li&gt;
&lt;li&gt;An Integration key will be generated for and should start with &lt;code&gt;ik_&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dWKMmA17--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530004533-550880-integration-added.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dWKMmA17--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530004533-550880-integration-added.png" alt="alt text"&gt;&lt;/a&gt;&lt;br&gt;
Go back to your TTN console and in you Application you just created, click on the Integrations tab:  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click on &lt;code&gt;Get started by creating a new one&lt;/code&gt; to see the available integrations&lt;/li&gt;
&lt;li&gt;Click on &lt;code&gt;HTTP Integration&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Add a random &lt;code&gt;Process ID&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on the &lt;code&gt;Access Key&lt;/code&gt; that was generated earlier in your Application&lt;/li&gt;
&lt;li&gt;Enter &lt;code&gt;https://integrations.wia.io/api/ttn/uplink&lt;/code&gt; as the url&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;POST&lt;/code&gt; as the HTTP method&lt;/li&gt;
&lt;li&gt;Add &lt;code&gt;Bearer ik_your_integration_key&lt;/code&gt;, replacing the &lt;code&gt;ik_your_integration_key&lt;/code&gt; with the Integration generated in your Wia Space&lt;/li&gt;
&lt;li&gt;Nothing needs be added  for &lt;code&gt;Custom Header Name&lt;/code&gt; and &lt;code&gt;Custom Header Value&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Click on save so that TTN will push all Event data from your LoRa Devices to Wia&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ykHC7Ip8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530007857-617583-integration.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ykHC7Ip8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530007857-617583-integration.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now with setup everything with need to connected our LoRa Device's to The Things Network and publish our Events to Wia. Now we need to setup a LoRa client node. We'll need the second LoPy to complete this task.&lt;/p&gt;
&lt;h1&gt;
  
  
  Setup of an over the air activation LoRa node
&lt;/h1&gt;

&lt;p&gt;In Atom, create a new folder and call it &lt;code&gt;otaa_lora&lt;/code&gt;. In this folder add the config file from the &lt;code&gt;LoRaWAN nano Gateway&lt;/code&gt; and copy it into the folder.&lt;/p&gt;

&lt;p&gt;Create a main.py file and copy the code from below into it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;""" OTAA Node example compatible with the LoPy Nano Gateway """

from network import LoRa
import socket
import binascii
import struct
import time
import config
import random

# Initialize LoRa in LORAWAN mode.
# Please pick the region that matches where you are using the device:
# Asia = LoRa.AS923
# Australia = LoRa.AU915
# Europe = LoRa.EU868
# United States = LoRa.US915
lora = LoRa(mode=LoRa.LORAWAN, region=LoRa.EU868)

# create an OTA authentication params
dev_eui = binascii.unhexlify('your-ttn-dev-eui')
app_eui = binascii.unhexlify('your-ttn-app-eui')
app_key = binascii.unhexlify('your-ttn-app-key')

# set the 3 default channels to the same frequency (must be before sending the OTAA join request)
lora.add_channel(0, frequency=config.LORA_FREQUENCY, dr_min=0, dr_max=5)
lora.add_channel(1, frequency=config.LORA_FREQUENCY, dr_min=0, dr_max=5)
lora.add_channel(2, frequency=config.LORA_FREQUENCY, dr_min=0, dr_max=5)

# join a network using OTAA
lora.join(activation=LoRa.OTAA, auth=(dev_eui, app_eui, app_key), timeout=0, dr=config.LORA_NODE_DR)

# wait until the module has joined the network
while not lora.has_joined():
    time.sleep(2.5)
    print('Not joined yet...')

# remove all the non-default channels
for i in range(3, 16):
    lora.remove_channel(i)

# create a LoRa socket
s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)

# set the LoRaWAN data rate
s.setsockopt(socket.SOL_LORA, socket.SO_DR, config.LORA_NODE_DR)

# make the socket blocking
s.setblocking(False)

time.sleep(5.0)

temperature = random.randint(0, 40)

for i in range (200):
    pkt = b'{}'.format(temperature)
    print('Sending:', pkt)
    s.send(pkt)
    time.sleep(4)
    rx, port = s.recvfrom(256)
    if rx:
        print('Received: {}, on port: {}'.format(rx, port))
    time.sleep(20)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You'll need to add the following keys obtained from TTN earlier into the tutorial code:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;dev_eui (Device EUI)&lt;/li&gt;
&lt;li&gt;app_eui (Application  EUI)&lt;/li&gt;
&lt;li&gt;app_key (The access key)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code&gt;LORAWAN mode&lt;/code&gt; should be set to the region that matches your region and the one you set for the &lt;code&gt;LoRaWAN nano Gateway&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Add a boot.py file into the and copy the code for below into the file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;from machine import UART
import machine
import os

uart = UART(0, baudrate=115200)
os.dupterm(uart)

machine.main('main.py')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now your folder: &lt;code&gt;otaa_lora&lt;/code&gt; should contain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;main.py&lt;/li&gt;
&lt;li&gt;boot.py&lt;/li&gt;
&lt;li&gt;config.py&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note: If you have both your &lt;code&gt;LoRaWAN nano Gateway&lt;/code&gt; and your &lt;code&gt;otaa LoRa Node&lt;/code&gt;&lt;br&gt;
running for your USB ports, you'll need to set project-level settings for one of the projects and change the &lt;code&gt;address&lt;/code&gt; to the port that your second device is connected with. Click on &lt;code&gt;Settings&lt;/code&gt; on the Pymakr plugin and click on project settings to add a &lt;code&gt;pymakr.conf&lt;/code&gt;. This is where you add the port for your second device.&lt;/p&gt;

&lt;p&gt;Click &lt;code&gt;Upload&lt;/code&gt; in the Pymakr plugin at the bottom of your window in Atom and send the code to your Pycom board.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--C8qtPsb9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530005624-627540-client-data-push.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--C8qtPsb9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530005624-627540-client-data-push.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In your Wia Dashboard, click on your LoRa Device and switch to the &lt;code&gt;Debugger&lt;/code&gt; tab to see the Events that your LoRa Device published coming through in real-time. To view all, click on the &lt;code&gt;Events&lt;/code&gt; tab.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uowEeeS3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530010124-591193-image-2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uowEeeS3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530010124-591193-image-2.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h1&gt;
  
  
  Handling your LoRa data in Wia
&lt;/h1&gt;

&lt;p&gt;Now for the next step, we must parse the data we received from The Things Network and do something useful with it. For this we need to build a Flow.&lt;/p&gt;

&lt;p&gt;Head over to your Wia dashboard and in the Space where your LoRa device is held. From there click on the Flow icon in the left hand menu to go your Flows.&lt;/p&gt;

&lt;p&gt;Now to create your Flow, you can name it whatever you like. Once you have created a Flow, you should be taken to the Flow studio.&lt;/p&gt;

&lt;p&gt;In the Flow studio:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Drag the trigger &lt;code&gt;Event&lt;/code&gt; node from the left hand side onto the canvas&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Click on the node and enter &lt;code&gt;ttnUplink&lt;/code&gt; as the event name&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Enable your LoRa Device as the event source&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;[upl-image-preview url=&lt;a href="https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530006282-733766-lora-flow-event.png"&gt;https://s3-eu-west-1.amazonaws.com/wia-flarum-bucket/2018-06-26/1530006282-733766-lora-flow-event.png&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;Now drag over a function node from the logic section (We’ll parse the data here)&lt;/p&gt;

&lt;p&gt;Click on the function node and add the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function parseLoRaEvent(loraData) {
  return Buffer.from(loraData, 'base64');
}

if (input.body) {
  output.body.data = parseLoRaEvent(input.body.data.payload_raw);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This code parses the LoRa data from &lt;code&gt;base64&lt;/code&gt; format to ascii.&lt;/p&gt;

&lt;p&gt;Start publishing data and your Flow should trigger.&lt;/p&gt;

&lt;p&gt;That's it!&lt;/p&gt;

</description>
      <category>lora</category>
      <category>learn</category>
      <category>opensource</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>What is Wia, and how I can use it</title>
      <dc:creator>Austin Spivey</dc:creator>
      <pubDate>Tue, 26 Jun 2018 11:18:34 +0000</pubDate>
      <link>https://dev.to/wiaio/what-is-wia-and-how-i-can-use-it-4h55</link>
      <guid>https://dev.to/wiaio/what-is-wia-and-how-i-can-use-it-4h55</guid>
      <description>&lt;p&gt;After asking what you would like to hear about, I have lots of tutorials in the making, so thank you for all your feedback! In the meantime, I realised I should tell you about what Wia is and how you can get setup.&lt;/p&gt;

&lt;h3&gt;
  
  
  Starting with the basics, What is Wia?
&lt;/h3&gt;

&lt;p&gt;Wia is an Internet of Things (IoT) cloud platform which provides a simple way for people and things to talk to each other with just a few lines of code encouraging developers to build any IoT application. Essentially providing the ability to turn any dumb device into a smart connected device within minutes.&lt;/p&gt;

&lt;p&gt;Anyone can learn how to connect their favourite development boards to Wia and integrate with third party services.&lt;/p&gt;

&lt;p&gt;For more advances developers you can also use our REST, MQTT and CoAP API reference by click &lt;a href="https://developers.wia.io/reference" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Create a Wia Account
&lt;/h3&gt;

&lt;p&gt;You can create a Wia account by visiting the &lt;a href="https://www.wia.io/signup" rel="noopener noreferrer"&gt;Sign Up&lt;/a&gt; page. Wia is free up to 10 devices at a time so you are able to continually test different devices and prototypes. &lt;a href="https://www.wia.io/signup" rel="noopener noreferrer"&gt;Create a Wia account today&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Ff32b552-Create_a_Wia_Account.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Ff32b552-Create_a_Wia_Account.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Next Up, Create your Space
&lt;/h3&gt;

&lt;p&gt;Spaces are a safe, secure place where your Devices live. You can create as many Spaces as you would like adding your Devices to monitor and share with anyone, anywhere. &lt;a href="https://developers.wia.io/docs/getting-started-create-a-space" rel="noopener noreferrer"&gt;Learn how to create a Space&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F63b66f1-Dashboard_Illustrations_1024px_ViewSpace_FA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F63b66f1-Dashboard_Illustrations_1024px_ViewSpace_FA.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Lets add your Devices
&lt;/h3&gt;

&lt;p&gt;Harness the full power and potential of the IoT Devices you own. If it connects to the internet, it connects to Wia. We make it easy to connect and turn your Devices into smart applications within minutes. &lt;a href="https://developers.wia.io/docs/getting-started-add-a-device" rel="noopener noreferrer"&gt;Learn how to add a Device&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F184cb97-Dashboard_Illustrations_1024px_AddDevice_FA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F184cb97-Dashboard_Illustrations_1024px_AddDevice_FA.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Now publishing an event is as easy as 1,2,3
&lt;/h3&gt;

&lt;p&gt;Once your Device has been added, you can publish events to Wia, and watch them come through in real time. You can also add a widget to see your Device data in your favourite format (I will talk more about this below). &lt;a href="https://developers.wia.io/docs/getting-started-publish-an-event" rel="noopener noreferrer"&gt;Learn how to publish an Event&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fa8e2b3a-Dashboard_Events_1024px_FA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fa8e2b3a-Dashboard_Events_1024px_FA.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Taking it one fantastic step further
&lt;/h3&gt;

&lt;p&gt;Flow Studio is the easiest way to connect your IoT devices to your favourite services. We are integrated with applications such as Slack and Twilio to help you get all your data in the most convenient way possible, tailored just for you. &lt;a href="https://developers.wia.io/docs/getting-started-build-a-flow" rel="noopener noreferrer"&gt;Learn how to create your a Flow&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fc51f273-flows.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fc51f273-flows.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  The final step
&lt;/h3&gt;

&lt;p&gt;Its time to add in a Widget or Command. Our new Widgets provide you with an overview of the data gathered from your Devices. Widgets display data through Text, Images, Maps and Commands. &lt;a href="https://developers.wia.io/docs/add-a-widget" rel="noopener noreferrer"&gt;Learn how to add a Widget&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Commands allow you to control your Devices from near and far in a few simple lines of code. &lt;a href="https://developers.wia.io/v1.0/docs/add-a-command" rel="noopener noreferrer"&gt;Learn how to add a Command&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Ff27d7b1-Dashboard_Illustrations_Widgets_1024px_FA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Ff27d7b1-Dashboard_Illustrations_Widgets_1024px_FA.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you have any questions about how it works please ask, in the meantime many more tutorials are to come! Hope this helps explain Wia a bit more and will help with clarifying some of the tutorials I have posted.&lt;/p&gt;

</description>
      <category>iot</category>
      <category>platform</category>
      <category>beginners</category>
      <category>tutorials</category>
    </item>
    <item>
      <title>What type of tutorials do people like to see?</title>
      <dc:creator>Austin Spivey</dc:creator>
      <pubDate>Thu, 21 Jun 2018 14:47:13 +0000</pubDate>
      <link>https://dev.to/anspivey/what-type-of-tutorials-do-people-like-to-see-3f8</link>
      <guid>https://dev.to/anspivey/what-type-of-tutorials-do-people-like-to-see-3f8</guid>
      <description>&lt;p&gt;We are rolling out more and more tutorials everyday but I always like to hear what people are most interested and what they would like to see! Any feedback is greatly appreciated.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>tutorials</category>
    </item>
    <item>
      <title>Setup a Raspberry Pi Zero and Publish an Event to Wia</title>
      <dc:creator>Austin Spivey</dc:creator>
      <pubDate>Thu, 21 Jun 2018 12:00:36 +0000</pubDate>
      <link>https://dev.to/wiaio/setup-a-raspberry-pi-zero-and-publish-an-event-to-wia-2e93</link>
      <guid>https://dev.to/wiaio/setup-a-raspberry-pi-zero-and-publish-an-event-to-wia-2e93</guid>
      <description>&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fab3ee43-006.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fab3ee43-006.jpg" alt="Raspberry Pi Zero"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  &lt;strong&gt;Components&lt;/strong&gt;
&lt;/h4&gt;

&lt;p&gt;You will need the following components:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Raspberry Pi Zero&lt;/li&gt;
&lt;li&gt;microSD card&lt;/li&gt;
&lt;li&gt;SD card adapter&lt;/li&gt;
&lt;li&gt;Micro USB to USB cable&lt;/li&gt;
&lt;li&gt;Ethernet cable and micro USB to ethernet adapter (if connecting via ethernet)&lt;/li&gt;
&lt;li&gt;Compatible WiFi chip (if connecting via WiFi) and USB to micro USB adapter if necessary&lt;/li&gt;
&lt;li&gt;Computer with an SD slot (or an appropriate SD card adapter)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Installing the operating system&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Download &lt;a href="https://downloads.raspberrypi.org/raspbian_latest" rel="noopener noreferrer"&gt;Raspbian&lt;/a&gt; and extract the .img file

&lt;ul&gt;
&lt;li&gt;On Windows, right-click on the Zip file in your downloads folder and click &lt;code&gt;Extract All&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Insert the microSD into your computer's SD card slot via the SD card adapter&lt;/li&gt;

&lt;li&gt;Next, you'll need to flash the Raspbian image to the microSD. There are various applications you can use to do this, such as &lt;a href="https://etcher.io/" rel="noopener noreferrer"&gt;Etcher&lt;/a&gt; for Linux, macOS or Windows&lt;/li&gt;

&lt;li&gt;Open the SD card from your file explorer - the drive will be labelled &lt;code&gt;boot&lt;/code&gt;
&lt;/li&gt;

&lt;li&gt;SSH access is disabled by default. To enable it, create an empty file in the &lt;code&gt;boot&lt;/code&gt; drive called &lt;code&gt;ssh&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;On Windows, inside the &lt;code&gt;boot&lt;/code&gt; directory, right-click in the white space, scroll to &lt;code&gt;New&lt;/code&gt; and select &lt;code&gt;Text Document&lt;/code&gt;. Enter &lt;code&gt;ssh as&lt;/code&gt; the name&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Connecting to the network&lt;/strong&gt;
&lt;/h3&gt;

&lt;h4&gt;
  
  
  Option 1 - Via ethernet
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Connect the Raspberry Pi to your router via the micro USB to ethernet adapter and ethernet cable, and proceed to the next section.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Option 2 - Via WiFi
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Connect your WiFi chip to your Raspberry Pi via the micro USB port.&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  On Mac/Linux
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Create a new file in the &lt;code&gt;boot&lt;/code&gt; drive called &lt;code&gt;wpa_supplicant.conf&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Follow code step below&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  On Windows
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Download and install Notepad++ from &lt;a href="https://notepad-plus-plus.org/download" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Once installed, inside Notepad++ go to &lt;code&gt;File &amp;gt; New&lt;/code&gt; to create a new file.&lt;/li&gt;
&lt;li&gt;In the top bar, select &lt;code&gt;Edit &amp;gt; EOL Conversion&lt;/code&gt;. Make sure &lt;code&gt;Unix (LF)&lt;/code&gt; is selected. It should appear disabled if it is.&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;File &amp;gt; Save&lt;/code&gt; as, navigate to your &lt;code&gt;boot&lt;/code&gt; drive and call the file &lt;code&gt;wpa_supplicant.conf&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;
  
  
  All OSs
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Paste in the following code:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Text&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; country=IE
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1

network={
  scan_ssid=1
  ssid="Your-SSID"
  psk="Your-PSK"
  key_mgmt=WPA-PSK
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;Your-SSID&lt;/code&gt; with your WiFi network, and &lt;code&gt;Your-PSK&lt;/code&gt; with your WiFi password.&lt;br&gt;
This file will tell the Raspberry Pi to connect to the specified network when it boots up.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fdace3c3-Screenshot_from_2018-03-27_16-53-50.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fdace3c3-Screenshot_from_2018-03-27_16-53-50.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: Make sure your computer is connected to the same network as your Raspberry Pi.&lt;/strong&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Booting up the board&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Eject the microSD card and insert it into the Raspberry Pi's microSD slot&lt;/li&gt;
&lt;li&gt;Connect the &lt;code&gt;PWR IN&lt;/code&gt; micro USB on your Raspberry Pi to a 5v power source (e.g. your computer's USB port)&lt;/li&gt;
&lt;li&gt;Wait for the board to boot up - the green LED should stop flashing when it's finished booting up&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;
  
  
  &lt;strong&gt;Get your Raspberry Pi's IP Address&lt;/strong&gt;
&lt;/h3&gt;
&lt;h4&gt;
  
  
  Option 1 - Login to your router
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;If you have access to your router, you can login to it's admin panel via a browser. It's usually something like &lt;code&gt;192.168.0.1&lt;/code&gt;, &lt;code&gt;192.168.1.1&lt;/code&gt; or &lt;code&gt;192.168.1.254&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Look at the list of devices and find the IP address of your Pi. It should look something like &lt;code&gt;192.168.1.8&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note: Please note&lt;/strong&gt;&lt;br&gt;
When entering a password in terminal or command prompt, you won't see it being typed, for security reasons. Simply type the password and hit the enter key.&lt;/p&gt;
&lt;h4&gt;
  
  
  Option 2 - Scan using Nmap
&lt;/h4&gt;

&lt;p&gt;The nmap command (Network Mapper) is a free and open-source tool for network discovery, available for Linux, macOS, and Windows.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;To install on Linux, install the nmap package. To do this, load your terminal and run the command &lt;code&gt;apt-get install nmap&lt;/code&gt;. (If it does not run due to permissions, try &lt;code&gt;sudo apt-get install nmap&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;To install on macOS or Windows, see the nmap.org download page &lt;a href="https://nmap.org/download.html" rel="noopener noreferrer"&gt;here&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To use nmap to scan the devices on your network, you need to know the subnet you are connected to. First find your own IP address, in other words the one of the computer you're using to find your Pi's IP address:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;On Linux, type &lt;code&gt;hostname -I&lt;/code&gt; into a terminal window&lt;/li&gt;
&lt;li&gt;On macOS, go to &lt;code&gt;System Preferences&lt;/code&gt; then &lt;code&gt;Network&lt;/code&gt; and select your active network connection to view the IP address&lt;/li&gt;
&lt;li&gt;On Windows, go to the &lt;code&gt;Settings&lt;/code&gt;, then under &lt;code&gt;Network and Internet&lt;/code&gt;, select your connection type i.e. Wi-Fi, Ethernet, click Properties (for some this is called &lt;code&gt;Hardware Properties&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;In here, you will see &lt;code&gt;IPv4 address&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Now you have the IP address of your computer, you will scan the whole subnet for other devices. For example, if your IP address is 192.168.1.5, other devices will be at addresses like &lt;code&gt;192.168.1.2&lt;/code&gt;, &lt;code&gt;192.168.1.3&lt;/code&gt;, &lt;code&gt;192.168.1.4&lt;/code&gt;, etc.&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In your terminal or Command Prompt, now use the nmap command with the -sn flag (ping scan) on the whole subnet range. This may take a few seconds:&lt;br&gt;
&lt;code&gt;nmap -sn 192.168.1.0/24&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note: The 192.168.1 part in the command above should be replaced by the first 3 parts of the IP address you attained previously.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Ping scan just pings all the IP addresses to see if they respond. For each device that responds to the ping, the output shows the hostname and IP address like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Starting Nmap 6.40 ( http://nmap.org ) at 2018-04-02 12:51 GMT
Nmap scan report for Conalls-MBP (192.168.1.4)
Host is up (0.0017s latency).
Nmap scan report for iPhone (192.168.1.45)
Host is up (0.0021s latency).
Nmap scan report for raspberrypi (192.168.1.8)
Host is up (0.0038s latency).
Nmap done: 256 IP addresses (3 hosts up) scanned in 2.21 seconds
Here you can see a device with hostname raspberrypi has IP address 192.168.1.8.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Option 3 - Use the hostname
&lt;/h4&gt;

&lt;p&gt;By default, the hostname for the &lt;code&gt;Raspberry Pi&lt;/code&gt; is raspberrypi. If you cannot get your IP address, you can try using &lt;code&gt;raspberrypi.local&lt;/code&gt; instead.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Connecting to Raspberry Pi via SSH&lt;/strong&gt;
&lt;/h3&gt;

&lt;h5&gt;
  
  
  On Mac and Linux
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Open a terminal window, and run &lt;code&gt;ssh pi@ip-address&lt;/code&gt;

&lt;ul&gt;
&lt;li&gt;Replace &lt;code&gt;ip-address&lt;/code&gt; with the one you attained in the previous step&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;You will be prompted to enter a password - the default password is &lt;code&gt;raspberry&lt;/code&gt;
&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F8fc3efc-Screenshot_from_2018-03-27_16-49-33.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F8fc3efc-Screenshot_from_2018-03-27_16-49-33.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h5&gt;
  
  
  On Windows
&lt;/h5&gt;

&lt;ul&gt;
&lt;li&gt;Download Putty from &lt;a href="https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html" rel="noopener noreferrer"&gt;here&lt;/a&gt; to allow you to communicate with your board via SSH.&lt;/li&gt;
&lt;li&gt;Under &lt;code&gt;Host Name (or IP address)&lt;/code&gt; enter the IP address for your Raspberry Pi.&lt;/li&gt;
&lt;li&gt;Click the &lt;code&gt;Open&lt;/code&gt; button to create the connection.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fdb97bb0-d4ed00b-connect-to-pi-via-putty-2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2Fdb97bb0-d4ed00b-connect-to-pi-via-putty-2.PNG" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;Publishing an event to Wia&lt;/strong&gt;
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Once you're connected to the Raspberry Pi via SSH, run &lt;code&gt;sudo apt-get install python-pip&lt;/code&gt; to install pip, a package manager&lt;/li&gt;
&lt;li&gt;Run sudo &lt;code&gt;pip install wia&lt;/code&gt; to install the Wia SDK.&lt;/li&gt;
&lt;li&gt;Create a new directory for your project by running &lt;code&gt;mkdir my-project&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Navigate into this new directory by running &lt;code&gt;cd my-project&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For this tutorial, we'll use python, but you can also use our &lt;a href="https://github.com/wiaio/wia-nodejs-sdk" rel="noopener noreferrer"&gt;Node.js SDK&lt;/a&gt;.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create a new python file by running touch test.py.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Note: You can name the file anything you want, but make sure you don’t name it ‘wia.py’ as this will cause an ImportError.&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Edit the file with &lt;code&gt;nano test.py&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Paste in the following code snippet to get started:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Python&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; from wia import Wia

wia = Wia()
wia.access_token = "your-access-token"

wia.Event.publish(name="temperature", data=21.5)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;your-access-token&lt;/code&gt; with your device's secret key (you can find this in your Wia dashboard, it begins with &lt;code&gt;d_sk&lt;/code&gt;), and save the file by following the on screen instructions at the bottom.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F89b6898-Screenshot_from_2018-03-27_16-45-30.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F89b6898-Screenshot_from_2018-03-27_16-45-30.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run your newly created script by running &lt;code&gt;python test.py&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Navigate to the Wia Dashboard and you'll see that your device is connected&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F37f0199-Screenshot_from_2018-03-28_09-55-45.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F37f0199-Screenshot_from_2018-03-28_09-55-45.png" alt="alt text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Navigate to the 'events' tab, and you'll see an event has been published
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Ffiles.readme.io%2F83a6a2e-Screenshot_from_2018-03-28_09-57-29.png" alt="alt text"&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>raspberrypi</category>
      <category>tutorial</category>
      <category>beginners</category>
      <category>python</category>
    </item>
  </channel>
</rss>
