Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Everything about esp8266 and more.

Moderator: leecollings

Post Reply
Mads
Posts: 40
Joined: Thursday 18 January 2018 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by Mads »

Hey All.

My wife is giving me grey hair :lol:
she wantet automater blinds.

I have bougth the 28BYJ-48 stepper motor, and nodemcu chip.

Found this nice software
Spoiler: show
https://github.com/nidayand/motor-on-roller-blind-ws
And I can controlle the motor. From the ip its get.
now it will be nice to have it in domoticz also.

Can see it have mqtt enable.
i have a broker running on My pi. (tested and working)
Spoiler: show
2019-01-17 14:34:36.538 Status: MQTT: Worker stopped...
2019-01-17 14:34:37.549 Status: MQTT: Connecting to 192.168.1.56:8883
2019-01-17 14:34:37.652 Status: MQTT: connected to: 192.168.1.56:8883
2019-01-17 14:34:37.754 Status: MQTT: Subscribed
Log from domoticz.

But I cant crack the way to setup, so the 2 Things talk togther.

Also have i installed this on the pi.
Node.js
RedNode

When i start the program i can see this on My serial monitor.
Spoiler: show
trying to send msg... /raw/esp8266/registre:{ "id" : "13014439", "ip":"192.168.1.140"}
Subscribed to /raw/esp8266/13014439/in
Is there a way to controlle it from domoticz :?: :? :
zygios
Posts: 15
Joined: Saturday 01 December 2018 6:42
Target OS: Linux
Domoticz version:
Contact:

Re: Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by zygios »

Hi,
Try to look into my GitHub:
https://github.com/zygios/ESP8266_AutoB ... T_Domoticz
I was working on project ESP8266+stepper motor and Domoticz, but currently it's on hold, not implemented fully.
For my blinds motor 28BYJ-48 is not enough torque, so I'm waiting for Nema Stepper.

Domoticz by default is listening to MQTT domoticz/in topic.
Mads
Posts: 40
Joined: Thursday 18 January 2018 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by Mads »

Thanks i Will give it a try.

Have does it work in domoticz?
how do I add en switch??
zygios
Posts: 15
Joined: Saturday 01 December 2018 6:42
Target OS: Linux
Domoticz version:
Contact:

Re: Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by zygios »

Hi Mads,
You need to create Dummy Device -> add Switch -> need to change Switch Type to "Blinds percentage".
In my code need to modify next line:

Code: Select all

int Domoticz_IDX[] = { 35, 36 }; 
35 replace with Your created device ID.
Mads
Posts: 40
Joined: Thursday 18 January 2018 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by Mads »

Hi again.

Now i am trying to compile your code, but got this error..

no matching function for call to 'stepper2::stepper2(int [4])'
zygios
Posts: 15
Joined: Saturday 01 December 2018 6:42
Target OS: Linux
Domoticz version:
Contact:

Re: Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by zygios »

Hi Mads,
You need to install Stepper2 library, in Arduino IDE:
https://github.com/zygios/ESP8266_autom ... r/Stepper2

Zygis
Mads
Posts: 40
Joined: Thursday 18 January 2018 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by Mads »

Thanks. Thourgth i Allready have that lib..

Will try to compile it tonigth.

Is there a way to make the Maks % for the blinds. So the Windows is completly closed?

Rigtj now My solution 'in My head' is to make a script in domo so it Will rotate like for 10 SEK, and then stops the motor.
Mads
Posts: 40
Joined: Thursday 18 January 2018 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by Mads »

Compile it succesfully and uploade to My nodemcu.

My broker is using user and Pw.

Can see that i have to make some change in your code to get that working.

But when is use this line:

if (client.connect(clientId,userName,passWord))
// if (client.connect(clientId.c_str())) out comment

IT wont compile. Where should it put My uswrname and Pw?
zygios
Posts: 15
Joined: Saturday 01 December 2018 6:42
Target OS: Linux
Domoticz version:
Contact:

Re: Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by zygios »

Hi Mads,
Try to use next code:

Code: Select all

if (client.connect(clientId.c_str(),"YourmqttuserName","YourmqttpassWord"))
Or define pass and user:

Code: Select all

const char* mqtt_user = "xxxx";
const char* mqtt_pass = "123456";

if (client.connect(clientId.c_str(),mqtt_user, mqtt_pass)

Mads
Posts: 40
Joined: Thursday 18 January 2018 20:57
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by Mads »

Hey again.

Now summer is over, and I got the time to play :)

Have you tried the code, and get it working?
radek23
Posts: 1
Joined: Friday 06 December 2019 13:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by radek23 »

Hi all.
I have a question to "Mads" or "zygios" . i have 28byj-48 + ULN2003 and wemos d1 mini. i try to use code: https://github.com/zygios/ESP8266_autom ... s_mqtt.ino
Can you more explain this arduino code, please? i change data wifi, and mqtt data but mqtt breaks connection. Wi fi connection is good. Can you tell me how can i should configure domoticz ? I cant to configure this code to control 28byj-48 with domoticz. Can you help me please?
nunorios
Posts: 1
Joined: Thursday 02 January 2020 21:59
Target OS: -
Domoticz version:
Contact:

Re: Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by nunorios »

Hello,

Today I managed to get Domoticz to communicate with the Stepper Motor through MQTT. How?:

Parts:
NodeMCU
28BYJ-48 stepper motor
ULN2003 driver board

Steps:
1. This step by step: which allowed me to setup the stepper motor, wifi and mqtt;

my sketch:

Code: Select all

