SekolahRobot
Published

Smart Laboratory Asset Management System

Streamlines equipment tracking, maintenance, and inventory. IoT integration enhances efficiency and productivity

IntermediateFull instructions provided6 hours1,126

Things used in this project

Hardware components

Hackster EEDU Kit - Getting started with IoT
DFRobot Hackster EEDU Kit - Getting started with IoT
×1
HUSKYLENS AI Camera
DFRobot HUSKYLENS AI Camera
×1

Software apps and online services

Arduino IoT Cloud
Arduino IoT Cloud

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)
Premium Female/Male Extension Jumper Wires, 40 x 6" (150mm)

Story

Read more

Custom parts and enclosures

enclosure

manualy not use 3D CAD

Schematics

smart_laboratory_asset_management_system_(2)_ZTVu0vU3dq.png

Code

Smart Laboratory IOT

Arduino
Huskylens, DFPlayer, Webserver
#include <DFRobot_DF1201S.h>

DFRobot_DF1201S DF1201S;


#include <WiFi.h>
#include <HTTPClient.h>
#include <Arduino_JSON.h>

//==== HUSKY ====
#include "HUSKYLENS.h"
HUSKYLENS huskylens;
int toolid[]={0,0,0,0,0,0};
int datatool1,datatool2,datatool3,datatool4;

// Defines the Digital Pin of the "On Board LED".
#define ON_Board_LED D9 

//======================================== SSID and Password of your WiFi router.
const char* ssid = "Sekolah Robot Indonesia";
const char* password = "sadapsadap";
//======================================== 

//======================================== Variables for HTTP POST request data.
String postData = ""; //--> Variables sent for HTTP POST request data.
String payload = "";  //--> Variable for receiving response from HTTP POST.
//======================================== 

//________________________________________________________________________________ Subroutine to control LEDs after successfully fetching data from database.
void get_fromdatabase() {
  Serial.println();
  Serial.println("---------------get database()");
  JSONVar myObject = JSON.parse(payload);

  // JSON.typeof(jsonVar) can be used to get the type of the var
  if (JSON.typeof(myObject) == "undefined") {
    Serial.println("Parsing input failed!");
    Serial.println("---------------");
    return;
  }

   // JSON.typeof(jsonVar) can be used to get the type of the var
  if (JSON.typeof(myObject) == "undefined") {
    Serial.println("Parsing input failed!");
    return;
  }

  if (myObject.hasOwnProperty("tool1")) {
    Serial.print("myObject[\"tool1\"] = ");
    Serial.println(myObject["tool1"]);
  }

  if (myObject.hasOwnProperty("tool2")) {
    Serial.print("myObject[\"tool2\"] = ");
    Serial.println(myObject["tool2"]);
  }

  if (myObject.hasOwnProperty("tool3")) {
    Serial.print("myObject[\"tool3\"] = ");
    Serial.println(myObject["tool3"]);
  }

  if (myObject.hasOwnProperty("tool4")) {
    Serial.print("myObject[\"tool4\"] = ");
    Serial.println(myObject["tool4"]);
  }
  
  datatool1 = myObject["tool1"];
  datatool2 = myObject["tool2"];
  datatool3 = myObject["tool3"];
  datatool4 = myObject["tool4"];
  
  if(datatool1 == 0 || datatool2 == 0 || datatool3 == 0 || datatool4 == 0)
  {
    Serial.println("not completed");
    DF1201S.playFileNum(1);
  }
  else
  {
    Serial.println("completed");
    DF1201S.playFileNum(2);
  }

  Serial.println("---------------");
}

void huskyData()
{
  if (huskylens.requestLearned())
  {
    if(huskylens.count(1)>0) toolid[1] = 1; else toolid[1] = 0;
    if(huskylens.count(2)>0) toolid[2] = 1; else toolid[2] = 0;
    if(huskylens.count(3)>0) toolid[3] = 1; else toolid[3] = 0;
    if(huskylens.count(4)>0) toolid[4] = 1; else toolid[4] = 0;
    if(huskylens.count(5)>0) toolid[5] = 1; else toolid[5] = 0;
  }
}


