Class, I'm using the two codes below to transfer a simple String between an ESP01S(TX) and a NODEMCU(RX).
Connected to the TX I have a 433Mhz receiver and I have a common garage door remote control on hand. TX and RX are on the same contact array sharing the same VCC (3.3 volts) and the same GND.
RX will never send data to TX, it will only receive data, so I only have 1 wire connecting the two. I know that a button on the 433Mhz control generates the code: 140160869
Then I copy it to the codereceiver String.
And I did an IF.
If codereceiver is equal to 140160869 datatx will be equal to "A" and will be sent to the RX through the SoftwareSerial link.
ERROR = DOES NOT SEND.
If I comment on the IF and just inform that datatx is equal to "A", without the IF condition, then YES, IT WORKS, I receive A in the serial RX monitor.
If I comment on serial link communication, disable it in TX, and just use common Serial.print, then YES, the IF condition works in the TX itself, that is, I press the 433Mhz control button and see A on the TX serial monitor .
TX:
#include <RCSwitch.h>
#include <SoftwareSerial.h>
SoftwareSerial link(2, 3); //ESP01S
RCSwitch mySwitch = RCSwitch();
String codereceiver,dadostx;
void setup() {
delay(2000);
// Serial.begin(115200);
link.begin(9600);
mySwitch.enableReceive(2);
}
void loop() {
if(mySwitch.available()) {
//Serial.println(mySwitch.getReceivedValue());
codereceiver = mySwitch.getReceivedValue();
mySwitch.resetAvailable();
}
//Serial.print("CodeReceiver: ");Serial.println(codereceiver);
//codereceiver = String(code).c_str();
//codereceiver.toCharArray(newchar, codereceiver.length() + 1);
if(codereceiver == "140160869") {
dadostx = "A";
link.println(dadostx); //Send to RX using SoftwareSerial
delay(500);
codereceiver = "";
dadostx = "";
}
}
RX:
#include <SoftwareSerial.h>
SoftwareSerial link(4, 9); // Nodemcu12E 1.0
String codereceiver;
const int led = 5;
void setup() {
Serial.begin(115200);
link.begin(9600);
pinMode(led, OUTPUT);
}
void loop() {
if (link.available() > 0) {
digitalWrite(led, HIGH);
codereceiver = link.readStringUntil('\n');
Serial.println(codereceiver);
} else {
digitalWrite(led, LOW);
}
}
Why is this 'confusion' occurring ? Anybody know ?
Thanks