Close

Open the bathroom window, Close the bathroom window

A project log for Home Smart Mesh

Mesh of sensors, zigbee, custom RF, BT, wifi, all to MQTT Gateways on Raspberry Pi with database, dashboard and webapps.

wassimWassim 04/26/2017 at 17:520 Comments

Demo

Installation

Software : MQTT Ruler

void mqtt_c::on_message(const struct mosquitto_message *message)
{
    std::string msg(static_cast<const char*>(message->payload) );
    std::string topic(message->topic);
    if(topic.find("Nodes/") == 0)
    {
		std::string Text = topic;
		//the topic is "Node/6/Humidity"
		utl::TakeParseTo(Text,'/');//remove first section 
		std::string Id = utl::TakeParseTo(Text,'/');//take the second element
		int NodeId = std::stoi(Id);
		float humidity_val = std::stof(msg);
		publish_humidity_status(NodeId,humidity_val);
void from_50_Green_to_Blue(float humidity,unsigned char &red,
									unsigned char &green,
									unsigned char &blue)
{
	red = 0, green = 5, blue = 0;
	if(humidity > 60)//60 -> 100
	{
		red = 0, green = 50, blue = 0;
		float factor = (humidity - 60)/40;//0->1
		float blue_f = 255 * factor;// 0 -> 255
		blue = f2c_sat(blue_f);
		float green_f = 50 - 50 * factor;// 50 -> 0
		green = f2c_sat(green_f);
	}
	else if (humidity > 50)//50 -> 60
	{
		float factor = (humidity - 50)/10;//0 ->1
		green = f2c_sat(5 + factor * 45);//5 -> 50
	}
}

The complete MQTT humidity to color ruler can be found with the rest of the IoT_Frameworks repo here in github.


Discussions