/*  ___   ___  ___  _   _  ___   ___   ____ ___  ____  
 * / _ \ /___)/ _ \| | | |/ _ \ / _ \ / ___) _ \|    \ 
 *| |_| |___ | |_| | |_| | |_| | |_| ( (__| |_| | | | |
 * \___/(___/ \___/ \__  |\___/ \___(_)____)___/|_|_|_|
 *                  (____/ 
 * This sketch is about how to use the MQTT protocol to control a step motor
 * Tutorial URL  http://osoyoo.com/2017/05/17/nodemcu-lesson-16-step-motor-mqtt/
 * CopyRight www.osoyoo.com
 */

#include <ESP8266WiFi.h>
#include <PubSubClient.h>
#include <Stepper.h>
#include <ArduinoJson.h>
// Update these with values suitable for your network.
const char* ssid = "Vodafone-XXXXXXXX";//put your wifi ssid here
const char* password = "XXXXXXXX";//put your wifi password here
const char* mqtt_server = "192.168.1.XXX";


const int stepsPerRevolution = 2038;  // change this to fit the number of steps per revolution
const int stepperSpeed = 6;
// initialize the stepper library on D1,D2,D5,D6
Stepper myStepper(stepsPerRevolution, D1, D2, D5, D6);
WiFiClient espClient;
PubSubClient client(espClient);

void setup_wifi() {
   delay(100);
  // We start by connecting to a WiFi network
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid, password);
    while (WiFi.status() != WL_CONNECTED) 
    {
      delay(500);
      Serial.print(".");
    }
  randomSeed(micros());
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void callback(char* topic, byte* payload, unsigned int length) 
{
  Serial.print("Command from MQTT broker is : ");
  Serial.println(topic);

  //print payload

  
  DynamicJsonBuffer jsonBuffer( MQTT_MAX_PACKET_SIZE );
  String messageReceived="";
  
  // Affiche le topic entrant - display incoming Topic
  Serial.print("MQTT Message arrived: ");
  // decode payload message
  for (int i = 0; i < length; i++) {
    messageReceived+=((char)payload[i]);
  }
  // display incoming message
   Serial.println(messageReceived);  
  
  if(messageReceived=="abrir-estores")
  {
    myStepper.step(stepsPerRevolution);
    Serial.println("Recebida instrucao para abrir os estores" );
   }
  
   else if(messageReceived=="fechar-estores")
  {
    myStepper.step(-stepsPerRevolution);
     Serial.println("Recebida instrucao para fechar os estores" );
   }
   //Serial.println();
  
  int p =(char)payload[0]-'0';
  // step one revolution  in one direction:
  if(p==1) 
  {
    myStepper.step(stepsPerRevolution);
    Serial.print("  clockwise" );
   }
  // step one revolution in the other direction:
  else if(p==2)
  {
    myStepper.step(-stepsPerRevolution);
    Serial.print("  counterclockwise" );
   }
   Serial.println();
}
 
//  Serial.println();
 //end callback

void reconnect() {
  // Loop until we're reconnected
  while (!client.connected()) 
  {
    Serial.print("Attempting MQTT connection...");
    // Create a random client ID
    String clientId = "ESP-EstoresSala-";
    clientId += String(random(0xffff), HEX);
    // Attempt to connect
    //if you MQTT broker has clientID,username and password
    //please change following line to    if (client.connect(clientId,userName,passWord))
    if (client.connect(clientId.c_str()))
    {
      Serial.println("connected");
     //once connected to MQTT broker, subscribe command if any
      //client.subscribe("domoticz/#");
      //client.subscribe("domoticz/in");
      client.subscribe("domoticz/out");
    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      // Wait 6 seconds before retrying
      delay(6000);
    }
  }
} //end reconnect()

void setup() {
  Serial.begin(115200);
  setup_wifi();
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
  // set the speed at 80 rpm:
  myStepper.setSpeed(stepperSpeed);
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

}
2. Read this guide "Dummies guide on driving a 28BYJ-48 Stepper Motor with a ULN2003 Driver Board", to better undestard the relation between steps per revolution and speed, among other details.

3. Created a MQTT script to be called in Domoticz to trigger MQTT:
~/domoticz/scripts $ sudo nano mqtt-to-estores-abrir.sh

Code: Select all

#!/bin/bash
mosquitto_pub -m  "abrir-estores" -t "domoticz/out"
3.2 Created a second script to close the blinds

~/domoticz/scripts $ sudo nano mqtt-to-estores-fechar.sh

Code: Select all

#!/bin/bash
mosquitto_pub -m  "fechar-estores" -t "domoticz/out"
3.1 Changed the mode of both scripts to be executable: (e.g. sudo chmod +x mqtt-to-estores-fechar.sh)

4. Then I've created a dummy device in Domoticz of type switch. After, change the type to Blids;
In the actions of the button, I've added the name of the script to be executed: script://mqtt-to-estores-fechar.sh and script://mqtt-to-estores-abrir.sh

And that was all for now. The next step is to try to understand how to control the position of the roller blinds to know how many steps are required to close or open them and then assembly everything more or less like this

Please let me know if I can help in any thing.

best regards

Nuno
tontze
Posts: 317
Joined: Thursday 12 January 2017 15:30
Target OS: Linux
Domoticz version: Beta Ch
Location: Finland
Contact:

Re: Esp8266 - > 28BYJ-48 - > ikea blinds (mqtt problems)

Post by tontze »

Im having this problem : https://github.com/BatBrain/motorized-w ... s/issues/1

Any1 know how to fix it ?
-----------------------------------------
Smartthings
zigbee2mqtt
RFLink 433mhz / Nrf 2.4Ghz
Mi Light
esp8266MiLight Hub
OpenHab/HomeAssistant/Domoticz
HP T610 & Debian 5.10.19-1 x86_64[/b]
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests