Добавляем модуль приема и передачи по радио 433Mhz

This commit is contained in:
2022-08-09 13:11:13 +03:00
parent 31b0e0d786
commit 755625cc35
5 changed files with 198 additions and 249 deletions

View File

@@ -5,21 +5,17 @@ void* getAPI_ButtonIn(String subtype, String params);
void* getAPI_ButtonOut(String subtype, String params);
void* getAPI_IoTServo(String subtype, String params);
void* getAPI_Mp3(String subtype, String params);
void* getAPI_Telegram(String subtype, String params);
void* getAPI_Timer(String subtype, String params);
void* getAPI_Ads1115(String subtype, String params);
void* getAPI_Aht20(String subtype, String params);
void* getAPI_AnalogAdc(String subtype, String params);
void* getAPI_Bme280(String subtype, String params);
void* getAPI_Bmp280(String subtype, String params);
void* getAPI_Dht1122(String subtype, String params);
void* getAPI_Ds18b20(String subtype, String params);
void* getAPI_Emon(String subtype, String params);
void* getAPI_GY21(String subtype, String params);
void* getAPI_Hdc1080(String subtype, String params);
void* getAPI_Max6675(String subtype, String params);
void* getAPI_Mhz19(String subtype, String params);
void* getAPI_Sds011(String subtype, String params);
void* getAPI_RCswitch(String subtype, String params);
void* getAPI_Sht20(String subtype, String params);
void* getAPI_Sonar(String subtype, String params);
void* getAPI_IarduinoRTC(String subtype, String params);
@@ -34,21 +30,17 @@ if ((tmpAPI = getAPI_ButtonIn(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_ButtonOut(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_IoTServo(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Mp3(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Telegram(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Timer(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Ads1115(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Aht20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_AnalogAdc(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Bme280(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Bmp280(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Dht1122(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Ds18b20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Emon(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_GY21(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Hdc1080(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Max6675(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Mhz19(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sds011(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_RCswitch(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sht20(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_Sonar(subtype, params)) != nullptr) return tmpAPI;
if ((tmpAPI = getAPI_IarduinoRTC(subtype, params)) != nullptr) return tmpAPI;

View File

@@ -0,0 +1,73 @@
#include "Global.h"
#include "classes/IoTItem.h"
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
class RCswitch : public IoTItem {
private:
int _pinRx; // Выход радио модуля
int _pinTx; // Выход модуля передатчика
public:
RCswitch(String parameters): IoTItem(parameters) {
jsonRead(parameters, "pinRx", _pinRx);
jsonRead(parameters, "pinTx", _pinTx);
_interval = _interval / 1000; // корректируем величину интервала int, теперь он в миллисекундах
if (_pinRx >= 0) {
Serial.printf("Protocol: %d", _pinRx);
mySwitch.enableReceive(digitalPinToInterrupt(_pinRx));
}
if (_pinTx >= 0)
mySwitch.enableTransmit(_pinTx);
}
void doByInterval() {
if (_pinRx >= 0 && mySwitch.available()) {
// Serial.print("Received ");
//Serial.print( mySwitch.getReceivedValue() );
// Serial.print(" / ");
// Serial.print( mySwitch.getReceivedBitlength() );
// Serial.print("bit ");
// Serial.print("Protocol: ");
// Serial.println( mySwitch.getReceivedProtocol() );
value.valD = mySwitch.getReceivedValue();
regEvent(value.valD, "RCswitch");
mySwitch.resetAvailable();
}
}
IoTValue execute(String command, std::vector<IoTValue> &param) {
if (_pinTx >= 0)
if (command == "sendBitStr") { // отправляем строку вида "000000000001010100010001"
if (param.size()) {
mySwitch.send(param[0].valS.c_str());
return {};
}
} else if (command == "sendTriState") { // отправляем строку вида "00000FFF0F0F"
if (param.size()) {
mySwitch.sendTriState(param[0].valS.c_str());
return {};
}
} else if (command == "sendDecimal") { // отправляем строку вида 5393 первым параметром и количество бит чтоб заполнить нулями
if (param.size()) {
mySwitch.send(param[0].valD, param[1].valD);
return {};
}
}
return {};
}
~RCswitch() {};
};
void* getAPI_RCswitch(String subtype, String param) {
if (subtype == F("RCswitch")) {
return new RCswitch(param);
} else {
return nullptr;
}
}

View File

@@ -0,0 +1,43 @@
{
"menuSection": "Сенсоры",
"configItem": [{
"name": "Сканер кнопок 433 MHz",
"num": 31,
"type": "Reading",
"subtype": "RCswitch",
"id": "rsw",
"int": 500,
"pinRx": 12,
"pinTx": 12
}],
"about": {
"authorName": "Serghei Crasnicov",
"authorContact": "https://t.me/Serghei63",
"authorGit": "https://github.com/Serghei63",
"specialThanks": "Valentin Khandriga @Valiuhaaa",
"moduleName": "RCswitch",
"moduleVersion": "1.0",
"moduleDesc": "Позволяет принимать и передавать байт-коды на частоте 433 MHz от и для простых пультов, кнопок, радиореле",
"propInfo": {
"pinRx": "GPIO номер, к которому подключен радио приемник 433 MHz. Если < 0, то приемник выключен",
"pinTx": "GPIO номер, к которому подключен радио передатчик 433 MHz. Если < 0, то передатчик выключен",
"int": "Количество миллисекунд между опросами датчика. 0 - читаем постоянно. (устранение повторений при нажатой кнопке)"
}
},
"defActive": true,
"devices": {
"esp32_4mb": [
"rc-switch @ ^2.6.4"
],
"esp8266_1mb": [
"rc-switch @ ^2.6.4"
],
"esp8266_4mb": [
"rc-switch @ ^2.6.4"
]
}
}