Skip to main content
Arduino

Return to Question

Notice removed Authoritative reference needed by Community Bot
Bounty Ended with no winning answer by Community Bot
Tweeted twitter.com/StackArduino/status/971060792488493057
added some parts to the question.
Source Link

ESP8266 is connected to Arduino Uno (2, 3 pins) and a relayrelay's data input to Arduino's pin 1312 and power for relay is provided from another source.

ESP8266 is connected to Arduino Uno (2, 3 pins) and a relay to Arduino's pin 13.

ESP8266 is connected to Arduino Uno (2, 3 pins) and a relay's data input to Arduino's pin 12 and power for relay is provided from another source.

Notice added Authoritative reference needed by Sachith Muhandiram
Bounty Started worth 50 reputation by Sachith Muhandiram
Format code, fix typos
Source Link
per1234
  • 4.3k
  • 2
  • 23
  • 43

ESP8266 disconnectdisconnects after few hours

My system looks like this.:

ESP8266 is connected to Arduino-Uno Uno (2,3 3 pins) and a Relayrelay to Arduino's pin 13.

Arduino gets data from server and switchswitches on/off relay according to that signal. This system works perfectly for few hours and then suddenly crashes. In my wifiWiFi console I have:

I have read this arduinoArduino question, but circuit diagram similar to that one. I get power from my PC to run Arduino.

This is my arduinoArduino code :

#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2,3); // RX, TX
#endif
char ssid[] = "RPi"; // your network SSID (name)
char pass[] = "raspberry"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "192.168.50.1";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds
int testLED = 12;
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
 pinMode(testLED, OUTPUT);
 // initialize serial for debugging
 Serial.begin(9600);
 // initialize serial for ESP module
 Serial1.begin(9600);
 // initialize ESP module
 WiFi.init(&Serial1);
 // check for the presence of the shield
 if (WiFi.status() == WL_NO_SHIELD) {
 Serial.println("WiFi shield not present");
 // don't continue
 while (true);
 }
 // attempt to connect to WiFi network
 while ( status != WL_CONNECTED) {
 Serial.print("Attempting to connect to WPA SSID: ");
 Serial.println(ssid);
 // Connect to WPA/WPA2 network
 status = WiFi.begin(ssid, pass);
 }
 Serial.println("You're connected to the network");
 
 //printWifiStatus();
}
void loop()
{
 // if there's incoming data from the net connection send it out the serial port
 // this is for debugging purposes only
 while (client.available()) {
 char c = client.read();
//code to run relay
 if(c == '#')
 {
 while(client.available() == 0) { } // Do nothing while we wait for the next value
 // reading the second charactor
 c = client.read();
 if(c == '1'){
 Serial.println("On");
 digitalWrite(testLED, HIGH);
 delay(600000);
 
 }
 else if(c == '0'){
 Serial.println("Off");
 digitalWrite(testLED, LOW);
 delay(600000);
 
 
 } //end of C cheking if-else 
 
 } //end of first charactor # if
//end of replay code
 
 }
 // if 10 seconds have passed since your last connection,
 // then connect again and send data
 if (millis() - lastConnectionTime > postingInterval) {
 httpRequest();
 }
}
// this method makes a HTTP connection to the server
void httpRequest()
{
 Serial.println();
 
 // close any connection before send a new request
 // this will free the socket on the WiFi shield
 client.stop();
 // if there's a successful connection
 if (client.connect(server, 80)) {
 Serial.println("Connecting...");
 
 // send the HTTP PUT request
 client.println(F("GET /simple.txt HTTP/1.1"));
 client.println(F("Host: localhost"));
 client.println("Connection: close");
 client.println();
 // note the time that the connection was made
 lastConnectionTime = millis();
 }
 else {
 
 WiFi.begin(ssid, pass);
 Serial.println("Reconnecting again");
 }
}
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2, 3); // RX, TX
#endif
char ssid[] = "RPi"; // your network SSID (name)
char pass[] = "raspberry"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "192.168.50.1";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds
int testLED = 12;
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
 pinMode(testLED, OUTPUT);
 // initialize serial for debugging
 Serial.begin(9600);
 // initialize serial for ESP module
 Serial1.begin(9600);
 // initialize ESP module
 WiFi.init(&Serial1);
 // check for the presence of the shield
 if (WiFi.status() == WL_NO_SHIELD) {
 Serial.println("WiFi shield not present");
 // don't continue
 while (true);
 }
 // attempt to connect to WiFi network
 while ( status != WL_CONNECTED) {
 Serial.print("Attempting to connect to WPA SSID: ");
 Serial.println(ssid);
 // Connect to WPA/WPA2 network
 status = WiFi.begin(ssid, pass);
 }
 Serial.println("You're connected to the network");
 //printWifiStatus();
}
void loop()
{
 // if there's incoming data from the net connection send it out the serial port
 // this is for debugging purposes only
 while (client.available()) {
 char c = client.read();
 //code to run relay
 if (c == '#')
 {
 while (client.available() == 0) { } // Do nothing while we wait for the next value
 // reading the second charactor
 c = client.read();
 if (c == '1') {
 Serial.println("On");
 digitalWrite(testLED, HIGH);
 delay(600000);
 }
 else if (c == '0') {
 Serial.println("Off");
 digitalWrite(testLED, LOW);
 delay(600000);
 } //end of C cheking if-else
 } //end of first charactor # if
 //end of replay code
 }
 // if 10 seconds have passed since your last connection,
 // then connect again and send data
 if (millis() - lastConnectionTime > postingInterval) {
 httpRequest();
 }
}
// this method makes a HTTP connection to the server
void httpRequest()
{
 Serial.println();
 // close any connection before send a new request
 // this will free the socket on the WiFi shield
 client.stop();
 // if there's a successful connection
 if (client.connect(server, 80)) {
 Serial.println("Connecting...");
 // send the HTTP PUT request
 client.println(F("GET /simple.txt HTTP/1.1"));
 client.println(F("Host: localhost"));
 client.println("Connection: close");
 client.println();
 // note the time that the connection was made
 lastConnectionTime = millis();
 }
 else {
 WiFi.begin(ssid, pass);
 Serial.println("Reconnecting again");
 }
}

