remotely control IOT smart hardware by Wechat Application
New Features
What feature(s) did you add?
Before reading
In China , Wechat is a communication tool developed by Tencent technology company.Almost all the people in China use Wechat App to communicate with others.Wechat is just like facebook or twitter.
So I develop this project for promoting our life convenience,letting us not only use wechat to chat with our lovers and family ,but also use wechat to control our home appliance whenever and wherever we are .
Briefly describe
Previous , I wrote the function of controlling the MCU remotely through the Web UI.
Now I add the additional way to remote control the MCU,which is controlling through a Wechat Application.
How did you implement it/them?
- Briefly introduce
Add Wechat control server script.
In this file,there are three parts
- downup.php : connect the server with ESP8266
- index.php : connect wechat official server with my server
- switch.sql: Save the control variable into database
Add ESP8266 firmware : ESP8266 connect to WIFI and HTTP request to server ,then get control variable
- Show some of the new code
index.php:
if (strstr($content, "1ON")) { $con = mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS); $dati = date("h:i:sa"); mysql_select_db("app_steemitcha0s0000", $con);//修改数据库名 $sql ="UPDATE switch SET timestamp='$dati',state = '1' WHERE ID = '1'";//修改开关状态值 if(!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); }else { mysql_close($con); $reply = "I am going to switch on the LED 1"; } }According to the wechat server Communication protocol,we can get the data which the user send to the wechat application.
Identify what the data is and then change the database data .
downup.php
<?php if (($_GET['token'] == "weixin")) { $con = mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS); $data = $_GET['data']; mysql_select_db("app_steemitcha0s0000", $con);//要改成相应的数据库名 $result = mysql_query("SELECT * FROM switch"); while($arr = mysql_fetch_array($result)){//找到需要的数据的记录,并读出状态值 if ($arr['ID'] == 1) { $state = $arr['state']; } } mysql_close($con); echo "{".$state."}";//返回状态值,加“{”是为了帮助Arduino确定数据的位置 }else{ echo "Permission Denied";//请求中没有type或data或token或token错误时,显示Permission Denied } ?>Deal with the HTTP request from the ESP8266 and send back the control variable.
ESP8266 firmware
WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); }Connect to WIFI and allow the ESP8266 to access the Internet
if (client.connected()) { digitalWrite(14, HIGH); client.print(String("POST ") + "/downup.php?token=weixin" + " HTTP/1.1\r\n" + "Host: " + host + "\r\n" + "User-Agent: BuildFailureDetectorESP8266\r\n" + "Connection: close\r\n\r\n"); delay(90); String line = client.readStringUntil('{'); Serial.print(line); delay(80); state = client.read(); delay(100); }Send HTTP request to server and get the control variable from server
Roadmap
Now , There are two ways to control the IOT smart hardware remotely.
In the future ,the control system will become more powerful
- Add sensors and LED states uploading to Web UI and show by chart
- Add a login system to become more practical
- Focusing more on UI design
- Connect to the Home appliance with using relay module
How to contribute?
Github: https://github.com/Cha0s0000/IOT
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin my-new-feature - Submit a pull request.
Posted on Utopian.io - Rewarding Open Source Contributors

Thank you for the contribution. It has been approved. From next time try to use relevant tags as steemstem, cn are irrelevant tags for this contribution.
You can contact us on Discord.
[utopian-moderator]
Thanks for your work ! OH I see ! I just think wechat is a China application so I decided to add a cn tag .i will remove it next time
Hey @codingdefined, I just gave you a tip for your hard work on moderation. Upvote this comment to support the utopian moderators and increase your future rewards!
Hey @cha0s0000 I am @utopian-io. I have just upvoted you!
Achievements
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x