Hi all!
I'm currently developing a software that allow the user to open an electronic lock remotely but first the clients "ring the bell" which is a push button on the door.
So the client pushes the door button, connected to the Arduino UNO with Ethernet shield, and sends a message to the receptionist through Visual Basic. The receptionist opens an IP camera and see who is it and then press a button on the visual basic software to open the door.
I already can open the door with the visual basic but I can't read on the visual basic when someone presses the button.
Any tip?
I leave the arduino current code and visual basic code as well as an attachment:
Arduino:
//*************************************************************************************************************************************
// Declarations
//*************************************************************************************************************************************
#include <SPI.h>
#include <Ethernet.h>
//*************************************************************************************************************************************
// Wired configuration parameters
//*************************************************************************************************************************************
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x97, 0x75 };
unsigned char local_ip[] = {192,168,1,90}; // IP address of WiShield
unsigned char gateway_ip[] = {192,168,1,1}; // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0}; // subnet mask for the local networ
EthernetServer server(80);
//*************************************************************************************************************************************
// Variables and constants
//*************************************************************************************************************************************
// the number of the pushbutton pin:
const int buttonPin2 = 4;
// the number of the eletronic door pin
const int doorPin = 8;
// variable for reading the pushbutton status
int buttonState2 = 0;
//*************************************************************************************************************************************
// SETUP
//*************************************************************************************************************************************
void setup() {
// initialize th communication:
Serial.begin(9600);
// initialize the LED pin as an output:
pinMode(doorPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin2, INPUT);
Serial.println("Connecting...");
// initialize ethernet mode:
Ethernet.begin(mac, local_ip);
Serial.println(Ethernet.localIP());
Serial.println("Connected!");//report it to the Serial
String msg="Hello Client";//Message to be sent
Serial.println("Sending Message:"+msg);//log to serial
server.println(msg);//send the message
}
//*************************************************************************************************************************************
// LOOP
//*************************************************************************************************************************************
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them:
EthernetClient client = server.available();
if (client) {
while (client.connected()){
if (client.available()){
char c = client.read();
handleCommand(c);
}
}
}
/* if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnected");
client.stop();
}*/
}
//*************************************************************************************************************************************
// Handler Commander
//*************************************************************************************************************************************
void handleCommand (char command)
{
switch (command)
{
case 'A':
{
digitalWrite(doorPin,HIGH);
Serial.print(command);
}
break;
case 'B':
{
digitalWrite(doorPin,LOW);
Serial.print(command);
}
break;
default:
break;
}
}
Visual Studio:
Código (vb.net):
Public Class FormPrincipal
Private Function Core_Connect(ByVal IP As String, ByVal Port As Integer) As Boolean
Try
tcpClient.Connect("192.168.1.90", 80)
networkStream = tcpClient.GetStream()
Catch ex As Exception
MsgBox(ex.Message)
Return False
End Try
Return True
End Function
Private Sub Core_Write(ByVal Output As String)
Try
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(Output)
Dim endByte As [Byte]() = {&HFE}
networkStream.Write(sendBytes, 0, sendBytes.Length)
networkStream.Write(endByte, 0, 1)
Catch ex As Exception
MsgBox("Falha na comunicação com o core, tente novamente!", MsgBoxStyle.OkOnly + MsgBoxStyle.Critical, "VideoIntercom")
End Try
End Sub
Private Sub Core_Disconnect()
If Not IsNothing(networkStream) Then
tcpClient.Close()
networkStream = Nothing
End If
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Core_Write("B")
Timer1.Enabled = True
End Sub
Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
Core_Write("A")
Timer1.Enabled = False
End Sub
End Class
I think I need a thread function or sub like a "Core_Read" to read when the button is clicked but I have no idea what so ever.
Thank you, Ricardo Barbara