Things used in this project

Hardware components:
00449 01a
SparkFun SparkFun RS232 Shifter - SMD
need cable connections
×2
SeeedStudio Grove - Base Shield V1.3
×1
SeeedStudio Grove - Relay
you might need some cables also
×1
SparkFun Sparkfun Ethernet Shield 2
×1
A000066 iso both
Arduino Arduino UNO & Genuino UNO
×1
Software apps and online services:
DasData free subscription

Schematics

dasAccessCode
Arduino Code for Access Control System
dasdata_accessControl.ino
DAS Access Control System Diagram
Diagram of DAS Access Control System
DB List Structure
Access DB List Structure
Db bilete
Upside picture
Connections cables
Wp 20150426 004
Side picture
Side picture
Arduino1

Code

dasdata_accessControl.inoC/C++
Code for Access Control
#include <SPI.h>
#include <EthernetV2_0.h>
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3); // RX, TX
SoftwareSerial mySerial2(6, 7); // RX, TX
String inData;
String outData;
int raspServer = 1;
int inReleuPort1 = 5;
int inReleuPort2 = 8;

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network:
byte mac[] = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x01 };
byte gateway[] = {192,168,0,254};
byte subnet[] = {255,255,255,0};
IPAddress ip(192,168,0,33);

// initialize the library instance:
EthernetClient client;

char serverName[] = "192.168.0.123";  // server IP
String serBarCode = "";                  // string to hold the barcode
 
void setup() { 
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
   mySerial.begin(9600);
   mySerial2.begin(9600);
  //mySerial.println("Conectat serial");
  pinMode(inReleuPort1, OUTPUT);
  pinMode(inReleuPort2, OUTPUT);
  
  client.flush();
  client.stop();
    
  // attempt a DHCP connection:
  Serial.println("Connect to the network...");
  Ethernet.begin(mac,ip,subnet,gateway);
  //if (Ethernet.begin(mac,ip,subnet,gateway)) {
   //  if DHCP fails, start with a hard-coded address:
  //  Serial.println("failed to get an IP address using DHCP, trying manually");
  // Ethernet.begin(mac);
  // }
  Serial.print("My address:");
  Serial.println(Ethernet.localIP());
  // connect to Server:
    client.connect(serverName, 27015);
}


void loop() // run over and over
{
 while(client.connected()) {   
 if (Serial.available())
       {
        char recieved = Serial.read();
        inData += recieved;
     if (recieved == '\n')
        {
            raspServer = 0;
           Serial.print(inData);
           //  Serial.println("Data sent to the server!"); 
            client.println(inData); 
          
          
      while (client.connected()||raspServer==0)  {
           char response = client.read();
            outData += response;
            if (response == ' ') break; 
             raspServer = 1; 
         }       
              if(outData.indexOf("0")>0) {
                Serial.println("  Access denied!  DOOR 1:INVALID"); 
                 digitalWrite(inReleuPort1, LOW);
                // delay(1000);
              }
              else {
              Serial.println(" Welcome! DOOR 1:VALID"); 
              digitalWrite(inReleuPort1, HIGH);
               delay(2000);
              }
          
            inData = ""; // Clear recieved buffer
            outData = ""; // Clear recieved buffer
           digitalWrite(inReleuPort1, LOW);
           digitalWrite(inReleuPort2, LOW);
           // delay(2000);
        }
       } 
       
  if (mySerial2.available())
       {
        char recieved = mySerial2.read();
        inData += recieved;
     if (recieved == '\n')
        {
            raspServer = 0;
            Serial.print(inData);
            // Serial.println("Data sent to the server!"); 
            client.println(inData); 
          
          
      while (client.connected()||raspServer==0)  {
           char response = client.read();
            outData += response;
            if (response == ' ') break; 
             raspServer = 1; 
         }       
              if(outData.indexOf("0")>0) {
                 Serial.println(" Access denied!  DOOR 2:INVALID"); 
                 digitalWrite(inReleuPort2, LOW);
                // delay(1000);
              }
              else {
              Serial.println(" Welcome! DOOR 2:VALID"); 
              digitalWrite(inReleuPort2, HIGH);
              delay(2000);
              }
          
            inData = ""; // Clear recieved buffer
            outData = ""; // Clear recieved buffer
           digitalWrite(inReleuPort1, LOW);
            digitalWrite(inReleuPort2, LOW);
           // delay(2000);
        }
       }
 }    
 while(!client.connected()) {
  // Serial.println();
     delay(5000);
    Serial.println("Server connection lost...Retry in 5");
    Ethernet.begin(mac,ip,subnet,gateway);
    client.flush();
    client.stop();
    delay(5000);
    client.connect(serverName, 27015); 
                               }
       
  }


