@quadmasta sorry I didn’t get back with you I have family in town. I’m not sure the cover platform will help anyways as my servo is a continuous rotating and rotates about 20 times to close and open the blinds.
I’m not too sure what you mean by the internet, if you mean to wifi, then did you enter your ssid and password properly to connect to your router? The only other items beyond that will be you topics. If all of those are filled in and you have mosquitto or another Mqtt service properly running, you should be good.
The ssid and password are correct. The Esp8266 does not connect to the wifi, as seen from the serial monitor. Other codes have worked fine in connecting to wifi and the mqtt server.
I agree, my parrots room has 4 windows with blinds that we need to open and close everyday to give them sunlight and to help protect my neighbors ears when they go bananas at the end of the evenings and since we work in shifts we could ensure they always be open/close as needed.
I have been trying to use your project but I’m probably not understanding something related with the topics, I have been trying to set it up as you show on your configuration.yaml example.
my sketch atm is:
#include <Servo.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiAP.h>
#include <ESP8266WiFiGeneric.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266WiFiScan.h>
#include <ESP8266WiFiSTA.h>
#include <ESP8266WiFiType.h>
#include <WiFiClient.h>
#include <WiFiClientSecure.h>
#include <WiFiServer.h>
#include <WiFiUdp.h>
#include <PubSubClient.h>
/************ WIFI and MQTT INFORMATION (CHANGE THESE FOR YOUR SETUP) ******************/
#define wifi_ssid "**********" //enter your WIFI SSID
#define wifi_password "*****************" //enter your WIFI Password
#define mqtt_server "***.***.*.***" // Enter your MQTT server adderss or IP. I use my DuckDNS adddress (yourname.duckdns.org) in this field
#define mqtt_user "******" //enter your MQTT username
#define mqtt_password "************" //enter your password
WiFiClient espClient;
PubSubClient client(espClient);
Servo myservo;
int val;
int itsatrap = 0;
void setup() {
Serial.begin(115200);
setup_wifi();
client.setServer(mqtt_server, 1883); //CHANGE PORT HERE IF NEEDED
client.setCallback(callback);
}
void setup_wifi() {
delay(10);
Serial.println();
Serial.print("Connecting to ");
Serial.println(wifi_ssid);
WiFi.mode(WIFI_STA);
WiFi.begin(wifi_ssid, wifi_password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void callback(char* topic, byte* payload, unsigned int length) {
char p[length + 1];
memcpy(p, payload, length);
p[length] = NULL;
String message(p);
String mytopic(topic);
if (itsatrap == 0 && mytopic == "blind/bc/command" && message.equals("ON")){
myservo.attach(D3);
delay(500);
myservo.write(90);
client.publish("blind/bc/state", "ON");
delay(1000);
myservo.detach();
}
else if (mytopic == "blind/br/command" && message.equalsIgnoreCase("OFF")){
myservo.attach(D3);
delay(500);
myservo.write(0);
client.publish("blind/br/state", "OFF");
delay(1000);
myservo.detach();
}
else if (mytopic == "blind/bc/level"){
myservo.attach(D3);
delay(500);
val = message.toInt(); //converts command to integer to be used for positional arrangement
val = map (val, 0, 99, 0, 180);
myservo.write(val);
client.publish("blind/bc/state", "ON");
delay(3000);
myservo.detach();
itsatrap = 1;
}
else{
itsatrap = 0;
}
}
void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();
}
void reconnect() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
// Attempt to connect
if (client.connect("ESPBlindstl666", mqtt_user, mqtt_password)) {
Serial.println("connected");
client.subscribe("command");
client.subscribe("level");
client.publish("state", "OFF");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}
Ok, I think I can help. It looks like in your void reconnect your topics don’t match what you have above in your void callback(). If you are using my .yaml syntax then the first subscribe should be /blind/bc/command, and the second subscribe should be /blind/bc/level.
Also in the first else if, in the void callback, you need to replace /blind/br/command with /blind/bc/command. As well as /blind/br/state with /blind/bc/state.
I’m not too sure, if you are using a standard analog rc servo looks the futaba s3003 it should rotate 90 degrees for on and then the opposite 90 degrees for off.
It was late yesterday when I gave up but its only rotating 90 degrees the same way for ON and OFF and the brightness isn’t working as it should as well but hass already communicating so its a start