Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Controll Mumbi (M-AFS104) RF PowerPlug Control via ESP32 (arduino)
//https://fast.jumpingcrab.com/wp/blog/2018/05/13/mumbi-funksteckdosen-mittel-esp32-und-rf-transmitter-fernsteuern/
#include <ESPUI.h>
#if defined(ESP32)
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
const char *ssid = "Your WIFI ssid";
const char *password = "Your WIFI Password";
const char *stationcode = "FFFFF";
const char *on = "0F";
const char *off = "F0";
//const char *plug1 = "0FFFF";
const char *plug[] = {"0FFFF","F0FFF","FF0FF","FFF0F"};
const char *switch_name[] = {"Switch1","Switch2","Switch3","Switch4"};
#define TX_PIN 23
void switch1(Control sender, int value) {
switch (value) {
case S_ACTIVE:
Serial.print("Active:");
sendCode( ( String(stationcode)+String(plug[0])+String(on) ).c_str() ); //send Code PLUG1 [ON]
break;
case S_INACTIVE:
Serial.print("Inactive");
sendCode( ( String(stationcode)+String(plug[0])+String(off) ).c_str() ); //send Code PLUG1 [OFF]
break;
}
Serial.print(" ");
Serial.println(sender.id);
}
void switch2(Control sender, int value) {
switch (value) {
case S_ACTIVE:
Serial.print("Active:");
sendCode( ( String(stationcode)+String(plug[1])+String(on) ).c_str() ); //send Code PLUG2 [ON]
break;
case S_INACTIVE:
Serial.print("Inactive");
sendCode( ( String(stationcode)+String(plug[1])+String(off) ).c_str() ); //send Code PLUG2 [OFF]
break;
}
Serial.print(" ");
Serial.println(sender.id);
}
void switch3(Control sender, int value) {
switch (value) {
case S_ACTIVE:
Serial.print("Active:");
sendCode( ( String(stationcode)+String(plug[2])+String(on) ).c_str() ); //send Code PLUG3 [ON]
break;
case S_INACTIVE:
Serial.print("Inactive");
sendCode( ( String(stationcode)+String(plug[2])+String(off) ).c_str() ); //send Code PLUG3 [OFF]
break;
}
Serial.print(" ");
Serial.println(sender.id);
}
void switch4(Control sender, int value) {
switch (value) {
case S_ACTIVE:
Serial.print("Active:");
sendCode( ( String(stationcode)+String(plug[3])+String(on) ).c_str() ); //send Code PLUG4 [ON]
break;
case S_INACTIVE:
Serial.print("Inactive");
sendCode( ( String(stationcode)+String(plug[3])+String(off) ).c_str() ); //send Code PLUG4 [OFF]
break;
}
Serial.print(" ");
Serial.println(sender.id);
}
boolean sendCode(const char* code){ //empfange den Code in Form eines Char[]
for(short z = 0; z<7; z++){ //wiederhole den Code 7x
for(short i = 0; i<12; i++){ //ein Code besteht aus 12bits
sendByte(code[i]);
}
sendByte('x'); //send a x to finish one transmition
}
return true;
}
//Protocolinfo
//Send F,0 and x(sync) acording to the rc-sitch receiver-demo)
//MUMBI M-AFS 104
//Protokoll 1 lt rc-switch library
//F = OFF -___---_ (one digit = 350µs)
//0 = ON -___-___
//x = sync -_______________________________
//SCALE 01234567890123456789012345678901
void sendByte(char i) {
switch(i){
case 'F':{ //Code for 'F'
digitalWrite(TX_PIN,HIGH);
wait(1);
digitalWrite(TX_PIN,LOW);
wait(3);
digitalWrite(TX_PIN,HIGH);
wait(3);
digitalWrite(TX_PIN,LOW);
wait(1);
return;
}
case '0':{ //Der Code for '0'
digitalWrite(TX_PIN,HIGH);
wait(1);
digitalWrite(TX_PIN,LOW);
wait(3);
digitalWrite(TX_PIN,HIGH);
wait(1);
digitalWrite(TX_PIN,LOW);
wait(3);
return;
}
case 'x':{ //Code for x(sync)
digitalWrite(TX_PIN,HIGH);
wait(1);
digitalWrite(TX_PIN,LOW);
wait(31);
}
}
}
//according to the Protocol ther are ~350 µs per signal
//this is ~342 µs for running the code (arduino genertated code is probably a little slower, than generic C++)
void wait(int x) {
delayMicroseconds(x*342); //warte x*350us
}
void setup(void) {
Serial.begin(115200);
pinMode(TX_PIN, OUTPUT);
Serial.print("Using GPIO PIN :");
Serial.println(TX_PIN);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
//second argument is the initial state
ESPUI.switcher(switch_name[0], false, &switch1, COLOR_ALIZARIN);
ESPUI.switcher(switch_name[1], true, &switch2, COLOR_ALIZARIN);
ESPUI.switcher(switch_name[2], true, &switch3, COLOR_ALIZARIN);
ESPUI.switcher(switch_name[3], true, &switch4, COLOR_ALIZARIN);
ESPUI.begin("ESP32 Control");
}
void loop(void) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.