0% found this document useful (0 votes)
94 views34 pages

Appendix A Source Code A. Arduino Code

The document contains source code for an Arduino and Visual Basic program that allows users to log in, browse reports, and send emergency alerts from different sensors to a webpage. The Arduino code sets up WiFi connectivity and defines sensor readings that trigger alerts to be displayed on a webpage when a client connects. The Visual Basic code defines login validation, navigation buttons to access the webpage, and methods to send alert reports to a database when the sensor buttons are clicked.

Uploaded by

kathleen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views34 pages

Appendix A Source Code A. Arduino Code

The document contains source code for an Arduino and Visual Basic program that allows users to log in, browse reports, and send emergency alerts from different sensors to a webpage. The Arduino code sets up WiFi connectivity and defines sensor readings that trigger alerts to be displayed on a webpage when a client connects. The Visual Basic code defines login validation, navigation buttons to access the webpage, and methods to send alert reports to a database when the sensor buttons are clicked.

Uploaded by

kathleen
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 34

APPENDIX A

SOURCE CODE

A. ARDUINO CODE

#include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present

#ifndef HAVE_HWSERIAL1

#include "SoftwareSerial.h"

SoftwareSerial Serial1(6, 7); // RX, TX

#endif

char ssid[] = "HUAWEI-E5330-DD08"; // your network SSID (name)

char pass[] = "b57rae9n"; // your network password

int status = WL_IDLE_STATUS; // the Wifi radio's status

//int reqCount = 0; // number of requests received

WiFiEspServer server(80);

46
RingBuffer buf(8);

void setup()

// initialize serial for debugging

Serial.begin(115200);

// initialize serial for ESP module

Serial1.begin(9600);

// initialize ESP module

WiFi.init(&Serial1);

//Set Pin mode for the arduino Nano digital pins

pinMode(2,OUTPUT);//for Buzzer

pinMode(3,OUTPUT);//for Connection led

pinMode(4,OUTPUT);//for Reporting led

// check for the presence of the shield

47
//Condition: if WiFi Shield is Present

