Wio Link project

Seeed Wio Link


Seeed Wio Link

The Seeed Studio Wio Link is an open-source WiFi development board that is based on an ESP8266 SoC WiFi microcontroller chip. The Wio Link enables a user to develop IoT applications using a variety of plug and play modules from the popular Seeed Grove range. Programming of the Wio Link can be done by means of an API using either an Android or iOS mobile App.

 

Wio Link

Wio Link Board

The set up instructions for the Wio Link are fairly straightforward, and can be found at the following link:-

http://www.seeedstudio.com/wiki/Wio_Link

For our setup, we used the Android version of the Wio Link app on a Google Nexus 5X phone.

Initial Setup

Unfortunately, our initial experience with the Wio Link board was a little problematic, as we were unable to get the Wio Link to attach to a WiFi hotspot that required a password (for example using WEP or WPA security). This meant having to set up a separate open WiFi hotspot running on a Raspberry Pi to enable us to connect to the Wio Link.

We had hoped that the issues we were having might have been down to the firmware on the Wio Link board, so we tried to update the board firmware using the instructions at the following link:-

https://github.com/Seeed-Studio/Wio_Link/wiki/Advanced%20User%20Guide#5-repair-bricked-wio-link

Unfortunately, even with the updated board firmware, we found we were still unable to attach the Wio Link to our router using WPA encryption; hence the need for a separate open WiFi hotspot. Additionally, even with this open WiFi, it did require a large number of attempts at setting up the Wio Link before we were able to successfully attach it to our WiFi.

New Improved Android App

Having experienced the problems we were having setting up the board, we initially put it to one side for a while. However, we later noticed that there was an updated version of the Wio Link Android app available, so we thought we’d have another go at using the board with the updated app, and we found this version of the app to work a lot better. The newer version of the Wio Link Android app allowed us to successfully connect the Wio Link to a router using WPA encryption, and the connection was successful on the first attempt.

Up and Running

Despite the initial problems setting up the Wio Link, once it was successfully linked to our WiFi we found it really easy to use. The set up instructions indicate how to connect devices to the Wio Link, and how to make use of the API within the mobile app in order to control the devices. The API make use of http POST and GET requests to control the devices connected to the Wio Link, and these POST and GET requests may be copied and pasted into other apps, or embedded into code in order to create user applications to control the devices. For example, the screen shot below shows the Google Chrome Postman app being used to send an http POST request to control a strip of 30 Neopixel LEDs.

Postman

Postman

Wio Link Neopixel strip

Wio Link Neopixel strip

Having successfully connected and set up our Wio Link, we thought we’d have a go at a fairly simple project using some of the bits that came with our Wio Link starter kit. As well as the Wio Link and micro USB cable, this starter kit included the following bits:-

  • Grove relay
  • Grove button
  • Grove digital light sensor
  • Grove WS812 30 LED strip
  • Grove temperature and humidity sensor
  • Grove 3-axis digital accelerometer
Seeed Wio Link starter kit

Seeed Wio Link starter kit

Wio Link Project

For our simple project, we took the Grove 30 LED strip, the digital light sensor and the temperature and humidity sensor, and connected it to our Wio Link board. Once connected, the board firmware needs to be updated to reflect the physical components that are connected to the board. This is done through the Android App. The screen shots below show how this is done through the Android App.

Wio Link Android screenshot

Wio Link Android screenshot

Wio Link Android screenshot

Wio Link Android screenshot

Once the Wio Link board firmware has been updated, the ‘View API’ screen in the Android App shows the various http GET and POST requests that can be used to control the board. For example, to get the temperature using the Grove digital temperature and humidity sensor, use the following http GET request (note that the access token will be different):-

https://us.wio.seeed.io/v1/node/GroveTempHumD1/temperature?access_token=0123456789abcdef0123456789abcdef

The physical setup of our project is shown in the picture below.

Wio Link project

Wio Link project

We found that the Grove digital light sensor was very sensitive to high ambient light levels, so we needed to place the light sensor inside a translucent resealable plastic bag.

Our simple project measures the ambient light level, and also the ambient temperature and humidity. The colour and brightness of the LEDs in the 30 LED strip are then altered; the brightness being controlled by the ambient brightness (in a dark room the LEDs will be dimmed, and in a bright room the LEDs will be made brighter), and the temperature and humidity controls the colour of the LEDs.

For our project we wrote a short Python script which we tried running on both a Raspberry Pi and a PC. For the PC we needed to install the ‘requests’ library. This was done using the following command in the Windows command window:-

pip install requests

The Python code for our simple Wio Link project is shown below:-

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import json
import time
import requests

wio_link_key = "access_token=0123456789abcdef0123456789abcdef"

LightSensor_Url = "https://us.wio.seeed.io/v1/node/GroveDigitalLightI2C0/lux" + "?" + wio_link_key
TempSensor_Url = "https://us.wio.seeed.io/v1/node/GroveTempHumD1/temperature" + "?" + wio_link_key
HumiditySensor_Url = "https://us.wio.seeed.io/v1/node/GroveTempHumD1/humidity" + "?" + wio_link_key
LED_Url_Prefix = "https://us.wio.seeed.io/v1/node/GroveLedWs2812D0/clear/30/"

TimeOutIndex = 0 # To Count how many times post url error

def UrlPost(url):
  result = requests.post(url)
  while result.status_code != 200: # if response error try again 10 times
    global TimeOutIndex
    TimeOutIndex = TimeOutIndex + 1
    time.sleep(1)
    result = requests.post(url)
    if TimeOutIndex == 10:
      TimeOutIndex = 0
      print("Can't access the Url, please check the Wio Link Connection")
      break

def UrlGet(url):
  result = requests.get(url)
  while result.status_code != 200: # if response error try again 10 times
    global TimeOutIndex
    TimeOutIndex = TimeOutIndex + 1
    time.sleep(1)
    result = requests.get(url)
    if TimeOutIndex == 10:
      TimeOutIndex = 0
      print("Can't access the Url, please check the Wio Link Connection")
      return result
      break
  return result

if __name__ == "__main__":
  while True:
    # Get ambient light level
    light_level = int(10)
    result = UrlGet(LightSensor_Url)
    if result.status_code == 200:
      data_json = result.json()
      light_level = int(data_json.get('lux') / 100)
    else:
      data_json = result.json()
      error = data_json.get('error')
    if light_level > 10:
      light_level = 10

    # Get temperature
    result = UrlGet(TempSensor_Url)
    if result.status_code == 200:
      data_json = result.json()
      temperature = data_json.get('celsius_degree')
    else:
      data_json = result.json()
      error = data_json.get('error')
      print error

    # Get humidity
    result = UrlGet(HumiditySensor_Url)
    if result.status_code == 200:
      data_json = result.json()
      humidity = data_json.get('humidity')
    else:
      data_json = result.json()
      error = data_json.get('error')
      print error

    # Set LED temperature/humidity string (6 digit hex)
    if light_level > 0:
      led_colour_r = int((temperature * 10) / light_level)
      led_colour_g = int((humidity * 5) / light_level)
      led_colour_b = int(255 / light_level)
    else:
      led_colour_r = int(temperature * 10)
      led_colour_g = int(humidity * 5)
      led_colour_b = int(255)

    led_string = '{0:02x}'.format(led_colour_r) + \
                 '{0:02x}'.format(led_colour_g) + \
                 '{0:02x}'.format(led_colour_b)

    LED_Url = LED_Url_Prefix + led_string + "?" + wio_link_key

    result = UrlPost(LED_Url)