Beruflich Dokumente
Kultur Dokumente
OBJECTIVE :-
The objective of this project is to make SMART I’s, ‘RFID readers’
and ‘biometric scanners’ wireless using TCP and UDP protocol, also
making the setup of system easier.
SETUP:-
This setup is required in case you don’t have a USB-TTL that provides 5V
power.
But in case you have a 3.3V powered USB-TTL then you shouldn’t use
78xxl. A direct connection should be done from 3.3V supply to VCC of
ESP8266 and the other connection connected to it should be kept the
same way.
The SMART I reader need a 5V connection. So a 5V connection should
be provided to the reader and the TX of reader should be connected to
RX of ESP8266 and RX of reader should be connected to TX of ESP8266.
In the above given case the left switch is FLASH switch and the right
switch is RESET switch.
There are two modes in which the ESP8266 works:-
1) The flash mode
2) The normal mode
1) The flash mode: - In this mode you can burn the code.
To get ESP into this mode press the RESET button and to then press the
FLASH button and the release the RESET BUTTON and then release the
hold button.
2) The normal mode: - In this mode ESP runs the code.
To get into this mode just hold and release the RESET button.
So once the system is connected put it in flash mode and burn the
code in it and then put it in normal mode so that it can function
smoothly.
FLOW OF HOW THE SYSTEM WORKS :-
First of all the new wireless RFID readers will be mounted in the
office. Once the power is supplied to it, it will create its own hotspot.
The User connects to the hotspot created by ESP8266.
Once connected :-
1) The login page will open in which we have to enter the default
login id and password set by the company.
2) The second page will ask the User the following points:- (all the
variables are set to ‘smarti’ in the start except for the hotspot
password which should be minimum 8 characters so the
password is smarti12345)
1) New login id and password
2) The new name for hotspot and password
3) The login id and password of WIFI network to which the
controller is connected.
4) The authentication type of that network.
5) The ip address of controller
6) The port via which communication to controller will be
done.
7) Controller id.
8) The type of communication
9) Reader no
10) Channel no
After all this information is provided the reader will connect to the
controller.
And send whatever the data it gets from the reader and send the
reader back whatever data is collected from microcontroller.
SETTING UP THE SOFTWARE:-
First download the Arduino IDE from the official website:-
https://www.arduino.cc/en/Main/Software
Then select the preferences option in the file menu and copy the
following link in Additional Board Managers Url
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Go to tools>boards>boards manager
in it select esp8266 by ESP8266 community and install it.
CODE:-
// login - page 1 login id pass - page 1 password
// nlogin - name of the wifi to be connected npass- password nauth- authenication type
// cip - controller ip cport- controller port cid - controller id ctype- connection type
int c = 0;
int m=0; //m governs the program - for example the udp or tcp connection program has to be used can be decided
by the value of m
int q=3; //q is used to restrict the movement of user from page to page
int udp_port=0;
char incomingPacket[255];
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <EEPROM.h>
#include <String.h>
#include "SoftwareSerial.h"
IPAddress apIP(10, 10, 10, 1); // the user can acess the login and other pages on 10.10.10.1
char isnew[20];
char login[20];
char pass[20];
char wlogin[20];
char wpass[20];
char nlogin[20];
char npass[20];
char nauth[20];
char cip[20];
char cport[20];
char cid[20];
char ctype[20];
char rdno[20];
char chno[20];
}CF;
#define TCP_CONNECT 0x02// when m is set to 2 esp tries to create a tcp conection
#define TCP_WORKING 0x03 // when m is set to 3 esp recieves and sends data using tcp
#define UDP_WORKING 0X05// when m is set to 5 esp recieves and sends data using udp
void DPrint(int dbg,String data,String value) //function created so the serial print can be on or off. serial print is
used for serial communication
DPrint(D_INFO,"LOGIN :",String(CF.login));
DPrint(D_INFO,"PASSWORD :",String(CF.pass));
DPrint(D_INFO,"CONTOROLLER IP :",String(CF.cip));
DPrint(D_INFO,"CONTROLLER ID :",String(CF.cid));
DPrint(D_INFO,"CHANNEL NO :",String(CF.chno));
void EStrWrite(unsigned int loc,unsigned char *data,int s) // used to read and write in eeprom
for(int i=0;i<s;i++)
EEPROM.commit();
void EStrRead(unsigned int loc ,unsigned char *data,int s) // used to read from eeprom
for(int i=0;i<s;i++)
if (!ho.equals("smart1")) //if the esp is running for the first time after its burnt
DPrint(D_INFO,"SMART NO MATCH!!","");
DPrint(D_INFO,"SMART KEY:","smart1");
memcpy(CF.isnew,"smarti",20);
memcpy(CF.login,"smarti",20);
memcpy(CF.pass,"smarti",20);
memcpy(CF.wlogin,"smarti",20);
memcpy(CF.wpass,"smarti12345",20);
memcpy(CF.nlogin,"smarti",20);
memcpy(CF.npass,"smarti",20);
memcpy(CF.cip,"smarti",20);
memcpy(CF.cport,"smarti",20);
memcpy(CF.cid,"smarti",20);
memcpy(CF.rdno,"smarti",20);
memcpy(CF.chno,"smarti",20);
memcpy(CF.ctype,"smarti",20);
q=0;
String set="/login";
String content= "<html><body><p align=\"center\"><font size=\"5\">" +e+ "</font></p><br><br>";
DPrint(D_INFO,"login: ",login1);
DPrint(D_INFO,"password: ",pass2);
q=1;
if(q==2)
login2 = server.arg("login");
pass2 = server.arg("pass");
wlogin2 = server.arg("wlogin1");
wpass2 = server.arg("wpass1");
nlogin2 = server.arg("nlogin1");
npass2 = server.arg("npass1");
nauth2 = server.arg("nauth1");
cip2 = server.arg("cip1");
cport2 = server.arg("cport1");
ctype2 = server.arg("ctype1");
cid2 = server.arg("cid1");
rdno2 = server.arg("rdno1");
chno2 = server.arg("chno1");
login2.toCharArray( CF.login,20);
pass2.toCharArray( CF.pass,20);
wlogin2.toCharArray( CF.wlogin,20);
wpass2.toCharArray(CF.wpass,20);
nlogin2.toCharArray( CF.nlogin,20);
npass2.toCharArray( CF.npass,20);
nauth2.toCharArray( CF.nauth,20);
cip2.toCharArray( CF.cip,20);
cport2.toCharArray( CF.cport,20);
cid2.toCharArray( CF.cid,20);
ctype2.toCharArray( CF.ctype,20);
rdno2.toCharArray( CF.rdno,20);
chno2.toCharArray( CF.chno,20);
PrintAllPara();
m=INITIALISE;
q=3;
WiFi.disconnect();
else
void handleLogin2(){
login2 = String(CF.login);
pass2 = String(CF.pass);
wlogin2 = String(CF.wlogin);
wpass2 = String(CF.wpass);
nlogin2 = String(CF.nlogin);
npass2 = String(CF.npass);
nauth2 = String(CF.nauth);
cip2 = String(CF.cip);
cport2 = String(CF.cport);
ctype2 = String(CF.cid);
rdno2 = String(CF.rdno);
chno2 = String(CF.chno);
c=c+1;
DPrint(D_INFO,"login: ",login2);
DPrint(D_INFO,"pass: ",pass2);
else
void handleLogin(){
DPrint(D_INFO,"LOGIN: ",login);
DPrint(D_INFO,"PASSWORD: ",pass);
{
String content= "<html><body><p align><font size=\"5\"> < ESP Hot spot name> </font></p><br><br><form
method=\"POST\" action=\"/login2\"><p ><font size=\"5\">";
q=2;
else
String set="/";
String content= e;
q=0;
else
void setup(void){
delay(5000);
Serial.begin(38400); // serial port runs at baud rate 38400 because the reader runs at baudrate 38400
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0)); // the user can acess the login and other pages on
value of apIP
DPrint(D_INFO,"Started : ",String(m));
IniDefault();
DPrint(D_INFO,"login1",login1);
DPrint(D_INFO,"pass1",pass1);
server.on("/", handleRoot);
server.on("/login", handleLogin);
server.on("/finish", handleFinish);
server.on("/login2", handleLogin2);
server.begin();
String a="";
String b="";
void loop(void)
int count;
if(!(count++ %100))
{ PrintAllPara();
//ESP8266WebServer server(80);
char c[10];
if(WiFi.status() != WL_CONNECTED)
WiFi.disconnect();
WiFi.begin(CF.nlogin,CF.npass);
DPrint(D_INFO,"",String(CF.nlogin));
int i =100000;
while(i--)
if(i == 100000-10000) //wait till i=10000 so esp 8266 tries to connect to wifi
//if it isnt able to connect still then wait for the user to put in new wifi login and password till i=100000
server.handleClient();
delay(1);
DPrint(D_INFO,"Local IP :",String(WiFi.localIP()));
DPrint(D_INFO,"CONNECTED TO : ",String(CF.wlogin));
break;
else
my_ip=WiFi.localIP().toString();
DPrint(D_INFO,"Local IP :",my_ip);
DPrint(D_INFO,"CONNECTED TO : ",String(CF.wlogin));
m=1;
if (ctype1.equals("TCP"))
m= TCP_CONNECT ;
if (ctype1.equals("UDP"))
m=UDP_CONNECT;
if( m == TCP_CONNECT )
{
server.handleClient();
if (!client.connect(CF.cip, port))
DPrint(D_INFO,"CONTROLLER IP",String(CF.cip));
DPrint(D_INFO,"CONTROLLER PORT",String(port));
return;
server.handleClient();
else
m=TCP_WORKING ;
DPrint(D_INFO,"TCP connected","");
if(m==TCP_WORKING )
while(client.available())
//Serial.print(client.read());
DPrint(D_INFO,line,"");
}
while(Serial.available())
client.print(old);
if(m==UDP_CONNECT )
DPrint(D_INFO,"UDP WORKING","");
Udp.begin(port);
DPrint(D_INFO,"PORT", String(port));
m=UDP_WORKING;
if(m==UDP_WORKING)
// int udp_port=0;
if (packetSize)
DPrint(D_INFO,"FROM PORT",String(Udp.remotePort()));
udp_ip=Udp.remoteIP();
//memcpy(udp_ip,Udp.remoteIP(),20);
udp_port=Udp.remotePort();
//char *udp_ip[20];
//char *udp_port[20];
if (len > 0)
incomingPacket[len] = 0;
Serial.printf(incomingPacket);
}// send back a reply, to the IP address and port we got the packet from
while(Serial.available())
Serial.print("udp printing");
Udp.beginPacket(udp_ip,udp_port);
char singham[40];
Serial.println(udp_ip);
Serial.println(udp_port);
Serial.readString().toCharArray(singham,40);
Udp.write(singham);
Udp.endPacket();
}
}