Demo
- On the down right side of the video is the RGB Led status indicator that turns blue when the bathroom is humid (Humidity = Water = Blue) and green again when it is time to close it not to use much eating energy for example.
- In this video, I closed the door to raise the humidity level, then opened the door and the window to evacuate it.
Installation
- STM8L wireless sensor node with its BME280 as a humidity sensor
- An RF Repeater node that is visible on the down right side of the video which has an WS2812B as an RG led status indicator
- A raspberry pi with an RF dongle as depicted in the Gallery HW + SW design
Software : MQTT Ruler
- The relevant software to fulfill this action in addition to the already installed HW+SW, is simply one small MQTT client, I wrote it in C++ but it could be in python as well, this client is nothing more than a ruler, it subscribes to an MQTT message (humidity level of the bathroom sensor id), and then produces a color depending on the level and send it again through another MQTT channel where the RF dongle is subscribed to send an RF signal to the right node id with the color to set.
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);
- This code extracts the node id from the Topic, converts the message payload from text to float and sends them together to the "publish_humidity_status()" function which is testing the node id, applying the rule and publishing the message.
- The function applying the rule which converts the humidity float into a color can be seen below
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
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.