Skip to content

Code that allows you to open electronic locks  #457

@Esk-C

Description

@Esk-C

using System;
using InTheHand.Net.Sockets;
using InTheHand.Net.Bluetooth;
using System.IO;

class Program
{
static void Main(string[] args)
{
string deviceAddress = "00:11:22:33:44:55"; // Address MAC From the device Bluetooth
Guid serviceUuid = new Guid("00001101-0000-1000-8000-00805F9B34FB"); // UUID From the service Bluetooth

    try
    {
        BluetoothAddress address = BluetoothAddress.Parse(deviceAddress);
        BluetoothClient client = new BluetoothClient();
        client.Connect(new BluetoothEndPoint(address, serviceUuid));

        using (NetworkStream stream = client.GetStream())
        using (StreamWriter writer = new StreamWriter(stream))
        using (StreamReader reader = new StreamReader(stream))
        {
            // Send command to open the lock 
            writer.WriteLine("OPEN"); // O specific command depends on the device
            writer.Flush();

            // Read response from device
            string response = reader.ReadLine();
            Console.WriteLine("Response: " + response);
        }

        client.Close();
    }
    catch (Exception ex)
    {
        Console.WriteLine("Error: " + ex.Message);
    }
}

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions