Имеется люстра, управляемая радио-пультом на 315Mhz. Беру Arduino с RF-ресивером, читаю через библиотеку RCSwitch код с четырёх кнопок пульта, получаю:
A Received 1559811 / 24bit Protocol: 1
B Received 1559820 / 24bit Protocol: 1
C Received 1559856 / 24bit Protocol: 1
D Received 1560000 / 24bit Protocol: 1
Пытаюсь, воспроизвести эти же коды, например так:
mySwitch.send(1560000, 24);
Не работает... Другие коды так же. Т.е. сигнал уходит -- на втором ресивере проверяю, приходит точно такой же код как и от пульта, но люстра на него не реагирует никак.
Может кто сталкивался, подскажите куда копать?
Вот как выглядит пульт с силовым блоком:

Скетч, которым пользовалсяПоказать
Код: Выделить всё
//#include <VirtualWire.h>
//#include <EasyTransferVirtualWire.h>
#include <RCSwitch.h>
#include <EEPROM.h> //Needed to access the eeprom read write functions
#define PIN_LED 13
#define PIN_LED_T 13
//#define PIN_DHT 3
#define PIN_RF 6
#define RF_SEND_COUNTER 3 // number of packets to send with transmission
int sent_pir=0;
int led_status=0;
unsigned int unique_device_id = 0;
int old_status=0;
int delay_value=1;
int allow_temp=0;
long int timeCheckedTemp=10000000;
//long int timeCheckedHum=10000000;
long int timesentTemp=0;
//long int timesentHum=0;
long int timeChangedLed=0;
unsigned int last_packet_id = 0;
unsigned long last_rc_value = 0;
char http_buf[80];
unsigned int uptime = 0;
unsigned int rc_received = 0;
unsigned int old_uptime = 0;
String inData;
RCSwitch mySwitch = RCSwitch();
/*
//create object
EasyTransferVirtualWire ET;
struct SEND_DATA_STRUCTURE{
//put your variable definitions here for the data you want to send
//THIS MUST BE EXACTLY THE SAME ON THE OTHER ARDUINO
//Struct can'e be bigger then 26 bytes for VirtualWire version
unsigned int device_id;
unsigned int destination_id;
unsigned int packet_id;
byte command;
int data;
};
//give a name to the group of data
SEND_DATA_STRUCTURE mydata;
*/
//This function will write a 2 byte integer to the eeprom at the specified address and address + 1
void EEPROMWriteInt(int p_address, unsigned int p_value)
{
byte lowByte = ((p_value >> 0) & 0xFF);
byte highByte = ((p_value >> 8) & 0xFF);
EEPROM.write(p_address, lowByte);
EEPROM.write(p_address + 1, highByte);
}
//This function will read a 2 byte integer from the eeprom at the specified address and address + 1
unsigned int EEPROMReadInt(int p_address)
{
byte lowByte = EEPROM.read(p_address);
byte highByte = EEPROM.read(p_address + 1);
return ((lowByte << 0) & 0xFF) + ((highByte << 8) & 0xFF00);
}
void sendHTTPRequest() {
Serial.println(http_buf);
}
void blinking(int count) {
for(int i=0;i<count;i++) {
digitalWrite(PIN_LED, HIGH);
delay(200);
digitalWrite(PIN_LED, LOW);
delay(200);
}
}
/*
void sendRFData() {
Serial.print("Transmitting packets ... ");
for(int i=0;i<RF_SEND_COUNTER;i++) {
if (i>0) {
delay(200);
}
digitalWrite(PIN_LED_T, HIGH);
ET.sendData();
digitalWrite(PIN_LED_T, LOW);
}
Serial.println("DONE");
}
void gotRFData() {
Serial.print("P:");
Serial.print(mydata.packet_id);
Serial.print(";F:");
Serial.print(mydata.device_id);
Serial.print(";T:");
Serial.print(mydata.destination_id);
Serial.print(";C:");
Serial.print(mydata.command);
Serial.print(";D:");
Serial.print(mydata.data);
Serial.println(";");
sprintf(http_buf, "GET /objects/?script=easyRF&did=%d&dest=%d&pid=%d&c=%d&d=%d HTTP/1.0", (int)mydata.device_id, (int)mydata.destination_id, (int)mydata.packet_id, (int)mydata.command, (int)mydata.data);
sendHTTPRequest();
digitalWrite(PIN_LED_T, HIGH);
delay(200);
digitalWrite(PIN_LED_T, LOW);
}
*/
void setup()
{
pinMode(PIN_LED, OUTPUT);
pinMode(PIN_LED_T, OUTPUT);
Serial.begin(9600);
//sensors.begin();
/*
ET.begin(details(mydata));
// Initialise the IO and ISR
//vw_set_rx_pin(PIN_RCV);
vw_set_tx_pin(PIN_RF);
vw_setup(2000); // Bits per sec
*/
randomSeed(analogRead(0));
mySwitch.enableReceive(0); // Receiver on inerrupt 0 => that is pin #2
mySwitch.enableTransmit(PIN_RF);
mySwitch.setPulseLength(320);
mySwitch.setProtocol(1);
mySwitch.setRepeatTransmit(15);
// Device ID
Serial.print("Getting Device ID... ");
unique_device_id=EEPROMReadInt(0);
if (unique_device_id<10000 || unique_device_id>60000) {
Serial.print("N/A, updating... ");
unique_device_id=random(10000, 60000);
EEPROMWriteInt(0, unique_device_id);
}
Serial.println(unique_device_id);
/*
mydata.device_id = 0;
mydata.destination_id = 0;
*/
}
void loop()
{
uptime=round(millis()/1000);
if (uptime!=old_uptime) {
Serial.print("Uptime: ");
Serial.println(uptime);
old_uptime=uptime;
timesentTemp+=delay_value;
timeCheckedTemp+=delay_value;
timeChangedLed+=delay_value;
}
if (Serial.available()) {
char c=Serial.read();
if (c == '\n' || c == ';')
{
Serial.println(inData);
if (inData.equals("blink")) {
Serial.println("BLINKING!");
}
if (inData.startsWith("rcon")) {
Serial.print("RCSwitch on: ");
inData.replace("rcon","");
int firstSep = inData.indexOf(':');
String firstPart=inData.substring(0, firstSep);
String secondPart=inData.substring(firstSep+1);
Serial.print('(');
Serial.print(firstPart);
Serial.print('/');
Serial.print(secondPart);
Serial.println(')');
//The first parameter represents the setting of the first 5 DIP switches.
//The second parameter represents the setting of the last 5 DIP switches.
//mySwitch.switchOn("11001", "01010");
char charBuf1[firstPart.length()+1];
char charBuf2[secondPart.length()+1];
firstPart.toCharArray(charBuf1, firstPart.length()+1);
secondPart.toCharArray(charBuf2, secondPart.length()+1);
mySwitch.switchOn(charBuf1, charBuf2);
//mySwitch.switchOn("00100","00100");
}
if (inData.startsWith("rcoff")) {
Serial.print("RCSwitch off: ");
inData.replace("rcoff","");
int firstSep = inData.indexOf(':');
String firstPart=inData.substring(0, firstSep);
String secondPart=inData.substring(firstSep+1);
Serial.print('(');
Serial.print(firstPart);
Serial.print('/');
Serial.print(secondPart);
Serial.println(')');
char charBuf1[firstPart.length()+1];
char charBuf2[secondPart.length()+1];
firstPart.toCharArray(charBuf1, firstPart.length()+1);
secondPart.toCharArray(charBuf2, secondPart.length()+1);
mySwitch.switchOff(charBuf1, charBuf2);
//mySwitch.switchOff("00100","00100");
}
if (inData.startsWith("rcsend")) {
Serial.print("RCSwitch send: ");
inData.replace("rcsend","");
Serial.print('(');
Serial.print(inData);
Serial.println(')');
mySwitch.send(inData.toInt(), 24);
}
/*
if (inData.startsWith("sendrf")) {
Serial.print("Send RF: ");
inData.replace("sendrf","");
unsigned int destination_id=0;
byte command=0;
int data=0;
int splitPosition;
String paramString;
splitPosition=inData.indexOf('-');
if(splitPosition != -1) {
paramString=inData.substring(0,splitPosition);
destination_id=paramString.toInt();
inData=inData.substring(splitPosition+1,inData.length());
splitPosition=inData.indexOf('-');
if(splitPosition != -1) {
paramString=inData.substring(0,splitPosition);
command=paramString.toInt();
inData=inData.substring(splitPosition+1,inData.length());
data=inData.toInt();
}
}
mydata.packet_id = random(65535);
mydata.command = command;
mydata.data = data;
mydata.destination_id = destination_id;
sendRFData();
}
*/
inData="";
Serial.flush();
} else {
inData += (c);
}
}
/*
if(ET.receiveData())
{
digitalWrite(PIN_LED, HIGH);
if (last_packet_id!=(int)mydata.packet_id) {
gotRFData();
last_packet_id=(int)mydata.packet_id;
}
digitalWrite(PIN_LED, LOW);
}
*/
if (mySwitch.available()) {
//Serial.println("Got something!");
int value = mySwitch.getReceivedValue();
if (value == 0) {
Serial.print("Unknown encoding");
} else {
unsigned long rc_value=mySwitch.getReceivedValue();
if ((last_rc_value!=rc_value) || ((uptime-rc_received)>1)) {
last_rc_value=rc_value;
rc_received=uptime;
Serial.print("RCSwitch:");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
Serial.print("GET /objects/?script=RCSwitch&rcswitch=");
Serial.print(mySwitch.getReceivedValue());
Serial.println(" HTTP/1.0");
}
//sendHTTPRequest();
}
mySwitch.resetAvailable();
}
if (timeChangedLed>=2) {
timeChangedLed=0;
if (led_status==1) {
led_status=0;
digitalWrite(PIN_LED, LOW);
} else {
led_status=1;
digitalWrite(PIN_LED, HIGH);
}
}
}