IOT project --Get sensor data in ESP8266 and upload to server then show those as dynamic chart in Web UI

in #utopian-io6 years ago (edited)

New Features

What feature(s) did you add?

  • Connect several sensors to ESP8266

    图片.png

  • Get sensor data in ESP8266

    GIF.gif

  • Upload data to TCP server and save in the database

    图片.png

  • Show in dynamic charts

    图片.png


How did you implement it/them?

  • Connecting sensors with ESP8266 and getting data by read the IO pin

    #include <dht11.h>  
    dht11 DHT11; 
    void getAirQuality()
    {
       AirQuality = analogRead(AirQualityPin);  
       Serial.print("getAirQuality running.Get data :");
       Serial.println(AirQuality);
      }
    void getDistance()
    {
       Distance = analogRead(DistancePin);  
       Serial.print("getDistance running.Get data :");
       Serial.println(Distance);
      }
    void  getVoice()
    {
       Voice = analogRead(VoicePin);  
       Serial.print("getVoice running.Get data :");
       Serial.println(Voice);
      }
    void  getLight()
    {
       Light = analogRead(LightPin);  
       Serial.print("getLight running.Get data :");
       Serial.println(Light);
      }
    
    void getHumi()
    {
      DHT11.read(TempHumiPin);  
      humi = (float)DHT11.humidity;
      Serial.print("getHumi running.Get data :");
      Serial.println(humi);
      }
      
    void getTemp()
    {
      DHT11.read(TempHumiPin);  
      temp = (float)DHT11.temperature;
      Serial.print("getTemp running.Get data :");
      Serial.println(temp);
      }
    

    By import dht11 temperature and humidity library then use the function of "DHT11.read" to get temperature and humidity

    Other sensors data can be read by the function "analogRead"

  • Upload sensor data to TCP server in a specific protocol

    client.print(String("AA") + ID + String("BB") + AirQuality +
                     String("CC") + Distance + String("DD") + Voice +
                     String("EE") + Light + String("FF") + humi +
                     String("GG") + temp +  String("HH"));
    

    Use several special character to identify the sensor data

  • Get each of the data and save in database

     $ID_bf = "AA";
     $airQuality_bf = "BB";
     $distance_bf = "CC";
     $voice_bf = "DD";
     $light_bf = "EE";
     $humi_bf = "FF";
     $temp_bf = "GG";
     $end = "HH";
    
    
    $ID_loc = strpos($message, $ID_bf);
    $airQuality_loc = strpos($message, $pm_bf);
    $distance_loc = strpos($message, $co_bf);
    $voice_loc = strpos($message, $pwm_bf);
    $light_loc = strpos($message, $temp_bf);
    $humi_loc = strpos($message, $switch_bf);
    $temp_loc = strpos($message, $checkdata_bf);
    $end_loc = strpos($message, $end);
    
    
    $data_ID = substr($message,$ID_loc+2,$airQuality_loc-$ID_loc-2);
    $data_ID = trim($data_ID);
    $data_airQuality = substr($message,$airQuality_loc+2,$distance_loc-$airQuality_loc-2);
    $data_distance = substr($message,$distance_loc+2,$voice_loc-$distance_loc-2);
    $data_voice = substr($message,$voice_loc+2,$light_loc-$voice_loc-2);
    $data_light = substr($message,$light_loc+2,$humi_loc-$light_loc-2);
    $data_humi = substr($message,$humi_loc+2,$temp_loc-$humi_loc-2);
    $data_temp = substr($message,$temp_loc+2,$end_loc-$temp_loc-2);
    
     $insert_sql = "INSERT INTO device (ID,data_airQuality,data_distance,data_voice,data_light,data_humi,data_temp,client_id,timestamp,online_or_not) values ('$data_ID','$data_airQuality','$data_distance','$data_voice','$data_light','$data_humi','$data_temp','$client_id','$dati','1')";
     $insert_reslut = mysql_query($insert_sql);
    
  • Replace the random function in file sensorsData.php with data from the database

    include_once("conn.php"); 
        $sql = "SELECT * from device where ID = '$ID' ";
        $result = mysql_query($sql);
        $row = mysql_fetch_array($result);
        $data_airQuality = $row['data_airQuality'];
        $data_distance = $row['data_distance'];
        $data_voice = $row['data_voice'];
        $data_light = $row['data_light'];
        $data_humi = $row['data_humi'];
        $data_temp = $row['data_temp'];
    


Roadmap

  • The function existing
    • Now , There are two ways to control the IOT smart hardware remotely.
    • Now,we can monitor several sensor data in the dynamic chart and Web UI.
    • Now ,we can actually show the sensors data in the dynamic chart in web UI.
  • In the future ,the IOT system will become more powerful
    • Add a login system to become more practical
    • Focusing more on UI design
    • Connect to the Home appliance with using relay module
    • Add more control and monitor way like discord controlling and so on.

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:  

i like coming up with embedded systems , they look so practical and problem solving

Yeah! I like it and always do some IOT project with embedded system

Thank you for the contribution. It has been approved.

You can contact us on Discord.
[utopian-moderator]

Thanks for your work !

Really nice project. I did something like this before, but your code is much cleaner ^^

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

Great one you have there. Great sensor. Currently working on similar stuffs too. You can follow my blog for details

Coin Marketplace

STEEM 0.27
TRX 0.11
JST 0.031
BTC 67138.06
ETH 3678.23
USDT 1.00
SBD 3.73