0

Following is my code that i am trying to use it with Arduino Uno with ESP8266 module but my code stucked in setup function why is that.

#include "ESP8266.h"
#include <SoftwareSerial.h>
SoftwareSerial mySerial(12,13);
#define SSID        "abcd"
#define PASSWORD    "87654321"
#define HOST_NAME   "www.baidu.com"
#define HOST_PORT   (80)

ESP8266 wifi(mySerial);

void setup(void)
{
    Serial.begin(9600);
    Serial.print("setup begin\r\n");

    Serial.print("FW Version:");
    Serial.println(wifi.getVersion().c_str());

    if (wifi.setOprToStationSoftAP()) {
        Serial.print("to station + softap ok\r\n");
    } else {
        Serial.print("to station + softap err\r\n");
    }

//    if (wifi.joinAP(SSID, PASSWORD)) {
//        Serial.print("Join AP success\r\n");
//
//        Serial.print("IP:");
//        Serial.println( wifi.getLocalIP().c_str());       
//    } else {
//        Serial.print("Join AP failure\r\n");
//    }
    delay(500);
    if (wifi.disableMUX()) {
        Serial.print("single ok\r\n");
    } else {
        Serial.print("single err\r\n");
    }

    Serial.print("setup end\r\n");

}

void loop(void)
{
    uint8_t buffer[1024] = {0};

    if (wifi.createTCP(HOST_NAME, HOST_PORT)) {
        Serial.print("create tcp ok\r\n");
    } else {
        Serial.print("create tcp err\r\n");
    }

    char *hello = "GET / HTTP/1.1\r\nHost: www.baidu.com\r\nConnection: close\r\n\r\n";
    wifi.send((const uint8_t*)hello, strlen(hello));

    uint32_t len = wifi.recv(buffer, sizeof(buffer), 10000);
    if (len > 0) {
        Serial.print("Received:[");
        for(uint32_t i = 0; i < len; i++) {
            Serial.print((char)buffer[i]);
        }
        Serial.print("]\r\n");
    }

    if (wifi.releaseTCP()) {
        Serial.print("release tcp ok\r\n");
    } else {
        Serial.print("release tcp err\r\n");
    }

    while(1);

}

On Serial Monitor i get the following continuously

setup begin
FW Version:0018000902
to station + softap ok
singl

setup begin FW Version:0018000902 to station + softap ok singl

1

It's always a good idea to put a serial output in the setup of your code.

It seems that your Arduino resets itself.

But why?

I believe the problem would be with too little power for your ESP8266 and Arduino. When the ESP8266 wants to create a network connection, it takes a little more current, possibly leaving your Arduino without enough current to run on itself.

So your Arduino would shut down since the ESP8266 takes up all the current. Creating some kind of bootloop on your Arduino.

Please tell us how you powered the devices and how you connected them. You might try using a separate power supply or a big capacitor on the Arduino's 5V+GND.

6
  • yes i am using separate voltage regulators for both and my other code which is different a little bit works fine thats why i am curious about this code – Muhammad Hassaan Bashir Mar 25 '16 at 9:24
  • and i need to run above code – Muhammad Hassaan Bashir Mar 25 '16 at 9:24
  • I think you're running out of RAM memory, try using a buffer of only 256 bytes and put the printed text in statments with F() like: Serial.print(F("Write something on the Serial Monitor that is stored in FLASH")); – Paul Mar 25 '16 at 10:07
  • yes its the buffer issue thanks but i need more memory because esp module send too much data to arduino when get request has been made it means i need to move towards mega board or due – Muhammad Hassaan Bashir Mar 25 '16 at 10:09
  • Teensy3.2 might be a good choice. That thing has got some serious bang for buck (but is a little more difficult to use). BUT there are other options, you don't have to receive the whole message at once! You can check it in a per-byte fashion. You should ONLY save the information that you actually need! – Paul Mar 25 '16 at 10:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.