private static void Main(string[] args) { var ipcon = new IPConnection(); ipcon.Connect(HOST, PORT); _client = new MqttClient(MqttServer, 17124, false, new MqttSslProtocols(), null, null); _client.Connect(Guid.NewGuid().ToString(), MqttUser, MqttPassword); var distanceUs1 = new BrickletDistanceUS(Dist1Id, ipcon); var distanceUs2 = new BrickletDistanceUS(Dist2Id, ipcon); var CompassBoxBricklet = new BrickletCompass(CompassBox, ipcon); var CompassRobotBricklet = new BrickletCompass(CompassRobot, ipcon); while (true) { var val1 = CalculateCM(distanceUs1.GetDistanceValue()); var val2 = CalculateCM(distanceUs2.GetDistanceValue()); var boxHeading = CompassBoxBricklet.GetHeading(); var robotHeading = CompassRobotBricklet.GetHeading(); _client.Publish("/mobile/distance", Encoding.UTF8.GetBytes( "{\n" + $"\"robotHeading\":{robotHeading / 10},\n" + $"\"boxHeading\":{boxHeading / 10},\n" + $"\"dist1\":{val1},\n" + $"\"dist2\":{val2}\n" + "}"), MqttMsgBase.QOS_LEVEL_EXACTLY_ONCE, false); Thread.Sleep(500); } }
private static string UID = "XYZ"; // Change XYZ to the UID of your Distance US Bricklet #endregion Fields #region Methods static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletDistanceUS dus = new BrickletDistanceUS(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current distance value int distance = dus.GetDistanceValue(); Console.WriteLine("Distance Value: " + distance); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }
private static string UID = "XYZ"; // Change XYZ to the UID of your Distance US Bricklet static void Main() { IPConnection ipcon = new IPConnection(); // Create IP connection BrickletDistanceUS dus = new BrickletDistanceUS(UID, ipcon); // Create device object ipcon.Connect(HOST, PORT); // Connect to brickd // Don't use device before ipcon is connected // Get current distance value int distance = dus.GetDistanceValue(); Console.WriteLine("Distance Value: " + distance); Console.WriteLine("Press enter to exit"); Console.ReadLine(); ipcon.Disconnect(); }