ESP8266 WIFI SoC! General News
Come follow us on Google+ Page

User avatar
By marck spencer
#62357 Hello, i have a problem when send my code for my rf relay to turn on. After send to turn on it make turn off.
I'm new with this.
I need help :

#include <ESP8266WiFi.h>
#include <RCSwitch.h>
const char* ssid = "...";
const char* password = "...";

WiFiServer server(1337);

WiFiClient client;
RCSwitch mySwitch = RCSwitch();

void printWiFiStatus();

void setup(void) {
mySwitch.enableTransmit(2);
delay(1000);
// mySwitch.setPulseLength(360);
// mySwitch.setRepeatTransmit(15);
Serial.begin(115200);
WiFi.begin(ssid, password);

// Start TCP server.
server.begin();
}

void loop(void) {
// Check if module is still connected to WiFi.
if (WiFi.status() != WL_CONNECTED) {
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
// Print the new IP to Serial.
printWiFiStatus();
}

client = server.available();

if (client) {
Serial.println("Client connected.");
char command=' ';
while (client.connected()) {
if (client.available()) {
command = client.read();
if (command == 'H') {
Serial.println("LED is now on.");
mySwitch.send(5393, 24);
delay(2000);
client.write("teste1");
}else if (command == 'L') {
Serial.println("LED is now off.");
mySwitch.send(5396, 24);
delay(2000);
client.write("teste2");
}
}
}
Serial.println("Client disconnected.");
client.stop();
}
}

void printWiFiStatus() {
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
User avatar
By rudy
#62375 You have posted to NEWS. You would probably get more responses if you post to the Arduino forum.