RGB LED strip control using Arduino and MQTT

arduino
mqtt
led
Tags: #<Tag:0x00007f18264a6f10> #<Tag:0x00007f18264a6d58> #<Tag:0x00007f18264a6bc8>

(JustAProgrammer) #21

Did you ever think of using the ARILUX controller for Openhab?
Didnt find documentation about it yet, but its basically a modded ESP8266 board.
costs about 5$ and I have 5 of them.
Would be cool to use them in Openhab.


(kluszczyn) #22

Please check sonoff-tasmota, it’s supporting lot of things beside sonoff devices, details in


I was using this firmware together with MagicHome and on bare esp12 modules. Works great!


(Michael Chilson) #23

Please be warned seems to be missing configuration files to work.

I have gotten this to flash to an Arduino Nano using an ENC28J60.

Arduino Code Modified

#include <UIPEthernet.h>
#include <utility/logging.h>
#include <PubSubClient.h>

// Set the MAC address
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0F, 0x5E, 0x69 };

// Set fallback IP address if DHCP fails
IPAddress ip(192,168,3,20);

// Set the broker server IP
byte server[] = { 192,168,3,3 };

EthernetClient ethClient;

// Callback function header
void callback(char* topic, byte* payload, unsigned int length);

PubSubClient client(server, 1883, callback, ethClient);

int SoffitR;
int SoffitG;
int SoffitB;
int BLUE = 5;                   
int GREEN = 7; 
int RED = 3; 

void setup()
{
    // Open serial communications
  Serial.begin(9600);
  
    // Start with a hard-coded address:
    Serial.println("Assigning Static IP address:");
    Ethernet.begin(mac, ip);
  
     Serial.print("My address:");
  Serial.println(Ethernet.localIP());
  
  // Connect to Broker, give it arduino as the name
  if (client.connect("arduino_LED2")) {
    
    // Publish a message to the status topic
    client.publish("status/arduino_LED2","Arduino LED2 is now online");
    
    // Listen for messages on the control topic
    client.subscribe("control/arduino_LED2/#");
  }
}


void loop()
{
  client.loop();
}

void callback(char* topic, byte* payload, unsigned int length) {
  // check for messages on subscribed topics
  payload[length] = '\0';
  Serial.print("Topic: ");
  Serial.println(String(topic));
  


  // check topic to identify type of content
if(String(topic) == "control/arduino_LED/livingroom/color") {
    // convert payload to String
    String value = String((char*)payload);
    //value.trim();
    Serial.print (value);
    //Serial.flush();
    // split string at every "," and store in proper variable
    // convert final result to integer
    SoffitR = value.substring(0,value.indexOf(',')).toInt();
    SoffitG = value.substring(value.indexOf(',')+1,value.lastIndexOf(',')).toInt();
    SoffitB = value.substring(value.lastIndexOf(',')+1).toInt();

    // print obtained values for debugging
    Serial.print("RED: ");
    Serial.println(SoffitR);
    //client.publish("status/arduino_LED2", SoffitR);

    Serial.print("GREEN: ");
    Serial.println(SoffitG);
    //client.publish("status/arduino_LED2", SoffitG);
    
    Serial.print("BLUE: ");
    Serial.println(SoffitB);
    //client.publish("status/arduino_LED2/soffit/color/blue", int SoffitB);
    //Serial.flush();
   
  analogWrite(GREEN, SoffitG);
  analogWrite(RED, SoffitR);
  analogWrite(BLUE, SoffitB);
  
   while(Serial.available())
  Serial.read();
    
  }
}

.Items Code

/* LED STRIPS */
Color LivSoffitLight "Living Room Soffit Color" (Lights_LivingRoom)
String LivSoffitLightColor (Lights_LivingRoom) {mqtt=">[mosquitto:control/arduino_LED/livingroom/color:command:*:default]"}
Number LivSoffitAnimation "Living Room Soffit Animation" (Lights_LivingRoom) {mqtt=">[mosquitto:control/arduino_LED/livingroom/animation:command:*:default]"}

Sitemap Code:

sitemap demo label="MC Smart Home Automation" {
    Frame label="Date" {
        Text item=Date
    }

Frame label="Accent-Lighting" {


Colorpicker item=LivSoffitLight


}

}

I have not gotten this to acutally light the LED’s on the Arduino I think this is missing rules. I will post rules if I figure them out. If anyone has knowledge about the rules I need I could use them.

Otherwise this will connect to mosquitto MQTT broker.