Good day all.
I'm trying to make an IoT device with ESP8266-01 connected to an RF transmitter to send data to arduino with RCSwitch library.
I have gotten the ESP-01 to send data through GPIO 2 and i confirmed its transmitting something with an led connected to the data pin of my transmitter. But strangely, the receiver data pin with i connected to arduino pin 7 is always "high" and the serial monitor shows nothing being received.
Please can someone tell me what I've done wrongly and how I can get it working. Thanks. My code is below.
The ESP-01 transmitter code
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
/* Set these to your desired credentials. */
const char *ssid = "My_Home";
const char *password = "password";
long code = 0;
String response_data = "";
ESP8266WebServer server(80);
/* Just a little test message. Go to http://192.168.4.1 in a web browser
* connected to this access point to see it.
*/
void root()
{
send_response("<h1>Welcome Home</h1>");
}
void check_connection()
{
send_response("<h1>000</h1>");
}
void entrance_light_ON()
{
response_data = "<h1>101</h1>";
code = response_data.substring(4,7).toInt();
sendCode(code);
send_response(response_data);
}
void setup()
{
Serial.begin(115200);
delay(1);
//setup transmitter
mySwitch.enableTransmit(2); //transmit through GPIO 2
mySwitch.setPulseLength(180);
Serial.println();
Serial.print("Configuring access point...\n");
/* You can remove the password parameter if you want the AP to be open. */
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
Serial.print("AP IP address: ");
Serial.println(myIP);
server.on("/", root);
server.on("/L_000",check_connection);
//ON commands
server.on("/L_101",entrance_light_ON);
server.begin();
Serial.println("HTTP server started");
}
void loop()
{
server.handleClient();
}
The Receiver Code
#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
Serial.begin(9600);
Serial.println("Started");
mySwitch.enableReceive(7);
}
void loop() {
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();
}
}