REST Platform With Android App for IoT Device

details

 

Description:

Hello, All

Before this, I made REST Platform, 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 posted it again as upper version, WIZwikiREST-io ver1.01 !!

Step 1: 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: Step 2: How to Add User Define

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, the user can find JSON format resource defined. It is not hard.

In here, the 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 the user wants to change the pin 05 value, the user needs 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 the integer type. It means user need to type int value when sending URL data. At the last, “.cb_action” is the callback function.

Step 4: Define Callback Function

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 the library. Other things are from the mbed library. When function called, it gets value in URL as the function parameter and no need to think about value type. because REST platform defines value type.

Step 5: Hardware

Platform board :

Step 6: Android App

 

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 the user has to know about 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

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…

wizwikirest_v101.aiawizwikirest_v101.aia    Download

Author: 

 

For more information:

https://www.instructables.com/id/REST-Platform-With-Android-App-for-IoT-Device/

 

Description:

Hello, All

Before this, I made REST Platform, 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 posted it again as upper version, WIZwikiREST-io ver1.01 !!

Step 1: 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: Step 2: How to Add User Define

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, the user can find JSON format resource defined. It is not hard.

In here, the 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 the user wants to change the pin 05 value, the user needs 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 the integer type. It means user need to type int value when sending URL data. At the last, “.cb_action” is the callback function.

Step 4: Define Callback Function

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 the library. Other things are from the mbed library. When function called, it gets value in URL as the function parameter and no need to think about value type. because REST platform defines value type.

Step 5: Hardware

Platform board :

Step 6: Android App

 

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 the user has to know about 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

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…

wizwikirest_v101.aiawizwikirest_v101.aia    Download

Author: 

 

For more information:

https://www.instructables.com/id/REST-Platform-With-Android-App-for-IoT-Device/

COMMENTS

Please Login to comment
  Subscribe  
Notify of