ESP8266 disconnect after few hours

My system looks like this.

ESP8266 is connected to Arduino-Uno (2,3 pins) and a Relay to Arduino's pin 13.

Arduino gets data from server and switch on/off relay according to that signal. This system works perfectly for few hours and then suddenly crashes. In my wifi console I have

I have read this arduino question, but circuit diagram similar to that one. I get power from my PC to run Arduino.

This is my arduino code :

#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2,3); // RX, TX
#endif
char ssid[] = "RPi"; // your network SSID (name)
char pass[] = "raspberry"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "192.168.50.1";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds
int testLED = 12;
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
 pinMode(testLED, OUTPUT);
 // initialize serial for debugging
 Serial.begin(9600);
 // initialize serial for ESP module
 Serial1.begin(9600);
 // initialize ESP module
 WiFi.init(&Serial1);
 // check for the presence of the shield
 if (WiFi.status() == WL_NO_SHIELD) {
 Serial.println("WiFi shield not present");
 // don't continue
 while (true);
 }
 // attempt to connect to WiFi network
 while ( status != WL_CONNECTED) {
 Serial.print("Attempting to connect to WPA SSID: ");
 Serial.println(ssid);
 // Connect to WPA/WPA2 network
 status = WiFi.begin(ssid, pass);
 }
 Serial.println("You're connected to the network");
 
 //printWifiStatus();
}
void loop()
{
 // if there's incoming data from the net connection send it out the serial port
 // this is for debugging purposes only
 while (client.available()) {
 char c = client.read();
//code to run relay
 if(c == '#')
 {
 while(client.available() == 0) { } // Do nothing while we wait for the next value
 // reading the second charactor
 c = client.read();
 if(c == '1'){
 Serial.println("On");
 digitalWrite(testLED, HIGH);
 delay(600000);
 
 }
 else if(c == '0'){
 Serial.println("Off");
 digitalWrite(testLED, LOW);
 delay(600000);
 
 
 } //end of C cheking if-else 
 
 } //end of first charactor # if
//end of replay code
 
 }
 // if 10 seconds have passed since your last connection,
 // then connect again and send data
 if (millis() - lastConnectionTime > postingInterval) {
 httpRequest();
 }
}
// this method makes a HTTP connection to the server
void httpRequest()
{
 Serial.println();
 
 // close any connection before send a new request
 // this will free the socket on the WiFi shield
 client.stop();
 // if there's a successful connection
 if (client.connect(server, 80)) {
 Serial.println("Connecting...");
 
 // send the HTTP PUT request
 client.println(F("GET /simple.txt HTTP/1.1"));
 client.println(F("Host: localhost"));
 client.println("Connection: close");
 client.println();
 // note the time that the connection was made
 lastConnectionTime = millis();
 }
 else {
 
 WiFi.begin(ssid, pass);
 Serial.println("Reconnecting again");
 }
}

