How to setup a local API for Home IoT Devices in your office using WiFi
Tags: iot, api, python, ruby
Published: 2020-09-03 11:02:27

## Small offices can profit from Home IoT devices made programmable with OSS

If you are working in an office with up to eight rooms, you may find yourself overlooked by commercial IoT solutions promising the typical benefits, e.g. energy savings, security improvements, disaster detection and other facility management improvements.

Luckily there are plenty of Home IoT product series on the market that you can use. Unfortunately, they are usually closed proprietary systems and don’t target specific office needs. At Xapix, we decided to open source our Industrial Internet of Things (IIoT) Server software that enables you to access common consumer-market Home IoT devices and develop custom office automation software against an HTTP API in your local office WiFi.

If you’d like an even simpler solution, you can enable the IIoT Server’s bridge to the free Xapix Community Edition and use the ready-made Xapix data pipelines. 

This blog series explains how to save money, and improve security and convenience in small offices using consumer-market Home IoT devices. 

## Get started with a Home IoT test environment

This post sets up the technical work for the rest of the series with just a little bit of hacker spirit. 

Most Home IoT device series are closed proprietary systems that often involve a gateway hub device and a vendor mobile app. We need a way to programmatically access the Home IoT devices, e.g. via an HTTP API, from within the local office WiFi as you do not want to expose it to the internet for security reasons.

Within this post, we explain how to set up a local API to a Home IoT light bulb on your development computer using our freshly released Open Source project [IIoT Server](https://github.com/xapix-io/iiot_server) and test your setup with a sample HTTP request via cURL or Postman.

If you have a [free Xapix Community Edition account](https://cloud.xapix.io/users/sign_up), we can even take the test setup one step further and create a Xapix pipeline. You’ll be able to turn your light bulb on and off with your web browser or cURL.

![Switch on bulb using Postman](https://dev-to-uploads.s3.amazonaws.com/i/uvtincq813fgh8j449y7.gif)

We will describe the setup process for a Mac computer and a light bulb, hub device, and dimmer of a globally operating swedish furniture chain. Feel free to use other hardware - the setup process is likely to be similar and we’d be happy to help if you want to reach out to us directly, e.g on our [Discord community channel](http://bit.ly/discord-xapix).

## Send HTTP API requests to your Home IoT devices within your local WiFi

Setting up the Home IoT devices as documented by the vendor is the first step. You can follow the instructions that the maker includes in the product. For our devices, we connect the hub device to the office router and power plug and then use the vendor mobile app to register the hub device with the app. 

Put batteries into the dimmer and register it with the vendor mobile app by putting the dimmer close to the hub and pressing the hub’s link button. Your hub device now manages your dimmer.

To register your light bulb with the app, plug in your light bulb, hold the dimmer close to the bulb and press the dimmer’s link button. Your hub now manages the dimmer, the dimmer manages your light bulb and the vendor mobile app controls everything. With the app or dimmer you should be able to dim, turn on and turn off the light bulb. The app additionally will allow you to change light color.   

To do the same with cURL, Postman or your favourite programming language’s HTTP library, go ahead and download and install the Xapix [IIoT Server](https://github.com/xapix-io/iiot_server) and it’s dependency software libraries. Follow the setup instructions and install the necessary libraries. 

One of the trickier steps is finding the IP address of your hub device within your local WiFi. You can best find it in your router’s administration UI. On a Mac you can also run `arp -a` in a terminal window and look for the IP address associated with your hub device’s MAC address to be found on the back of the device.

Once everything is configured, run the IIoT Server in a terminal window and next, to programmatically turn on your light bulb for the first time, run the cURL command:

```
curl --location --request POST 'localhost:4567/device_cmd' \
--header 'Content-Type: application/json' \
--data-raw '{
	"device": "test_bulb",
	"action": {
		"cmd": "bulb_on"
	}
}’
```

Congratulations! You are now good to go ahead and develop your own custom applications for your local office’s IoT setup.

## Getting ready to integrate cloud APIs and services with your Home IoT setup

If you are interested in some easy paths to advanced tasks, especially when using web APIs and services, then we recommend trying our free [Xapix Community Edition](https://cloud.xapix.io/users/sign_in) that seamlessly integrates with the IIoT Server when enabled. With Xapix, you can start by creating a basic data pipeline to test your setup and from that point onward, integrations with different APIs for solving your use-cases, e.g. weather forecast APIs or text notification APIs, will only be a few clicks away.

If interested, then **[> CONTINUE READING <](https://www.xapix.io/post/how-to-set-up-a-local-api-for-home-iot-devices-in-your-office-using-wifi?utm_source=dev-to&utm_medium=editorial&utm_campaign=home_automation_1)** the full version of this article on our Xapix blog.

## Join our Home IoT community

We are working on numerous follow-ups to this blog-series and will be posting updates regularly within our Discord community to help inspire you on how best to make use of the Xapix IIoT Server once you have set it up. We would love to hear your ideas too and collaborate on this fun project. 

Please contact us on our [Discord community channel](http://bit.ly/discord-xapix) if you would like to discuss this tutorial or if you have questions or feedback about the Xapix Community Edition. Or really anything else as well. We look forward to hearing from you!