Muhammad Fauzan
Published © CC BY

Mesin Antrian Menggunakan Raspberry Pi + NodeJS

Mesin antrian berbasis web server menggunakan NodeJS dan dimasukan dalam Raspberry Pi. Akses api menggunakan NodeMCU dan ditampilkan pada PC

EasyFull instructions provided1 hour675
Mesin Antrian Menggunakan Raspberry Pi + NodeJS

Things used in this project

Hardware components

Raspberry Pi 3 Model B
Raspberry Pi 3 Model B
×1
NodeMCU ESP8266 Breakout Board
NodeMCU ESP8266 Breakout Board
×3
Resistor 10k ohm
Resistor 10k ohm
×6
Button
×1
USB-A to Micro-USB Cable
USB-A to Micro-USB Cable
×4

Software apps and online services

Arduino IDE
Arduino IDE
Putty
WinSCP
NodeJS
Sublime Text

Story

Read more

Schematics

Tombol Antrian dengan NodeMCU

Drawing gqow3lwpmm

Code

Tombol Next dan Recall

C/C++
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>
ESP8266WiFiMulti WiFiMulti;
#define pinNext 5     //d1
#define pinRecall 16  //d0

void setup()
{
    Serial.begin(9600);
    pinMode(pinNext, INPUT);
    digitalWrite(pinNext, LOW);
    pinMode(pinRecall, INPUT);
    digitalWrite(pinRecall, LOW);
  
    // set Wifi SSID dan passwordnya
    WiFiMulti.addAP("SSID", "PASSWORD");
    //Memulai koneksi internet
      while((WiFiMulti.run() != WL_CONNECTED))
      {
      Serial.print("."); 
      delay(500);
      if(WiFi.status() == WL_CONNECTED)
      {
      Serial.print("Connect to Wifi");
      delay(1500);
     }
    }   
}

void loop()
{ 
  if(digitalRead(pinNext) == HIGH)
  {
    Serial.println("request next");
    if((WiFiMulti.run() == WL_CONNECTED))
    {
        HTTPClient http;

        String url_api  = "http://192.168.10.10/api/next/< Loket ke- >";        
        char url_api_char[100];
        url_api.toCharArray(url_api_char, 100);
        http.begin(url_api_char);
        int httpCode = http.GET();
        if(httpCode > 0)
        {
            Serial.printf("[HTTP] GET... code: %d\n", httpCode);

            if(httpCode == HTTP_CODE_OK)
            {
                String json = http.getString();
                Serial.println(json);
            }
        } else {
            Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }
        http.end();
    }
    delay(1000); 
  }
  if(digitalRead(pinRecall) == HIGH)
  {
    Serial.println("request recall");
    if((WiFiMulti.run() == WL_CONNECTED))
    {
        HTTPClient http;

        String url_api  = "http://192.168.10.10/api/recall/< Loket ke- >";        
        char url_api_char[100];
        url_api.toCharArray(url_api_char, 100);
        http.begin(url_api_char);
        int httpCode = http.GET();
        if(httpCode > 0)
        {
            Serial.printf("[HTTP] GET... code: %d\n", httpCode);

            if(httpCode == HTTP_CODE_OK)
            {
                String json = http.getString();
                Serial.println(json);
            }
        } else {
            Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
        }
        http.end();
    }
    delay(1000); 
  }
}

Mesin Antrian

Credits

Muhammad Fauzan

Muhammad Fauzan

1 project • 1 follower
noob

Comments

Add projectSign up / Login