remotely control IOT smart hardware by Wechat Application

in #utopian-io7 years ago (edited)

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.

    图片.png

    GIF.gif


How did you implement it/them?

  1. Briefly introduce
  1. 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

Sort:  

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

  • You have less than 500 followers. Just gave you a gift to help you succeed!
  • Seems like you contribute quite often. AMAZING!

Community-Driven Witness!

I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!

mooncryption-utopian-witness-gif

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

Coin Marketplace

STEEM 0.17
TRX 0.13
JST 0.028
BTC 59596.75
ETH 2659.83
USDT 1.00
SBD 2.45