ESP8266 disconnects after few hours

My system looks like this:

ESP8266 is connected to Arduino Uno (2, 3 pins) and a relay to Arduino's pin 13.

Arduino gets data from server and switches on/off relay according to that signal. This system works perfectly for few hours and then suddenly crashes. In my WiFi console I have:

I have read this Arduino question, but circuit diagram similar to that one. I get power from my PC to run Arduino.

This is my Arduino code :

#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2, 3); // RX, TX
#endif
char ssid[] = "RPi"; // your network SSID (name)
char pass[] = "raspberry"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "192.168.50.1";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds
int testLED = 12;
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
 pinMode(testLED, OUTPUT);
 // initialize serial for debugging
 Serial.begin(9600);
 // initialize serial for ESP module
 Serial1.begin(9600);
 // initialize ESP module
 WiFi.init(&Serial1);
 // check for the presence of the shield
 if (WiFi.status() == WL_NO_SHIELD) {
 Serial.println("WiFi shield not present");
 // don't continue
 while (true);
 }
 // attempt to connect to WiFi network
 while ( status != WL_CONNECTED) {
 Serial.print("Attempting to connect to WPA SSID: ");
 Serial.println(ssid);
 // Connect to WPA/WPA2 network
 status = WiFi.begin(ssid, pass);
 }
 Serial.println("You're connected to the network");
 //printWifiStatus();
}
void loop()
{
 // if there's incoming data from the net connection send it out the serial port
 // this is for debugging purposes only
 while (client.available()) {
 char c = client.read();
 //code to run relay
 if (c == '#')
 {
 while (client.available() == 0) { } // Do nothing while we wait for the next value
 // reading the second charactor
 c = client.read();
 if (c == '1') {
 Serial.println("On");
 digitalWrite(testLED, HIGH);
 delay(600000);
 }
 else if (c == '0') {
 Serial.println("Off");
 digitalWrite(testLED, LOW);
 delay(600000);
 } //end of C cheking if-else
 } //end of first charactor # if
 //end of replay code
 }
 // if 10 seconds have passed since your last connection,
 // then connect again and send data
 if (millis() - lastConnectionTime > postingInterval) {
 httpRequest();
 }
}
// this method makes a HTTP connection to the server
void httpRequest()
{
 Serial.println();
 // close any connection before send a new request
 // this will free the socket on the WiFi shield
 client.stop();
 // if there's a successful connection
 if (client.connect(server, 80)) {
 Serial.println("Connecting...");
 // send the HTTP PUT request
 client.println(F("GET /simple.txt HTTP/1.1"));
 client.println(F("Host: localhost"));
 client.println("Connection: close");
 client.println();
 // note the time that the connection was made
 lastConnectionTime = millis();
 }
 else {
 WiFi.begin(ssid, pass);
 Serial.println("Reconnecting again");
 }
}
Source Link

