Skip to content

GeorgeHahn/Charlotte

Repository files navigation

Charlotte pipeline status NuGet

The Modern MQTT Framework

public class ProximitySensor
{
	public ProximitySensor(string broker)
	{
		var mqtt = new Charlotte(broker);

		mqtt.On["{room}/sensors/{sensor}"] = msg =>
		{
			Log("Data received from {0} (in {1}): {2}", msg.sensor, msg.room, msg.Message);
		};

		mqtt.On["sensors/bedroom/presence"] = async msg =>
		{
			if (msg.Message == "human present")
			{
				await mqtt.Publish("lights/bedroom", "on");
			}
		};
	}