Hey guys,
I am using a D1 mini as Sinric Host to control my smarthome.
Garage doors (433Mhz) Switches (433MHz) and Windows Shutters (Stepper Motors connected to DRV8825).
This is my biggest project so far and the thing i am most proud of.
But with implementing a second DRV to control the left window shutter independently, my project got buggy.
I spent at least 10 hours trying to debug the code while pulling out my hair, changed many parts back and forth but it refuses to work.
Without external help i am not capable of finishing it.
But i must to be able to live peacefully.
The program (huge, but much to be ignored bc. repetitive) keeps getting stuck.
Let's say i start the // 7.40 Nap AN with google home. The window shutters close according to code and open 7 hours and 40 minutes later, but then The ESP does not respond to new requests anymore. I have to reset it to get it back to work again.
Since today i got the additional bug that the DRV "Oben" at Pins
const int resetSleepOben = D6;
const int StepOben = D7;
const int DirOben = D8;
which is controlling the left window shutter "rollolinks" is still working, but the DRV "Unten at Pins
const int resetSleepUnten = D2;
const int StepUnten = D3;
const int DirUnten = D4;
does not move anymore.
I am sure the problem is in how it is handeling the Websocket code because i just copypastaed it.
Here is the code in pieces with a small descriptions below.
Below those also the full code.
#include <AccelStepper.h>
#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266Ping.h>
#include <ESP8266WiFiMulti.h>
#include <WebSocketsClient.h>
#include <ArduinoJson.h>
#include <StreamString.h>
#include <RCSwitch.h>
boolean napmode = false;
boolean rollolinks = true;
unsigned long napende;
const int ledPin = 2;
const int resetSleepUnten = D2;
const int StepUnten = D3;
const int DirUnten = D4;
const int resetSleepOben = D6;
const int StepOben = D7;
const int DirOben = D8;
const int transmitterPin = D5;
IPAddress ip (192, 168, 178, 83);
RCSwitch mySwitch = RCSwitch();
AccelStepper stepperUnten = AccelStepper(1, StepUnten, DirUnten); //STEP, DIR
AccelStepper stepperOben = AccelStepper(1, StepOben, DirOben); //STEP, DIR
ESP8266WiFiMulti WiFiMulti;
WebSocketsClient webSocket;
WiFiClient client;
#define MyApiKey "XXX"
#define MySSID "It hurts when IP"
#define MyWifiPassword "XXX"
#define HEARTBEAT_INTERVAL 300000 // 5 Minutes
uint64_t heartbeatTimestamp = 0;
boolean isConnected = false;
Importing all libraries. rollolinks=true makes the left windows shutter move with the rest. "Unten" Corresponds to the DRV that has 2 window shutters, "Oben" to the DRV for the left window shutter.
void turnOn(String deviceId) {
if (deviceId == "5c3cbebdbd3a297e44c2b4ad") // eins
{
senden_pollin("000000000000010101010001", "eins");
}
else if (deviceId == "5c2ba92f796c411478dfc24b") // zwei
{
senden_pollin("000000000001000101010001", "zwei");
}
else if (deviceId == "5c3cc0c3bd3a297e44c2b4b0") // drei
{
senden_pollin("000000000001010001010001", "drei");
}
else if (deviceId == "5c2ba940796c411478dfc24f") // vier
{
senden_pollin("000000000001010100010001", "vier");
}
else if (deviceId == "5c2ba940796c411478dfc24f") // fünf
{
senden_pollin("010000000000010101010001", "fünf");
}
First turn on strings for Power plug sockets. all working.
// ROLLOS ANFANG
else if (deviceId == "5e9398923fe9eb7fe2524f5a") // rollolinks AN
{
rollolinks = true;
blinken(200,1);
}
else if (deviceId == "5e5f82534fcc8d0db3409269") // rollos AN
{
rollosBewegen(47000);
}
else if (deviceId == "5e66578ecafbba4ea4f42cbc") // Rolloreset jetzt AN
{
stepperUnten.setCurrentPosition(47000);
if (rollolinks) {
stepperOben.setCurrentPosition(47000);
}
rollosBewegen(0);
}
else if (deviceId == "5e85581784b8e724dc0f2d04") // 0.20 Nap AN
{
napmode = true;
napende = (millis()+1200000-8000);
rollosBewegen(47000);
}
else if (deviceId == "5e85583984b8e724dc0f2d1b") // 1.40 Nap AN
{
napmode = true;
napende = (millis()+6000000-8000);
rollosBewegen(47000);
}
else if (deviceId == "5e8557cb84b8e724dc0f2cd3") // 6.10 Nap AN
{
napmode = true;
napende = (millis()+22200000-8000);
rollosBewegen(47000);
}
else if (deviceId == "5e85580b84b8e724dc0f2cfa") // 7.40 Nap AN
{
napmode = true;
napende = (millis()+27600000-8000);
rollosBewegen(47000);
}
else if (deviceId == "5e86275fce60582b5f88bf98") // 9.10 Nap AN
{
napmode = true;
napende = (millis()+33000000-8000);
rollosBewegen(47000);
}
// ROLLOS ENDE
Turn on strings for the window shutters.
"Rolloreset" opens the rollos in case the ESP gets restarted while they are closed.
The "Nap" codes close the shutters and create a timestamp in the future for them to be opened again. This is handled in the loop.
else if (deviceId == "5c3cbc9bbd3a297e44c2b4a2") // rechner
{
senden_pollin("010101010100010101010001", "rechner");
}
else if (deviceId == "5c3cbc4fbd3a297e44c2b4a0") // system
{
senden_pollin("000000000000010101010001", "eins");
delay(1600);
senden_pollin("010101010100010101010001", "rechner");
}
else if (deviceId == "5c44701ae20cf81e2fc7d2c9") // tor
{
senden_hof("11110011001111101", "gartentor");
}
else if (deviceId == "5c447037e20cf81e2fc7d2cb") // hoflicht
{
senden_hof("11110011001111000", "hoflicht");
}
else if (deviceId == "5c4473c7e20cf81e2fc7d2d0") // omator
{
senden_hof("11110011001111100", "omator");
}
else if (deviceId == "5c4473dde20cf81e2fc7d2d2") // werkstatttor
{
senden_hof("11110011001111001", "werkstatttor");
}
else if (deviceId == "5c44d09ef7e36f2beb4ee743") // hoflicht blinken
{
senden_hof("11110011001111000", "hoflicht");
delay(2400);
senden_hof("11110011001111000", "hoflicht");
delay(2400);
senden_hof("11110011001111000", "hoflicht");
delay(1200);
senden_hof("11110011001111000", "hoflicht");
delay(1200);
senden_hof("11110011001111000", "hoflicht");
delay(1200);
senden_hof("11110011001111000", "hoflicht");
delay(1200);
senden_hof("11110011001111000", "hoflicht");
delay(400);
senden_hof("11110011001111000", "hoflicht");
delay(400);
senden_hof("11110011001111000", "hoflicht");
delay(400);
senden_hof("11110011001111000", "hoflicht");
delay(400);
senden_hof("11110011001111000", "hoflicht");
delay(400);
senden_hof("11110011001111000", "hoflicht");
delay(400);
senden_hof("11110011001111000", "hoflicht");
delay(400);
senden_hof("11110011001111000", "hoflicht");
delay(400);
}
else if (deviceId == "5c3f5f57fa93fa46cefa20ec") // verlassen routine tor
{
senden_pollin("010101010100010101010001", "rechner");
Serial.print("Pinge PC \n");
if (Ping.ping(ip) == false) {
delay(4000);
senden_pollin("010101010100010101010001", "rechner");
}
delay(500);
senden_hof("11110011001111000", "hoflicht");
delay(1000);
senden_hof("11110011001111101", "gartentor");
for (int i=0; i <= 30; i++){
if (Ping.ping(ip) == false) {
Serial.print("keine Antwort \n");
i = 30;
}
else {
Serial.print("Antwort \n");
blinken(50,1);
if (i == 4){
senden_pollin("010101010100010101010001", "rechner");
blinken(50,4);
}
}
}
breathe();
senden_pollin("000000000000010101010100", "eins");
}
else if (deviceId == "5c44d10ef7e36f2beb4ee749") // verlassen routine kein tor
{
senden_pollin("010101010100010101010001", "rechner");
Serial.print("Pinge PC \n");
IPAddress ip (192, 168, 178, 83);
if (Ping.ping(ip) == false) {
delay(4000);
senden_pollin("010101010100010101010001", "rechner");
}
delay(500);
senden_hof("11110011001111000", "hoflicht");
for (int i=0; i <= 30; i++){
if (Ping.ping(ip) == false) {
Serial.print("keine Antwort \n");
i = 30;
}
else {
Serial.print("Antwort \n");
blinken(50,1);
if (i == 4){
senden_pollin("010101010100010101010001", "rechner");
blinken(50,4);
}
}
}
breathe();
senden_pollin("000000000000010101010100", "eins");
}
else
{
Serial.print("Turn on for unknown device id: ");
Serial.println(deviceId);
}
}
Some other devices. All fine.