Hello, I’m new in programing and I have started if one tutoreal, but the guy don’t post the continue to control the LED RGB.
So I’m asking for helping to continue, beacause I allready buy and made the board… Sorry about my english =[
I have follow everthing from here:
https://www.mksmarthouse.com/led-control
This is the program:
#include <ESP8266WiFi.h>
#include <MQTTClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <ESP8266HTTPUpdateServer.h>
/* ---------- DO NOT EDIT ANYTHING ABOVE THIS LINE ---------- */
//Only edit the settings in this section
/* WIFI Settings /
// Name of wifi network
const char ssid = “****”;
// Password to wifi network
const char* password = “*****”;
/* Web Updater Settings /
// Host Name of Device
const char host = “MK-LEDStripControl1”;
// Path to access firmware update page (Not Neccessary to change)
const char* update_path = “/firmware”;
// Username to access the web update page
const char* update_username = “admin”;
// Password to access the web update page
const char* update_password = “Admin”;
/* MQTT Settings /
// Topic which listens for commands
char subscribeTopic = “MK-SmartHouse/lights/MK-LEDStripControl1”;
//MQTT Server IP Address
const char* server = “192.168.1.102”;
//Unique device ID
const char* mqttDeviceID = “MK-SmartHouseDevice7”;
/* ---------- DO NOT EDIT ANYTHING BELOW THIS LINE ---------- */
// Declare Esp8266 Pins Used For LED Strip
const int greenLed = 12;
const int redLed = 14;
const int blueLed = 13;
// initialize led values
String greenLedVal = “0”;
String redLedVal = “0”;
String blueLedVal = “0”;
// initialize led values
String greenLedValLast = “0”;
String redLedValLast = “0”;
String blueLedValLast = “0”;
ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;
WiFiClient net;
MQTTClient client;
unsigned long lastMillis = 0;
void connect();
void setup()
{
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
client.begin(server, net);
client.onMessage(messageReceived);
connect();
MDNS.begin(host);
httpUpdater.setup(&httpServer, update_path, update_username, update_password);
httpServer.begin();
MDNS.addService(“http”, “tcp”, 80);
}
void connect()
{
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
}
while (!client.connect(mqttDeviceID))
{
delay(1000);
}
client.subscribe(subscribeTopic);
}
void loop()
{
client.loop();
delay(10);
if(!client.connected())
{
connect();
}
httpServer.handleClient();
}
void messageReceived(String &topic, String &payload)
{
String stringOne = payload;
Serial.println(stringOne);
// find first ; in the string
int firstClosingBracket = stringOne.indexOf(’;’)+1;
// find second ; in the string
int secondOpeningBracket = firstClosingBracket + 1;
int secondClosingBracket = stringOne.indexOf(’;’, secondOpeningBracket);
// find the third ; in the string
int thirdOpeningBracket = secondClosingBracket + 1;
int thirdClosingBracket = stringOne.indexOf(’;’, thirdOpeningBracket);
// using the locations of ; find values
greenLedVal = stringOne.substring(0 , (firstClosingBracket - 1));
redLedVal = stringOne.substring(firstClosingBracket , secondClosingBracket);
blueLedVal = stringOne.substring((secondClosingBracket +1) , thirdClosingBracket);
if ((blueLedVal != blueLedValLast) || (greenLedVal != greenLedValLast) || (redLedVal != redLedValLast))
{
Serial.println(blueLedVal.toInt());
Serial.println(redLedVal.toInt());
Serial.println(greenLedVal.toInt());
analogWrite(blueLed, ((blueLedVal.toInt()) * 10.23));
analogWrite(redLed, ((redLedVal.toInt()) * 10.23));
analogWrite(greenLed, ((greenLedVal.toInt()) * 10.23));
greenLedValLast = greenLedVal;
redLedValLast = redLedVal;
blueLedValLast = blueLedVal;
}
else
{
}
}
I need help to input the web control:
/etc/openhab2/items/home.items
/etc/openhab2/sitemaps/home.sitemap
/etc/openhab2/rules/home.rules
I promised my family that the LEDs would be ready for Christmas , so I’m turning to the community.