bportaluri / WiFiEsp

Arduino WiFi library for ESP8266 modules
GNU General Public License v3.0
552 stars 209 forks source link

The board is constantly rebooting #160

Open alkoval opened 6 years ago

alkoval commented 6 years ago

I use arduino mega and esp8266. Tested with different firmware versions ESP NONON:

  1. ESP8266_NONOS_SDK-2.0.0;
  2. ESP8266_NONOS_SDK-2.2.1.

Scheme https://imgur.com/a/Ohb3fRz

Sketch:

#include "WiFiEsp.h"

char ssid[] = "RTK-710055";            // your network SSID (name)
char pass[] = "ELTX5C40803SE128";        // your network password

int status = WL_IDLE_STATUS;     // the Wifi radio's status

char server[] = "arduino.cc";

unsigned long lastConnectionTime = 0;         // last time you connected to the server, in milliseconds
const unsigned long postingInterval = 10000L; // delay between updates, in milliseconds

// Initialize the Ethernet client object
WiFiEspClient client;

void setup()
{
  // 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();
    Serial.write(c);
  }

  // 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 /asciilogo.txt HTTP/1.1"));
    client.println(F("Host: arduino.cc"));
    client.println("Connection: close");
    client.println();

    // note the time that the connection was made
    lastConnectionTime = millis();
  }
  else {
    // if you couldn't make a connection
    Serial.println("Connection failed");
  }
}

void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength
  long rssi = WiFi.RSSI();
  Serial.print("Signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}

After loading the sketch, the board constantly reboots. If you work only in the AT command mode, then there are no problems with the patch. Faced with a similar or know the solution?

JAndrassy commented 6 years ago

there is no other mode. only with AT commands firmware

alkoval commented 6 years ago

there is no other mode. only with AT commands firmware

The library(WiFiEsp) is designed to connect arduino to the Internet. But even such a sketch causes a constant reboot.

#include <WiFiEsp.h>
#include <SPI.h>

void setup() {
  Serial.begin(9600);
  Serial.println("Step 0");

  Serial1.begin(9600);
  Serial.println("Step 1");

  WiFi.init(Serial1);
  Serial.println("Step 2");
}

void loop() {
}

I use ESP8266_NONOS_SDK-2.2.1.

JAndrassy commented 6 years ago

use AT firmware in esp8266 and WiFiEsp in connected Arduino. SDK is not a firmware.

alkoval commented 6 years ago

use AT firmware in esp8266 and WiFiEsp in connected Arduino. SDK is not a firmware.

Could you recommend an example for creating exchange via mqtt using arduino board (mega 2560) and esp8266?

JAndrassy commented 6 years ago

PubSubClient library over WiFiEsp https://github.com/knolleary/pubsubclient

tbitu commented 5 years ago

Same issue. As soon as I initialize WiFiEspClient the Uno goes haywire and starts bootlooping. Tried with any number of power supplies as I couldn't imagine what else would cause such a problem, but everything works as long as I don't initialize WiFiEspClient.