"The only constant in life is change." — Heraclitus
At the last 5 years, architecture of everything was starting to change with IoT. Music players, TVs, cameras, lambs and other all have gone to work with IoT and mobile... When we focused on all this IoT things, we forgot to change most important thing in our life: socket! Now, I think the time to change architecture of sockets design. When this happen and adapt to our life, future tech will be easier and better than now. For this, I suggest you an innovative socket idea: intelliPWR!
ScenarioAs you can see at below, I added 5 linear pins for communication of I2C. When You plug any of this type redesigned device to this socket, socket will start to communicate with this device and will update your mobile application based on your device. Most important things in this point, both female and male socket must have same structure as that.
Otherwise, communication can't start but that isn't a problem because I added a solid-state relay to inside for switching power of mains power. You can use this relay for switching power of old designed devices.
So, probably you can ask that what is the advantage factor of this sockets. Let's take a look:
- You don't need to make setup for each device. You can plug it and use it.
- You can manage and control all of your device from an application. We will call this app as openHAB on the next steps.
- You don't need to integrate a Wi-Fi SOC to each device one-by-one. Your power socket can do your Wi-Fi communication for you.
- Also, you can downgrade your cost with one Wi-Fi SOC for multiple devices by looking at previous article.
- For each device, you only need to write device library. No more about Wi-Fi.
- You can control as on-off switch your older devices that can not compatible with this architecture.
First of everything, we need to design our circuit diagram. At this point, I will approach 2 different circuit diagrams on the project: level shifter and lamb fade-out.
With the level shifter side, we will make a 3.3V to 5V level shifter circuit for slave devices. We need to make this because I2C of Netduino is working with 3.3V. That can cause a lot problem in the future because lots of dev board is running with 5V.
On another hand, I bought a switch button which has a white led that can notify users. I chose this for better user experience, you can choose another one but when you choose this, maybe you can want to make a fade-out effect on button led. For chancing the time of fade-out, you can use a bigger or lower value of capacitor.
When all of them on the above is done, you will arrive half of all of core circuit diagram. After that, we will link with each together and lastly, we will add SSR pins.
- LED1: Status input of Led of Button1
- LED2: Status input of Led of Button2
- SSR1: Relay of Power Socket
- SSR2: Relay of Button1
- SSR3: Relay of Button2
On the coding step, I wrote 2 different .NET libraries for this project: Serializer and MasterScanner libraries.
MasterScanner library scan I2C bus as event-driven method. When a device connects to master or disconnects from master, triggers a registered function about situation. You can recalibrate bus scanning ranges, clock speed and timeout.
For event-drive usage, you need to register a function to OnConnected and a function to OnDisconnected. Otherwise, you can't understand which address was connected or not.
public ConnectedEventHandler OnConnected;
public DisconnectedEventHandler OnDisconnected;
public MasterScanner();
public MasterScanner(byte startAddress, byte stopAddress);
public MasterScanner(ushort clockSpeed, ushort timeout);
public MasterScanner(ushort clockSpeed, ushort timeout, ushort retryCount);
public MasterScanner(byte startAddress, byte stopAddress, ushort clockSpeed, ushort timeout, ushort retryCount);
public bool IsConnected(byte address);
public void ResetRange();
public void ScanSlaves(I2CDevice Device);
public bool SetRange(byte startAddress, byte stopAddress);
Serializer library decodes or encodes a given data with given delimiters array. When you have a string array and you want to add a special delimiter between each string, you can use this library. Also, you can use it at total opposite.
public Serializer();
public string[] Decode(char delimiter, string data);
public string[] Decode(char[] delimiter, string data);
public string Encode(char delimiter, string[] data);
public string Encode(char[] delimiter, string[] data);
public string Encode(bool startWithDelimiter, char[] delimiter, string[] data);
I used all these libraries on I2C communication of my main program. In the main program, I wrote an algorithm that can send and receive function from slave.
For example, assume that we have a device which can detect the temperature, humidity, smoke and carbon monoxide of environment. We will call it as slave device. When we connect this slave device to master device, master will start to scan the all function of slave device. After the scanning, master will fetch the all vendor and function data and store all of them in itself. When a situation triggered by users, related function will call by master and communication will start with slave device. A visual example is given at below:
For mobile app side, we will use openHAB application. The open Home Automation Bus (openHAB) is an open source, technology agnostic home automation platform which runs as the center of your smart home. For using this platform, you wil need a server that can run openHAB core. In additional, you will need a MQTT broker for listening published message and publishing message. We will choose Mosquitto MQTT for this step.
For more information about installation of openHAB and MQTT, you can follow detailed instruction that provided by openHAB Community and the openHAB Foundation. If you still need instruction about installation of both, you can access it from below:
# Refresh database
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y software-properties-common
# Install Java, openHAB need it
sudo add-apt-repository ppa:webupd8team/java
sudo apt update; sudo apt install oracle-java8-installer
javac -version
sudo apt install oracle-java8-set-default
# Install openHAB
wget -qO - 'https://bintray.com/user/downloadSubjectPublicKey?username=openhab' | sudo apt-key add -
sudo apt-get install apt-transport-https
echo 'deb https://dl.bintray.com/openhab/apt-repo2 stable main' | sudo tee /etc/apt/sources.list.d/openhab2.list
sudo apt-get update
sudo apt-get install openhab2
sudo apt-get install openhab2-addons
# Add it on startup
sudo systemctl start openhab2.service
sudo systemctl status openhab2.service
sudo systemctl enable openhab2.service
After the openHAB installation, you must to install Mosquitto and UFW:
# Install Mosquitto
sudo apt-get install mosquitto mosquitto-clients
sudo apt-get update
sudo apt-get install mosquitto
Your server and broker is ready now but not secure! For protecting it we will add following two entries to the mosquitto.conf file but before we need to stop Mosquitto server.
# If you have just installed the Mosquitto broker, make sure its stopped
sudo systemctl stop mosquitto.service
sudo mosquitto_passwd -c /etc/mosquitto/passwd <USER_NAME>
With the second line of given code, you will see the editor panel of password file. Before this step, you must to set specific username when calling this entry. You must do this step again for your password on the next step.
password_file /etc/mosquitto/passwd
allow_anonymous false
We need to restart broker again for modifications:
# Restart the server again
mosquitto -c /etc/mosquitto/mosquitto.conf
sudo systemctl start mosquitto.service
After all, openHAB must have installed on your OS with Mosquitto MQTT broker. The first start of openHAB may take up to 15 minutes. When this time passed, you should be able to reach the openHAB Dashboard at http://openhab-device:8080 address.
On the next step, aka installing UFW, run following commands on terminal:
# Install UFW
sudo apt-get install ufw
# Check status of UFW, not required
sudo ufw status
sudo ufw allow 1883
sudo ufw allow ssh
sudo ufw allow 22
# Enable on the end
sudo ufw enable
When you did all of this step correctly, you will have 3 different value as username, password and port. We will use all of these variables for calibrating remote-control device. After all, your server will be ready for using it. You can detect the status of server with pinging it on PuTTY and publishing an example topic/message on MQTT.fx. I am passing this step...
Now, we can use our openHAB server. For mobile app side, we need to add a sitemap to openHAB server. Otherwise, message/topic can published but can't been accessible by users. For making this, I recommend you my git repo which includes some examples that given bottom of the article. Passing this step, too...
Step 4. 3D Part AssemblingActually, this step is not mandatory for you. I made all of these parts for better user experience. If you want to make it same, you can get all provided assembly files bottom of the article.
When I made all of these parts for this project, I discerned that a stand is required for holding maincase as straight. So, I went to IKEA and bought a wooden part. And after cut it based on my drawing.
Yeap, we finally arrived the latest step. The most important point in this step is wiring diagram of I2C. If you make mistake and reverse the connection of I2C, you can freeze your Netduino device. I2C can cause this type problem sometimes. Therefore, please be carefully.
There are 5 pieces pins on male socket port. First, the middle one connected to ground. Right side connected to SDA and the last one, aka left side, connected to SCL. The female part must be total opposite of this because of symmetry/mirroring.
ConclusionAs a result, we done a new generation power socket for next posterity. With this power socket, we rebuilt lastly designed IoT with new architecture. Now, it is more usable and powerful.
You can see all example usage on the below. I made two different devices for this IoT system. Both are working with Arduino Pro. One of them is listening values of air, other one is working as air conditioner.
Thanks for reading and spending time! Regards... (BOM: About 170 Dollars)
Comments