REST Platform With Android App for IoT Device

by joon874 in Circuits > Remote Control

990 Views, 10 Favorites, 0 Comments

REST Platform With Android App for IoT Device

20160708_130917.png
20160706_091620.png
그림1.png

Hello, All

Before this, I made REST Platfrom, WIZwikiREST-io with WIZwiki-W7500ECO board.

And I posted it on https://www.instructables.com/id/WIZwikiREST-io/

At that time, the platform has only GPIO and control LED by App.

So, I decide to add more peripherals to use platform for IoT and other makers who think it is so hard to make IoT device.

That is why I post it again as upper version, WIZwikiREST-io ver1.01 !!

Step 1: WIZwikiREST-io Ver 1.01 Features

  • Using WIZwikiREST-io platform
  • Add peripherals
    • GPIO
    • PWM
    • I2C
  • Possible to add JSON format Resource define
  • Possible to add Service define
  • No need parsing to get value from data

Step 2: How to Add User Define

20160706_091556.png
wizwiki_w7500_pinout_wiki_150701_detail.png

It is not hard to add User define.

It means User can define pin function(gpio, adc, pwm ... etc), json format uri and even callback function.

Now let me explain how to add GPIO, PWM, I2C

1. Declare Pin

//-- I2C OLED --
I2CPreInit gI2C(PA_10,PA_9);
//-- PWM DC --
PwmOut DC(D6);
//-- GPIO LED --
DigitalInOut GP05(D5);

In this case, I used mbed web compiler. And I used Adafuit_GFX library to handle OLED with I2C. That is why I declare I2C pins in I2CPreInit class. You can check with below open source.

Step 3: Define User Resource

2. Define user resource

    //Fill the object
    WIZwikiREST["Name"] = "WIZwikiREST-io ver1.01";
    WIZwikiREST["Name"].accessible = false;

    //Network
    WIZwikiREST["Network"]["MAC"] = mac_str;
    WIZwikiREST["Network"]["IP"] = ip_addr; 
    WIZwikiREST["Network"]["IP"].accessible = true; 
    WIZwikiREST["Network"]["SN"] = subnet_mask;  
    WIZwikiREST["Network"]["SN"].accessible = true;  
    WIZwikiREST["Network"]["GW"] = gateway_addr;
    WIZwikiREST["Network"]["GW"].accessible = true;
    
    // I2C OLED
    WIZwikiREST["I2C"]["OLED"] = "none";
    WIZwikiREST["I2C"]["OLED"].accessible = true;
    WIZwikiREST["I2C"]["OLED"].cb_action = oled_set;
    
    // PWM DC
    WIZwikiREST["PWM"]["DC"] = DC.read();
    WIZwikiREST["PWM"]["DC"].accessible = true;
    WIZwikiREST["PWM"]["DC"].cb_action = pwm_set;
    
    // GPIO
    WIZwikiREST["GPIOs"]["P05"] = GP05.read();
    WIZwikiREST["GPIOs"]["P05"].accessible = true;
    WIZwikiREST["GPIOs"]["P05"].cb_action = p5_set;</p>

In main.cpp, user can find JSON format resource defined. It is not hard.

In here, user can define the URI, and decide it is acceptable or not. It means the value can be changed by URL.

If you set ".accessible = false" , none change the value. WIZwikiREST["GPIOs"]["P05"] = GP05.read(); ["GPIOs"]["P05"] is like direction to approach the value.

So, if user want to change the pin 05 value, user need to type " xxx.xxx.xxx.xxx(platform ip)/GPIOs/P05/1 (or 0) "

And GP05.read() is initial value. Also define value type.

so, the value will be integer type. It means, user need to type int value when send URL data. At the last, ".cb_action" is the callback function.

Step 4: Define Callback Function

20160706_091609.png
20160706_091430.png

Now, I will explain the callback functions I designed. It is so easy.

//-- I2C OLED --<br>bool oled_set(void* param)
{
    char * oled;
    if(!param) return false;
    oled = (char*) param;
    gOled.clearDisplay();
    gOled.setTextCursor(0,0);
    gOled.printf("%s",oled);
    gOled.display();    
    return true;
}


//-- PWM DC --
bool pwm_set(void* param)
{
    if(!param) return false;
    DC.write((float)(*(int*)param)/100.0);
    return true;
}


//-- GPIO --
bool p5_set(void* param)
{
    if(!param) return false;
    GP05.write(*(int*)param);
    return true;
}

Those three functions are callback function defined upper layer. As I said I used Adafuit library to control OLED so, I used functions offered by library. Other things are from mbed library. When function called, it get value in URL as function parameter and no need to think about value type. because REST platform defines value type.

Step 5: Hardware

20160708_130220.png
HTB1xg37FFXXXXcZXFXXq6xXFXXXl.jpg
-5mm-LED.jpg
938-15.jpg

Platform board :

WIZwiki-W7500

WIZwiki-W7500ECO

Components :

Adafruit 128by64 OLED (https://www.adafruit.com/product/938)

Mini Fan

LED

Step 6: Android App

20160706_091352.png
app.jpg
20160707_164002.png
20160708_132413.png

WIZwikiREST-io ver1.01 App has 5 screens.

  • Main Screen
  • Peripheral Select Screen
  • GPIO control Screen
  • PWM control Screen
  • I2C text send Screen

It is based on MIT App inventor 2.

Anyone can download and refer the open app source.

Only one thing user have to know for using.

Actually, App should support changing IP address. Because usually REST Platform running on DHCP and IP address could be changed some times.

But in this App I made has no changing IP Address function.

So, User have to write it on App source code. I added where should re-type.

And also I will release upper version to support setting network information.

Step 7: Open Source

20160706_091519.png

Android App open source and WIZwikiREST-io ver1.01 open source

Here is the link to download WIZwikiREST-io ver1.01 : https://developer.mbed.org/users/joon874/code/WIZw...

Thank you!