ESP8266 disconnect after few hours

My system looks like this.

ESP8266 is connected to Arduino-Uno (2,3 pins) and a Relay to Arduino's pin 13.

Arduino gets data from server and switch on/off relay according to that signal. This system works perfectly for few hours and then suddenly crashes. In my wifi console I have

wlan0: STA 2c:3a:e8:4e:bf:70 WPA: pairwise key handshake completed (RSN) wlan0: STA 2c:3a:e8:4e:bf:70 IEEE 802.11: disassociated wlan0: AP-STA-DISCONNECTED 2c:3a:e8:4e:bf:70 wlan0: STA 2c:3a:e8:4e:bf:70 IEEE 802.11: disassociated wlan0: STA 2c:3a:e8:4e:bf:70 IEEE 802.11: associated wlan0: STA 2c:3a:e8:4e:bf:70 IEEE 802.11: disassociated wlan0: STA 2c:3a:e8:4e:bf:70 IEEE 802.11: disassociated wlan0: STA 2c:3a:e8:4e:bf:70 IEEE 802.11: associated wlan0: AP-STA-CONNECTED 2c:3a:e8:4e:bf:70

I have read this arduino question, but circuit diagram similar to that one. I get power from my PC to run Arduino.

This is my arduino code :

#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2,3); // RX, TX
#endif
char ssid[] = "RPi"; // your network SSID (name)
char pass[] = "raspberry"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "192.168.50.1";
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds
int testLED = 12;
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
 pinMode(testLED, OUTPUT);
 // initialize serial for debugging
 Serial.begin(9600);
 // initialize serial for ESP module
 Serial1.begin(9600);
 // initialize ESP module
 WiFi.init(&Serial1);
 // check for the presence of the shield
 if (WiFi.status() == WL_NO_SHIELD) {
 Serial.println("WiFi shield not present");
 // don't continue
 while (true);
 }
 // attempt to connect to WiFi network
 while ( status != WL_CONNECTED) {
 Serial.print("Attempting to connect to WPA SSID: ");
 Serial.println(ssid);
 // Connect to WPA/WPA2 network
 status = WiFi.begin(ssid, pass);
 }
 Serial.println("You're connected to the network");
 
 //printWifiStatus();
}
void loop()
{
 // if there's incoming data from the net connection send it out the serial port
 // this is for debugging purposes only
 while (client.available()) {
 char c = client.read();
//code to run relay
 if(c == '#')
 {
 while(client.available() == 0) { } // Do nothing while we wait for the next value
 // reading the second charactor
 c = client.read();
 if(c == '1'){
 Serial.println("On");
 digitalWrite(testLED, HIGH);
 delay(600000);
 
 }
 else if(c == '0'){
 Serial.println("Off");
 digitalWrite(testLED, LOW);
 delay(600000);
 
 
 } //end of C cheking if-else 
 
 } //end of first charactor # if
//end of replay code
 
 }
 // if 10 seconds have passed since your last connection,
 // then connect again and send data
 if (millis() - lastConnectionTime > postingInterval) {
 httpRequest();
 }
}
// this method makes a HTTP connection to the server
void httpRequest()
{
 Serial.println();
 
 // close any connection before send a new request
 // this will free the socket on the WiFi shield
 client.stop();
 // if there's a successful connection
 if (client.connect(server, 80)) {
 Serial.println("Connecting...");
 
 // send the HTTP PUT request
 client.println(F("GET /simple.txt HTTP/1.1"));
 client.println(F("Host: localhost"));
 client.println("Connection: close");
 client.println();
 // note the time that the connection was made
 lastConnectionTime = millis();
 }
 else {
 
 WiFi.begin(ssid, pass);
 Serial.println("Reconnecting again");
 }
}
lang-cpp

AltStyle によって変換されたページ (->オリジナル) /