if (WiFi.status() == WL_NO_SHIELD) {

digitalWrite(3, LOW);

// don't continue

while (true);

// attempt to connect to WiFi network

while ( status != WL_CONNECTED) {

Serial.print("Attempting to connect to WPA SSID: ");

Serial.println(ssid);

// Connect to WPA/WPA2 network

status = WiFi.begin(ssid, pass);

Serial.println("You're connected to the network");

48
digitalWrite(3, HIGH);

printWifiStatus();

// start the web server on port 80

server.begin();

// Call for Program Loop

void loop()

// listen for incoming clients

WiFiEspClient client = server.available();

//Condition: if client is available

if (client) {

Serial.println("New client");

// an http request ends with a blank line

49
boolean currentLineIsBlank = true;

while (client.connected()) {

if (client.available()) {

char c = client.read();

buf.push(c);

if (buf.endsWith("GET /H")) {

Serial.println("Confirmed Call");

digitalWrite(2, HIGH);

delay(3000);

client.print("Refresh: 10\r\n"); // refresh the page automatically every 10 sec

// "\r\n"

// if you've gotten to the end of the line (received a newline

// character) and the line is blank, the http request has ended,

// so you can send a reply

if (c == '\n' && currentLineIsBlank) {

50
Serial.println("Sending response");

// send a standard http response header

// use \r\n instead of many println statements to speedup data send

client.print(

"HTTP/1.1 200 OK\r\n"

"Connection: close\r\n" // the connection will be closed after completion of the

response

"Refresh: 10\r\n" // refresh the page automatically every 10 sec

"\r\n");

client.print("<!DOCTYPE HTML>\r\n");

client.print("<html>\r\n");

client.print("<h1></h1></p>\r\n");

client.println("<br>");

int sensorValue = analogRead(A0);

int sensorValue2 = analogRead(A1);

51
int sensorValue3 = analogRead(A2);

int sensorValue4 = analogRead(A3);

if (sensorValue >= 1000){

Serial.print("NEED POLICE ASSISTANCE");

client.print("<br>\r\n");

client.print("JRMSU main Campus ");

client.print("NEED POLICE ASSISTANCE");

client.println("<p id='date'></p>");

client.println("<script>");

client.println("document.getElementById('date').innerHTML = Date();");

client.println("</script>");

digitalWrite(4, HIGH);

delay(5000);

digitalWrite(4, LOW);

client.print("<br>\r\n");

client.print("</html>\r\n");

52
}

if (sensorValue2 >= 1000){

client.print("<br>\r\n");

client.print("JRMSU main Campus ");

client.print("NEED FIRE ASSISTANCE");

client.println("<p id='date'></p>");

client.println("<script>");

client.println("document.getElementById('date').innerHTML = Date();");

client.println("</script>");

digitalWrite(4, HIGH);

delay(5000);

digitalWrite(4, LOW);

client.print("<br>\r\n");

client.print("</html>\r\n");

if (sensorValue3 >= 1000){

client.print("<br>\r\n");

53
client.print("JRMSU main Campus ");

client.print("NEED CDRRMO ASSISTANCE");//

client.println("<p id='date'></p>");

client.println("<script>");

client.println("document.getElementById('date').innerHTML = Date();");

client.println("</script>");

digitalWrite(4, HIGH);

delay(5000);

digitalWrite(4, LOW);

client.print("<br>\r\n");

client.print("</html>\r\n");

if (sensorValue4 >= 1000){

client.print("<br>\r\n");

client.print("JRMSU main Campus ");

client.print("NEED AMBULANCE");

client.println("<p id='date'></p>");

54
client.println("<script>");

client.println("document.getElementById('date').innerHTML = Date();");

client.println("</script>");

digitalWrite(4, HIGH);

delay(5000);

digitalWrite(4, LOW);

client.print("<br>\r\n");

client.print("</html>\r\n");

break;

else if (c != '\r') {

// you've gotten a character on the current line

currentLineIsBlank = false;

// give the web browser time to receive the data

55
delay(10);

// close the connection:

client.stop();

Serial.println("Client disconnected");

void printWifiStatus()

// print the SSID of the network you're attached to

Serial.print("SSID: ");

Serial.println(WiFi.SSID());

// print your WiFi shield's IP address

IPAddress ip = WiFi.localIP();

Serial.print("IP Address: ");

56
Serial.println(ip);

// print where to go in the browser

Serial.println();

Serial.print("To see this page in action, open a browser to http://");

Serial.println(ip);

Serial.println();

B. VISUAL BASIC CODE

Codes for Login

Private Sub Command5_Click()

Adodc1.RecordSource = "select * from Login where username = '" + Text2.Text + "'"

Adodc1.Refresh

57
If (Adodc1.Recordset.EOF = False) Then

If (Text3.Text = Adodc1.Recordset.Fields("password") And Text8.Text =

Adodc1.Recordset.Fields("level")) Then

MsgBox "login successful"

web.Show

web.Label13.Caption = Text2.Text

Else

web.File.Enabled = False

web.PrintReport.Enabled = False

End If

Me.Hide

Text2.Text = ""

Text3.Text = ""

Text8.Text = ""

Else

MsgBox "invalid password or access level"

58
Text2.Text = ""

Text3.Text = ""

Text8.Text = ""

Text2.SetFocus

End If

Else

MsgBox "invalid username"

Text2.Text = ""

Text3.Text = ""

Text8.Text = ""

Text2.SetFocus

End If

End Sub

Private Sub Command6_Click()

msg1 = MsgBox("are you sure you want to LOGOUT?", vbYesNo, "LOGOUT")

If msg1 = vbYes Then

59
End

End If

If msg1 = vbNo Then

web.Show

End If

End Sub

Codes for JRMSU ERS BROWSER

Private Sub About_Click()

Unload Me

60
frmAbout.Show

End Sub

Private Sub Account_Click()

Unload Me

frmUserAcct.Show

End Sub

Private Sub Command1_Click()

WebBrowser1.Navigate ("http://192.168.8.101")

End Sub

Private Sub Command10_Click()

WebBrowser5.Navigate (Text5.Text + "H")

Adodc2.Recordset.AddNew

61
Adodc2.Recordset.Fields("username") = Label13.Caption

Adodc2.Recordset.Fields("date") = Label5.Caption

Adodc2.Recordset.Fields("time") = Label16.Caption

Adodc2.Recordset.Fields("department") = Label14.Caption

Adodc2.Recordset.Fields("report") = "Combo5.text"

End Sub

Private Sub Command11_Click()

WebBrowser5.Navigate ("http://192.168.8.105")

End Sub

Private Sub Command2_Click()

WebBrowser1.Navigate (Text1.Text + "H")

Adodc2.Recordset.AddNew

Adodc2.Recordset.Fields("username") = Label13.Caption

Adodc2.Recordset.Fields("date") = Label5.Caption

Adodc2.Recordset.Fields("time") = Label16.Caption

62
Adodc2.Recordset.Fields("department") = Label14.Caption

Adodc2.Recordset.Fields("report") = "Combo1.text"

End Sub

Private Sub Command3_Click()

WebBrowser2.Navigate (Text2.Text + "H")

Adodc2.Recordset.AddNew

Adodc2.Recordset.Fields("username") = Label13.Caption

Adodc2.Recordset.Fields("date") = Label5.Caption

Adodc2.Recordset.Fields("time") = Label16.Caption

Adodc2.Recordset.Fields("department") = Label14.Caption

Adodc2.Recordset.Fields("report") = "Combo2.text"

End Sub

Private Sub Command4_Click()

WebBrowser2.Navigate ("http://192.168.8.102")

End Sub

63
Private Sub Command5_Click()

Unload Me

frmLogin.Show

End Sub

Private Sub Command6_Click()

WebBrowser3.Navigate (Text3.Text + "H")

Adodc2.Recordset.AddNew

Adodc2.Recordset.Fields("username") = Label13.Caption

Adodc2.Recordset.Fields("date") = Label5.Caption

Adodc2.Recordset.Fields("time") = Label16.Caption

Adodc2.Recordset.Fields("department") = Label14.Caption

Adodc2.Recordset.Fields("report") = "Combo3.text"

End Sub

Private Sub Command7_Click()

64
WebBrowser3.Navigate ("http://192.168.8.103")

End Sub

Private Sub Command8_Click()

WebBrowser4.Navigate (Text4.Text + "H")

Adodc2.Recordset.AddNew

Adodc2.Recordset.Fields("username") = Label13.Caption

Adodc2.Recordset.Fields("date") = Label5.Caption

Adodc2.Recordset.Fields("time") = Label16.Caption

Adodc2.Recordset.Fields("department") = Label14.Caption

Adodc2.Recordset.Fields("report") = "Combo4.text"

End Sub

Private Sub mnublue_Click()

web.BackColor = RGB(0, 0, 255)

End Sub

65
Private Sub mnubrown_Click()

web.BackColor = RGB(165, 42, 42)

End Sub

Private Sub mnucyan_Click()

web.BackColor = RGB(0, 255, 255)

End Sub

Private Sub mnugold_Click()

web.BackColor = RGB(255, 215, 0)

End Sub

Private Sub mnugreen_Click()

66
web.BackColor = RGB(0, 255, 0)

End Sub

Private Sub mnuorange_Click()

web.BackColor = RGB(255, 165, 0)

End Sub

Private Sub mnured_Click()

web.BackColor = RGB(255, 0, 0)

End Sub

Private Sub mnuskyblue_Click()

web.BackColor = RGB(135, 206, 235)

67
End Sub

Private Sub mnuyellow_Click()

web.BackColor = RGB(255, 255, 0)

End Sub

Private Sub size1_Click()

web.Width = 5000

web.Height = 5000

WebBrowser1.Width = 5000

WebBrowser1.Height = 5000

End Sub

Private Sub size2_Click()

web.Width = 7000

68
web.Height = 7000

WebBrowser1.Width = 7000

WebBrowser1.Height = 7000

End Sub

Private Sub size3_Click()

web.Width = 9000

web.Height = 9000

WebBrowser1.Width = 9000

WebBrowser1.Height = 9000

End Sub

Private Sub size4_Click()

web.Width = 12000

web.Height = 12000

WebBrowser1.Width = 12000

69
WebBrowser1.Height = 12000

End Sub

Private Sub size5_Click()

web.Width = 15000

web.Height = 15000

WebBrowser1.Width = 15000

WebBrowser1.Height = 15000

End Sub

Private Sub DataGrid1_Click()

End Sub

Private Sub DataGrid1_DblClick()

70
End Sub

Private Sub Command9_Click()

WebBrowser4.Navigate ("http://192.168.8.104")

End Sub

Private Sub Form_Load()

End Sub

Private Sub PrintReport_Click()

Me.Hide

frmReports.Show

Set DataReport1.DataSource = frmReports.Adodc2

DataReport1.Sections("Section1").Controls("text1").DataField = "username"

DataReport1.Sections("Section1").Controls("text2").DataField = "department"

71
DataReport1.Sections("Section1").Controls("text3").DataField = "date"

DataReport1.Sections("Section1").Controls("Text4").DataField = "time"

DataReport1.Sections("Section1").Controls("Text5").DataField = "report"

DataReport1.Show

End Sub

Private Sub Text7_Change()

End Sub

Private Sub Timer1_Timer()

Today = Now

Label5.Caption = Format(Today, "mmmm dd, yyyy")

Label6.Caption = Format(Today, "dddd")

Label16.Caption = Format(Time, "H:M:S")

End Sub

72
Private Sub WebBrowser1_StatusTextChange(ByVal Text As String)

Text1.Text = (WebBrowser1.LocationURL)

Text2.Text = (WebBrowser2.LocationURL)

Text3.Text = (WebBrowser2.LocationURL)

Text4.Text = (WebBrowser2.LocationURL)

'web.Caption = (WebBrowser1.LocationName)

End Sub

Codes for User Registration

Private Sub Command11_Click()

On Error Resume Next

73
msg1 = MsgBox("are you sure you want to delete this?", vbOKCancel, "delete")

If msg1 = vbOK Then

Adodc1.Recordset.Delete

End If

If msg1 = vbCancel Then

Adodc1.Refresh

End If

End Sub

Private Sub Command3_Click()

Adodc1.Recordset.AddNew

Adodc1.Recordset.Fields("username") = Text4.Text

Adodc1.Recordset.Fields("password") = Text5.Text

Adodc1.Recordset.Fields("department") = Text6.Text

Adodc1.Recordset.Fields("level") = Text9.Text

Text4.Text = "Username"

Text5.Text = "Password"

74
Text6.Text = "Department"

Text9.Text = "Level"

Text5.PasswordChar = ""

Text4.SetFocus

End Sub

Private Sub Command4_Click()

msg1 = MsgBox("are you sure you want to EXIT?", vbOKCancel, "EXIT")

If msg1 = vbOK Then

Text4.Text = ""

Text5.Text = ""

Text6.Text = ""

Text9.Text = ""

Text7.Text = ""

End If

Unload Me

web.Show

75
If msg1 = vbCancel Then

End If

End Sub

Private Sub Command7_Click()

sr2 = "username like '" & Text7 & "'"

Adodc1.RecordSource = "Select * From Login Where " & sr2

Adodc1.Refresh

End Sub

Private Sub Command9_Click()

If Text4.Text = "" Or Text5.Text = "" Or Text6.Text = "" Or Text9.Text = "" Then

MsgBox "One of the boxes is empty!"

Else

Adodc1.Recordset.Fields("username") = Text4.Text

Adodc1.Recordset.Fields("password") = Text5.Text

76
Adodc1.Recordset.Fields("department") = Text6.Text

Adodc1.Recordset.Fields("level") = Text9.Text

Adodc1.Recordset.Update

Text4.Text = ""

Text5.Text = ""

Text6.Text = ""

Text9.Text = ""

Text4.SetFocus

End If

End Sub

Private Sub DataGrid1_DblClick()

Text4.Text = Adodc1.Recordset.Fields("username")

Text5.Text = Adodc1.Recordset.Fields("password")

Text6.Text = Adodc1.Recordset.Fields("department")

Text9.Text = Adodc1.Recordset.Fields("level")

Command9.Enabled = True

77
Command11.Enabled = True

Command3.Enabled = False

End Sub

Private Sub Frame1_DragDrop(Source As Control, X As Single, Y As Single)

End Sub

Private Sub Text4_Change()

End Sub

Codes for ERS Reports

78
Private Sub Command1_Click()

Unload Me

web.Show

End Sub

Private Sub Form_Load()

End Sub

79

You might also like