I have a question about setting up a 433mhz signal.
Let me start at the beginning:
I have an automatic bed with a motor for adjusting the position of the bed.
For this, there is a remote control to operate it.
Now I have discovered that this remote works on the 433mhz signal.
Via Arduino terminal I have read the binary signal from the remote control, and I can reproduce it successfully via a 433 transmitter connected to the arduino. (via the RCSwitch.h library).
Via the regular remote I can just hold the button and the motor will keep turning in an upward direction. When I reproduce the signal, the motor runs for a short period (half a second) and then stops. In the script I can repeat the signal, but it remains run-stop-run-stop.
Does anyone know how I can extend / repeat the signal so that the motor keeps running for x seconds?
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <RCSwitch.h>
#ifndef STASSID
#define STASSID "XXXX"
#define STAPSK "XXXXXXXX"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
String token = "XXXXXXXXXX";
RCSwitch transmitter = RCSwitch();
ESP8266WebServer server(80);
const int led = 13;
void handleRoot() {
if (!validToken()) {
server.send(403, "text/plain", "Unauthorized");
return;
}
digitalWrite(led, 1);
server.send(200, "text/plain", "hello from esp8266!");
digitalWrite(led, 0);
}
void handleLightsOn() {
if (!validToken()) {
server.send(403, "text/plain", "Unauthorized");
return;
}
transmitter.send("000100000000000100000011");
server.send(200, "text/plain", "lights are on!");
}
void handleLightsOff() {
if (!validToken()) {
server.send(403, "text/plain", "Unauthorized");
return;
}
transmitter.send("000100000000000100001100");
server.send(200, "text/plain", "lights are off!");
}
void handlebutton1() {
if (!validToken()) {
server.send(403, "text/plain", "Unauthorized");
return;
}
transmitter.send("000100000000000100000011");
server.send(200, "text/plain", "handlebutton1");
}
void handlebutton2() {
if (!validToken()) {
server.send(403, "text/plain", "Unauthorized");
return;
}
transmitter.send("000100000000000100001100");
server.send(200, "text/plain", "handlebutton2");
}
void handlebutton3() {
if (!validToken()) {
server.send(403, "text/plain", "Unauthorized");
return;
}
transmitter.send("000100000000000100110000");
server.send(200, "text/plain", "handlebutton3");
}
void handlebutton4() {
if (!validToken()) {
server.send(403, "text/plain", "Unauthorized");
return;
}
transmitter.send("000100000000000111000000");
server.send(200, "text/plain", "handlebutton4");
}
void handlebutton5() {
if (!validToken()) {
server.send(403, "text/plain", "Unauthorized");
return;
}
transmitter.send("000100000000000100110011");
server.send(200, "text/plain", "handlebutton5");
}
void handlebutton6() {
if (!validToken()) {
server.send(403, "text/plain", "Unauthorized");
return;
}
transmitter.send("000100000000000100111100");
server.send(200, "text/plain", "handlebutton6");
}
void handleNotFound() {
digitalWrite(led, 1);
server.send(404, "text/plain", "404: Not Found" );
digitalWrite(led, 0);
}
bool validToken() {
return !(server.arg("Token") == "" || server.arg("Token") != token);
}
void setup(void) {
transmitter.enableTransmit(D2);
transmitter.setProtocol(1);
transmitter.setPulseLength(480);
transmitter.setRepeatTransmit(15);
pinMode(led, OUTPUT);
digitalWrite(led, 0);
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on("/lightsOn", handleLightsOn);
server.on("/lightsOff", handleLightsOff);
server.on("/Omhoog_hoofd_NM", handlebutton1);
server.on("/Omlaag_hoofd_NM", handlebutton2);
server.on("/Omhoog_voet_NM", handlebutton3);
server.on("/Omlaag_voet_NM", handlebutton4);
server.on("/Omlaag_alles_NM", handlebutton5);
server.on("/Lampjes_afstandsbediening", handlebutton6);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void) {
server.handleClient();
MDNS.update();
}