Did some testing today and the range is fine at 3.3 volts. Comparable to the standard KaKu remote. (also on 3V battery). I can place this transmitter anywhere in my house al long as it's in the 2.4 Ghz WiFi range. You asked for the code, I'm programming the ESP-2866 in the Arduino IDE, the ESP can be added using the board manager function in the recent Arduino IDE. This way I can use Arduino libraries. You do need a board with a reset en programming button to program the ESP. That's the board on my picture. Also a 3 Volt serial-usb adaptor because the ESP in 3.3V only, not 5V tolerant. You do need some Arduino knowledge and have to handle the solder iron to get this running.
So I just combined the ESP and KaKu library's together. There is one practical issue with this setup, the WiFi SSID and password are programmed into the ESP, so when changing my WiFi network I have to compile a new version of the code and program it into the ESP.
I can't test the dimming function because I do not own a KaKu dimmer but I expect it to work as it's supported in the library.
My test are done with an ASUN-650 sun screen ( = Zonnescherm ?) controller.
Here is the code is use in this prototype :
Code: Select all
// Add the ESP8266 Boards to the Arduino IDE :
// https://github.com/esp8266/Arduino
// For the KaKu protocol the library NewRemoteTransmitter is used :
// https://github.com/hjgode/homewatch/tree/master/arduino/libraries/NewRemoteSwitch
const String ID = "KaKu_Transmitter\n";
const String Version = "Version 1.4\n";
// URL examples
// http://10.0.0.5/sendUnit?unit=1&value=1
// http://10.0.0.5/sendDim?unit=2&value=15
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <NewRemoteTransmitter.h>
const char* ssid = "yourSSID";
const char* password = "yourPassword";
ESP8266WebServer server(80);
// Create a KAKU transmitter on address 123, using digital GPIO0 to transmit,
// with a period duration of 260ms (default), repeating the transmitted
// code 2^3=8 times.
NewRemoteTransmitter transmitter(123, 0, 260, 3);
#define LED 2 // Status Led on GPIO2
void handleRoot() {
String message = ID;
message += Version;
message += "MAC ";
message += (WiFi.macAddress());
server.send(202, "text/plain", message);
}
void handleNotFound(){
String message = "Command not found\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
}
void handleCommand(){
String message = ID;
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " " + server.argName(i) + ": " + server.arg(i) + "\n";
}
if (server.uri() == "/sendUnit") {
int unit = (server.arg(0).toInt());
int val = (server.arg(1).toInt());
digitalWrite(LED, HIGH); // Blink status LED when transmitting data
transmitter.sendUnit(unit, val); // Transmit KaKu data
digitalWrite(LED, LOW);
}
if (server.uri() == "/sendDim") {
int unit = (server.arg(0).toInt());
int val = (server.arg(1).toInt());
digitalWrite(LED, HIGH); // Blink status LED when transmitting data
transmitter.sendDim(unit, val); // Transmit KaKu data
digitalWrite(LED, LOW);
}
server.send(200, "text/plain", message); // Echo the data to the webpage
// used for debugging from webbrowser
}
void setup(void){
pinMode(LED, OUTPUT);
digitalWrite(LED,LOW);
Serial.begin(9600);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
digitalWrite(LED, HIGH); // Blink LED three times to indicate that the unit is connected to WiFI
delay(200);
digitalWrite(LED, LOW);
delay(200);
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
delay(200);
digitalWrite(LED, HIGH);
delay(200);
digitalWrite(LED, LOW);
Serial.println(""); // Echo status to serial port
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("MAC address: ");
Serial.println(WiFi.macAddress());
if (MDNS.begin("esp8266")) {
Serial.println("MDNS responder started");
}
server.on("/", handleRoot);
server.on ("/sendUnit", handleCommand);
server.on ("/sendDim", handleCommand);
server.onNotFound(handleNotFound);
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}