create account

IOT project -- Use ThinkPHP as the IOT system project framework by cha0s0000

View this thread on: hive.blogpeakd.comecency.com
· @cha0s0000 · (edited)
$54.75
IOT project -- Use ThinkPHP as the IOT system project framework
# New Features

## What feature(s) did you add?

- Migrate the whole IOT  system project to ThinkPHP v5 framework

  ![图片.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519283372/yavwwxqh3aoslmu0wvkk.png)

- Update the login function .Consider more secure factors like sql injection

  ### **Before**:

  When i come to login interface in the old version without thinkphp ,I input "admin' AND 1=1 -- " into the username blank and input any other text into password blank even though that is a wrong password. It will show like this:

  ![图片.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519284286/lp0kp5t087olkvs8m9or.png)
  ![图片.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519283756/j4fjizxzvyh12dh0a66n.png)![图片.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519284315/vqy1hbelr8luw3ocn1wh.png)

  ### Now:

  Input the same as above step,then the thinkphp framework will filter the user input then show like this:
![图片.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519288874/dpuckncenn2t4x5nlkxy.png)

  ![图片.png](https://res.cloudinary.com/hpiynhbhq/image/upload/v1519284373/ocikgntl1fwfaxhqpvrz.png)

  But to a certain extent,ThinkPHP may also have some vulnerable bugs  leading to be hacked.


---

# How did you implement it/them?

-  **IOT/webMonitor/thinkphp v5/thinkphp5/application/index/controller/Login.php**

  ```
  <?php
  namespace app\index\controller;
  use think\Controller;
  use think\Cookie;
  class Login extends Controller
  {
      public function index()
      {
      	return $this->fetch();
      }   
      public function login()
      {
      	$post_data = input('post.');
      	$username = $post_data['username'];
      	$password = $post_data['password'];
      	if(empty($username))
      	{
      		$this->error('please input username');
      	}
      	if(empty($password))
      	{
      		$this->error('please input password');
      	}
      	$valid = db('user')->where('username', $username)->find();
      	if(empty($valid)){
      		
      		$this->error('username or password error!');
      	}
      	if($valid['password'] != md5($password)){
      		
      		$this->error('username or password error!');
      	}
      	cookie('username', $valid['username'], 3600);
      	$this->redirect(url('index/index'));
      }
  }
  ```

  When do some mysql operation , use the ThinkPHP internal sql function to realize the login function.

  ```
  db('user')->where('username', $username)->find()
  ```

  ​

-  **IOT/webMonitor/thinkphp v5/thinkphp5/application/index/controller/Sensorsdata.php**

  ```
  <?php
  namespace app\index\controller;
  use think\Controller;
  use think\Cookie;
  class Sensorsdata extends Controller
  {
      public function index()
      {
          if(cookie::has('username'))
          {
              $ID = 0;
              $dataset = db('device')->where('ID', $ID)->find();
              $data_airQuality = $dataset['data_airQuality'];
              $data_distance = $dataset['data_distance'];
              $data_voice = $dataset['data_voice'];
              $data_light = $dataset['data_light'];
              $data_humi = $dataset['data_humi'];
              $data_temp = $dataset['data_temp'];
              $data = array(
                  'temp'=>$data_temp, 
                  'humi'=>$data_humi,
                  'light'=>$data_light, 
                  'voice'=>$data_voice,
                  'airquality'=>$data_airQuality, 
                  'distance'=>$data_distance
              );
              return json_encode($data);
          }
              
              // return $this->fetch();
          else
          {
              $this->error('Please login first');
              $this->redirect(url('login/index'));
          }
             
      }   
  }
  ```

  Get sensors data in real time from the ESP8266 hardware and send them to the web UI.

- **Split frontend and backend**

  The project list is as below:

  - controller
    - Index,php
    - Login.php
    - Sensorsdata.php
  - view
    - index
      - index.html
    - login
      - index.html


---

## Roadmap

- Considering when the IOT system is used into actual, there are many devices instead of one of two .So it is necessary to add a devices manager function  to help use it Conveniently.
- Identify different devices by their ID
- Consider the performance of the communication protocol .May use MQTT protocol in the future version.
- Add other control way like discord controlling .

---

## 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.

<br /><hr/><em>Posted on <a href="https://utopian.io/utopian-io/@cha0s0000/iot-project-use-thinkphp-as-the-iot-system-project-framework">Utopian.io -  Rewarding Open Source Contributors</a></em><hr/>
👍  , , , , , , , , ,
properties (23)
authorcha0s0000
permlinkiot-project-use-thinkphp-as-the-iot-system-project-framework
categoryutopian-io
json_metadata{"community":"utopian","app":"utopian/1.0.0","format":"markdown","repository":{"id":120746740,"name":"IOT","full_name":"Cha0s0000/IOT","html_url":"https://github.com/Cha0s0000/IOT","fork":false,"owner":{"login":"Cha0s0000"}},"pullRequests":[],"platform":"github","type":"development","tags":["utopian-io","steemstem","development","steemdev","iot"],"links":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1519283372/yavwwxqh3aoslmu0wvkk.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519284286/lp0kp5t087olkvs8m9or.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519283756/j4fjizxzvyh12dh0a66n.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519284315/vqy1hbelr8luw3ocn1wh.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519288874/dpuckncenn2t4x5nlkxy.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519284373/ocikgntl1fwfaxhqpvrz.png"],"image":["https://res.cloudinary.com/hpiynhbhq/image/upload/v1519283372/yavwwxqh3aoslmu0wvkk.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519284286/lp0kp5t087olkvs8m9or.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519283756/j4fjizxzvyh12dh0a66n.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519284315/vqy1hbelr8luw3ocn1wh.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519288874/dpuckncenn2t4x5nlkxy.png","https://res.cloudinary.com/hpiynhbhq/image/upload/v1519284373/ocikgntl1fwfaxhqpvrz.png"],"moderator":{"account":"wehmoen","time":"2018-02-25T17:41:33.724Z","reviewed":true,"pending":false,"flagged":false},"questions":[],"score":0}
created2018-02-22 08:41:42
last_update2018-02-25 17:41:33
depth0
children5
last_payout2018-03-01 08:41:42
cashout_time1969-12-31 23:59:59
total_payout_value38.508 HBD
curator_payout_value16.242 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length4,993
author_reputation30,983,518,016,225
root_title"IOT project -- Use ThinkPHP as the IOT system project framework"
beneficiaries
0.
accountutopian.pay
weight2,500
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id39,555,496
net_rshares12,094,776,635,045
author_curate_reward""
vote details (10)
@enjoyy ·
Thanks for sharing although I couldn't understand it much.
properties (22)
authorenjoyy
permlinkre-cha0s0000-iot-project-use-thinkphp-as-the-iot-system-project-framework-20180223t004233918z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-02-23 00:38:00
last_update2018-02-23 00:38:00
depth1
children0
last_payout2018-03-02 00:38:00
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length58
author_reputation342,844,941,159
root_title"IOT project -- Use ThinkPHP as the IOT system project framework"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id39,730,714
net_rshares0
@utopian-io ·
### 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. <a href="https://discord.gg/zTrEMqB">Participate on Discord</a>. Lets GROW TOGETHER!
- <a href="https://v2.steemconnect.com/sign/account-witness-vote?witness=utopian-io&approve=1">Vote for my Witness With SteemConnect</a>
- <a href="https://v2.steemconnect.com/sign/account-witness-proxy?proxy=utopian-io&approve=1">Proxy vote to Utopian Witness with SteemConnect</a>
- Or vote/proxy on <a href="https://steemit.com/~witnesses">Steemit Witnesses</a>

[![mooncryption-utopian-witness-gif](https://steemitimages.com/DQmYPUuQRptAqNBCQRwQjKWAqWU3zJkL3RXVUtEKVury8up/mooncryption-s-utopian-io-witness-gif.gif)](https://steemit.com/~witnesses)

**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**
properties (22)
authorutopian-io
permlinkre-cha0s0000-iot-project-use-thinkphp-as-the-iot-system-project-framework-20180226t173330698z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"community":"utopian","app":"utopian/1.0.0"}
created2018-02-26 17:33:30
last_update2018-02-26 17:33:30
depth1
children0
last_payout2018-03-05 17:33:30
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,085
author_reputation152,955,367,999,756
root_title"IOT project -- Use ThinkPHP as the IOT system project framework"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id40,652,365
net_rshares0
@wehmoen · (edited)
$1.10
 
👍  
properties (23)
authorwehmoen
permlinkre-cha0s0000-iot-project-use-thinkphp-as-the-iot-system-project-framework-20180225t175102162z
categoryutopian-io
json_metadata{}
created2018-02-25 17:51:12
last_update2020-06-03 06:49:45
depth1
children2
last_payout2018-03-04 17:51:12
cashout_time1969-12-31 23:59:59
total_payout_value0.823 HBD
curator_payout_value0.273 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1
author_reputation86,504,380,503,125
root_title"IOT project -- Use ThinkPHP as the IOT system project framework"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id40,388,712
net_rshares197,498,796,672
author_curate_reward""
vote details (1)
@cha0s0000 ·
thanks your work.I will next time
properties (22)
authorcha0s0000
permlinkre-wehmoen-re-cha0s0000-iot-project-use-thinkphp-as-the-iot-system-project-framework-20180226t002844938z
categoryutopian-io
json_metadata{"tags":["utopian-io"],"app":"steemit/0.1"}
created2018-02-26 00:28:45
last_update2018-02-26 00:28:45
depth2
children0
last_payout2018-03-05 00:28:45
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length33
author_reputation30,983,518,016,225
root_title"IOT project -- Use ThinkPHP as the IOT system project framework"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id40,455,555
net_rshares0
@utopian.tip ·
Hey @wehmoen, 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!
properties (22)
authorutopian.tip
permlinkre-re-cha0s0000-iot-project-use-thinkphp-as-the-iot-system-project-framework-20180225t175102162z-20180226t003848
categoryutopian-io
json_metadata""
created2018-02-26 00:38:48
last_update2018-02-26 00:38:48
depth2
children0
last_payout2018-03-05 00:38:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length157
author_reputation238,310,597,885
root_title"IOT project -- Use ThinkPHP as the IOT system project framework"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id40,457,326
net_rshares0