void setup() {
  // put your setup code here, to run once:
  
  Serial.begin(115200); //--> Initialize serial communications with the PC.
  Serial2.begin(115200);
  while (!DF1201S.begin(Serial2)) {
    Serial.println("Init failed, please check the wire connection!");
    delay(1000);
  }

  DF1201S.setVol(/*VOL = */20);
  DF1201S.switchFunction(DF1201S.MUSIC);
  delay(2000);
  DF1201S.setPlayMode(DF1201S.SINGLE);
  
  pinMode(ON_Board_LED,OUTPUT);
  
  Wire.begin();
  while (!huskylens.begin(Wire))
    {
        Serial.println(F("Begin failed!"));
        Serial.println(F("1.Please recheck the \"Protocol Type\" in HUSKYLENS (General Settings>>Protocol Type>>I2C)"));
        Serial.println(F("2.Please recheck the connection."));
        delay(100);
    }

  //---------------------------------------- Make WiFi on ESP32 in "STA/Station" mode and start connecting to WiFi Router/Hotspot.
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  //---------------------------------------- 
  
  Serial.println();
  Serial.println("-------------");
  Serial.print("Connecting");

  int connecting_process_timed_out = 20; //--> 20 = 20 seconds.
  connecting_process_timed_out = connecting_process_timed_out * 2;

  while (WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    //........................................ Make the On Board Flashing LED on the process of connecting to the wifi router.
    digitalWrite(ON_Board_LED, HIGH);
    delay(250);
    digitalWrite(ON_Board_LED, LOW);
    delay(250);
    //........................................ 

    //........................................ Countdown "connecting_process_timed_out".
    if(connecting_process_timed_out > 0) connecting_process_timed_out--;
    if(connecting_process_timed_out == 0) {
      delay(1000);
      ESP.restart();
    }
    //........................................ 
  }
  //---------------------------------------- 
  
  digitalWrite(ON_Board_LED, LOW); //--> Turn off the On Board LED when it is connected to the wifi router.
  
  //---------------------------------------- If successfully connected to the wifi router, the IP Address that will be visited is displayed in the serial monitor
  Serial.println();
  Serial.print("Successfully connected to : ");
  Serial.println(ssid);
  //Serial.print("IP address: ");
  //Serial.println(WiFi.localIP());
  Serial.println("-------------");
  //---------------------------------------- 

  delay(2000);
}
//________________________________________________________________________________ 

//________________________________________________________________________________ VOID LOOP()
void loop() {
  // put your main code here, to run repeatedly

  //---------------------------------------- Check WiFi connection status.
  if(WiFi.status()== WL_CONNECTED) {
    HTTPClient http;  //--> Declare object of class HTTPClient.
    int httpCode;     //--> Variables for HTTP return code.
    
    //........................................ Process to get LEDs data from database to control LEDs.
    postData = "id=pegboard1";
    payload = "";
  
    digitalWrite(ON_Board_LED, HIGH);
    Serial.println();
    Serial.println("---------------getdata.php");
    http.begin("http://192.168.0.101/dataiot/firebeetle/getdata.php");  //--> Specify request destination
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");        //--> Specify content-type header
   
    httpCode = http.POST(postData); //--> Send the request
    payload = http.getString();     //--> Get the response payload
  
    Serial.print("httpCode : ");
    Serial.println(httpCode); //--> Print HTTP return code
    Serial.print("payload  : ");
    Serial.println(payload);  //--> Print request response payload
    
    http.end();  //--> Close connection
    Serial.println("---------------");
    digitalWrite(ON_Board_LED, LOW);
    //........................................ 
    get_fromdatabase();
    
    
    delay(1000);

    huskyData();
    postData = "id=pegboard1";
    postData += "&tool1=" + String(toolid[1]);
    postData += "&tool2=" + String(toolid[2]);
    postData += "&tool3=" + String(toolid[3]);
    postData += "&tool4=" + String(toolid[4]);
    payload = "";

   
    Serial.println();
    Serial.println(postData);
    http.begin("http://192.168.0.101/dataiot/firebeetle/updatedata.php");  //--> Specify request destination
    http.addHeader("Content-Type", "application/x-www-form-urlencoded");  //--> Specify content-type header
   
    httpCode = http.POST(postData); //--> Send the request
    payload = http.getString();  //--> Get the response payload
  
    Serial.print("httpCode : ");
    Serial.println(httpCode); //--> Print HTTP return code
    Serial.print("payload  : ");
    Serial.println(payload);  //--> Print request response payload


    http.end();  //Close connection
    Serial.println("---------------");
    digitalWrite(ON_Board_LED, LOW);
    //........................................ 
    
    delay(4000);
    
    
  }
  //---------------------------------------- 
}

Smart Lab Github

Credits

SekolahRobot

SekolahRobot

6 projects • 17 followers
Sekolah Robot Indonesia is non formal education in Indonesia to learning about robot, and base on Community

Comments