Introduction: Adding REST-based Web Services to IoT Device for IO Monitoring

Picture of Adding REST-based Web Services to IoT Device for IO Monitoring

This project is to make a simple RESTful Web service library for IoT Devices. The library is written with C language code and on WIZwiki-W7500ECO platform board from WIZnet. With it, users can implement a RESTful Web service on IoT devices easily. Monitoring IoT devices can be done by RESTful API based on JSON, as well.

* Frozen JSON parser and generator for C/C++ included

* APIs for HTTP POST method will be added

* The post will be update continuously

Step 1: Parts

Picture of Parts

WIZnet WIZwiki-W7500ECO Platform board

  • WIZwiki-W7500ECO is a compact platform board based on W7500, which is a SOC chip that integrates an ARM Cortex-M0, 128KB Flash memory and hardwired TCP/IP core.
  • W7500 is the best fit to IoT devices.

A computer for using KEIL uVision5 IDE

  • These library is developed and compiled with uVision5 IDE.

Step 2: Download, Build and RUN

Download the RESTful Web Server & I/O Control by REST API Project on GitHub repository

Build and Firmware write to target board: WIZwiki-W7500ECO

  1. Project Build
  2. Firmware Write
    • Writing firmware into WIZwiki-W7500ECO has three ways
      1. Using the CMSIS-DAP (Drag and Drop)
      2. Using the CMSIS-DAP (through Keil uVision5)
      3. Using the ISP (ISP, In-System Programming)
      4. For more details, Please refer to WIZnet wiki site; How to write the firmware into WIZwiki-W7500ECO

Step 3: REST API Design

REST API Document is under construction.

[:id] : pre-defined 4-IO pins, 'a', 'b', 'c', 'd'.

  • 'a' : P30 pin (digital input / digital output / analog input)
  • 'b' : P29 pin (digital input / digital output / analog input)
  • 'c' : P28 pin (digital input / digital output / analog input)
  • 'd' : P27 pin (digital input / digital output / analog input)

HTTP GET method:Get the device info and IO status / value

  • http://w7500xRESTAPI.local/index
  • http://w7500xRESTAPI.local/uptime
  • http://w7500xRESTAPI.local/netinfo
  • http://w7500xRESTAPI.local/userio
  • http://w7500xRESTAPI.local/userio/:id
  • http://w7500xRESTAPI.local/userio/:id/info

HTTP POST method:Enable the assigned IO

  • http://w7500xRESTAPI.local/userio/:id

HTTP PUT method* (in development) : Set the IO status (digital output only) and IO configuration

  • http://w7500xRESTAPI.local/userio/:id
  • http://w7500xRESTAPI.local/userio/:id/info

HTTP DELETE method:Disable the assigned IO

  • http://w7500xRESTAPI.local/userio/:id

Step 4: Testing: HTTP Get Method

Picture of Testing: HTTP Get Method

Connect your board to your network and REST API Testing with test tool. These library has been tested on Postman Builder. For more details about Postman, please refer to Postman Chrome webstore.

Step 5: Testing: HTTP POST and DELETE Method

Picture of Testing: HTTP POST and DELETE Method

Step 6: Testing: Errors and Serial Debug

Picture of Testing: Errors and Serial Debug

Comments

webmonger (author)2016-04-10

This looks like a great article thanks for posting but I'd just like to raise a potential security issue in relation to running unauthenticated web services on hardware that could cause damage to both your device and potentially your home. I understand the need to make requests to iot devices and also the wish to remotely make them do things however this also raises security issue when the devices are not secured properly. There are many articles on the Internet in relation to securing hardware which are too numerous to mention here however here are a few things. Never open ports to your device so this can be controlled from outside your network, remember any friend of fo who has access to your network also has access to this device to control it so be careful, use authentication where possible so not just anyone can access it and always connect over https.

IMO a better architecture for IoT devices is to have them connect to an external secure web service that allows the IoT device to both post and get commands from. Both AWS and Azure have APIs which would allow you to do this for free and I'm sure there are lots of articles which can help get these setup. Once this is done you have both access from within your home and also where ever you are outside too. I believe both services have OAuth configurations so you'll also be able to easily manage the security as well.

Hope this helps and happy IoT developing :)

About This Instructable

6,345views

62favorites

License:

Bio: Embedded Firmware Engineer / Researcher. I'm Interested in IoT platforms and OpenSourceHardWare like arduino, Cloud, Web / App and product development.
More by Eric.Hyungki.Jung:Building Your Android Apps for monitoring IoT devices using REST APIAdding REST-based Web Services to IoT Device for IO monitoringWeb Manager development for WIZnet Serial to Ethernet modules
Add instructable to: