My problem is with the sending ESP. I can receive signals from the sensors and view them with serial monitor. I just don't know how to convert them to usable data so I can use an IF statement to determine what to do with it.
I have no problems with the udp code. My need is really just about analyzing the 433 signals.
Here is my code:
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiUDP.h>
#include <RCSwitch.h>
ESP8266WiFiMulti wifiMulti;
WiFiUDP Udp;
RCSwitch mySwitch = RCSwitch();
/*
PINS:
0=Data Rx from RxB1
RX & TX to programmer and serial monitor
*/
void door() {
Udp.beginPacket(IPAddress (192,168,1,26), 4500);
Udp.write("doorsensor");
Udp.endPacket();
delay(500);
}
void window() {
Udp.beginPacket(IPAddress (192,168,1,26), 4500);
Udp.write("windowsensor");
Udp.endPacket();
delay(500);
}
void setupWifi() {
WiFi.mode(WIFI_STA);
wifiMulti.addAP("SSID_1", "PW_1");
wifiMulti.addAP("SSID_2", "PW_2");
wifiMulti.addAP("SSID_3", "PW_3");
wifiMulti.addAP("SSID_4", "PW_4");
Serial.println("Connecting Wifi...");
while (wifiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("Connected to SSID: ");
Serial.println(WiFi.SSID());
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}
void setup() {
Serial.begin(115200);
setupWifi();
Udp.begin(4500);
mySwitch.enableReceive(0);
}
void loop() {
if (wifiMulti.run() != WL_CONNECTED) {
Serial.println("WiFi not connected!");
delay(1000);
setupWifi();
}
if (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() );
mySwitch.resetAvailable();
}
//create an if statement for each sensor in the house
If(mySwitch.getReceviedValue() == 3372380) {
window(); //or door depending on sensor type
}
}
This code produces the following results in the serial monitor as expected:
Connecting Wifi....................
WiFi connected
Connected to SSID:
SSID_1
IP address:
192.168.1.3
Received 3372380 / 24bit Protocol: 1
You can see I am using the RC_Switch library. I am most interested in the "mySwitch.getReceviedValue()" since it is unique for each sensor. However, I don't know how to process it in the loop. I've tried:
If(mySwitch.getReceviedValue() == 3372380) {
window(); //or door() depending on sensor type
}
But it does nothing. I am hoping to use a series of if statements (one for each sensor) to determine whether to call window() or door() functions.
Any help is greatly appreciated. I assume my problem is in the variable type, but I don't know how to correct it. Thanks.