// end of story 

 


 
DasSocketClient.zipC#
Server app archive - c#
No preview (download only).
DbStructure & ProceduresSQL
Database structure and procedures
No preview (download only).
Server CodeC#
Server communication with the Arduino client
Database command and response with the validation
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Text;
/// <summary>
/// SOCKET COMM WITH THE ARDUNIO
/// 
/// ==============================
/// Find out more: support@dasdata.co 
/// </summary>
namespace DasSocketClient
{
    class Program
    {
       // comm with the DB - change connection details 
        static _db _myDb = new _db();
        static System.Timers.Timer aTimer = new System.Timers.Timer();
        static IPAddress localAddr = IPAddress.Any;

        static void Main(string[] args)
        {
            try
            {
                // arduino connection 
                cmdGetConnected("192.168.1.116");
            }
            catch (Exception ex)
            {
            }
        }
       
        
        //Connection arduino
        public static void cmdGetConnected(String _ClientIP)
        {
            TcpListener server = null;
            server = null;
            try
            {
                // Set the TcpListener on port 8800. 
                Int32 port = 8800;
                server = new TcpListener(localAddr, port);
                // Start listening for client requests.
                server.Start();
                // Buffer for reading data 
                byte[] bytes = new byte[1025];
                string data = null;

                // Enter the listening loop. 
                while (true)
                {
                    try
                    {
                        Console.Write("Waiting for a connection... ");
                        TcpClient client = server.AcceptTcpClient();
                        Console.WriteLine("Connected!");
                        data = null;
                        // Get a stream object for reading and writing 
                        NetworkStream stream = client.GetStream();
                        Int32 i = default(Int32);
                        // Loop to receive all the data sent by the client.
                        i = stream.Read(bytes, 0, bytes.Length);
                        while ((i != 0))
                        {
                            // Translate data bytes to a ASCII string.
                            data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                            if (data.Length > 5)
                            {
                                Console.Clear();
                                Console.Write("* " + System.DateTime.Now.ToString() + " - Ticket: " + data + " ");

                                //     cmdGeticketValidation(data);
                                // DATABASE VERIFICATION 
                                string _srvValidation = cmdGeticketValidation(data).ToString();
                                Console.ForegroundColor = ConsoleColor.Green;
                                string _srvValidationMessage = "Valid entry";
                                if (Convert.ToInt32(_srvValidation) == 0)
                                {
                                    _srvValidationMessage = "Acces denied";
                                    Console.ForegroundColor = ConsoleColor.Red;
                                }
                                string strResponse = _srvValidation + " ";
                                byte[] myResponse = Encoding.ASCII.GetBytes(strResponse);
                                stream.Write(myResponse, 0, myResponse.Length);
                                Console.WriteLine(_srvValidationMessage);
                                Console.ForegroundColor = ConsoleColor.White;
                            }
                            i = stream.Read(bytes, 0, bytes.Length);
                        }
                        // Shutdown and end connection 
                        client.Close();
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }
            catch (SocketException ex) { }
            finally
            {      //   server.Stop()
            }
            //   Console.WriteLine(ControlChars.Cr + "Hit enter to continue....")
            //    Console.Read()
        }

        //MAKE VALIDATION ON THE DATABASE SERVER
        public static object cmdGeticketValidation(string _TicketID)
        {
            try
            {
                DataSet _dsTicketsValid = new DataSet();
                _dsTicketsValid = _myDb.getDB("salGetTicketValidation", "UID", _TicketID);
                string _ticketValid = _dsTicketsValid.Tables[0].Rows[0]["Valid"].ToString();
                return _ticketValid;
            }
            catch (Exception ex)
            {
                return "0";
            }
        }

      //end 

    }
}

Credits

Dasdata i4zi6jkmzv
Marius Dima

interested in data exploration and finding innovative solutions to help enterprises.

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Intelligent Community Alerts Beacon [-iCAB-]
Advanced
  • 274
  • 10

A cloud connected alert system that parses local alert feeds ranging from weather to missing persons and provides visual and audio feedback.

Wifi controlled ceiling fan
Advanced
  • 163
  • 5

Full instructions

My young children were not tall enough to pull the chains on the ceiling fan, to turn on the fan & light. Alexa, turn on the 'Boys Light'.

Power Lunch
Advanced
  • 142
  • 6

Full instructions

An insulated food container divided into two sections by a thermoelectric cooler module for quickly heating one side and cooling the other.

Power Lunch

5 members

Smart Compost System
Advanced
  • 210
  • 3

A smart system that can help anyone compost. The system aerates and hydrates your compost, and lets you know when you need to take action.

Smart Compost System

Team Boomer Sooner

Suicide Prevention Gun Safe Locking System
Advanced
  • 1,050
  • 4

Full instructions

An IoT device that helps prevent gun suicides through safe monitoring, only allowing access to a safe through a request/approval process.

Purdue ExoMIND Glove
Advanced
  • 1,495
  • 9

The ExoMIND Glove is a stroke rehabilitation device used to generate biofeedback for physical therapists and patients.

Purdue ExoMIND Glove

Team Purdue MIND

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login