So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By Xhendos
#60273 Dear lovely ESP8266 community,

I've bought 1 week ago my first NodeMCU which contains the ESP266 WiFi chip.
I am trying to send a simple command and receive the data from it.

Header file.
Code: Select all#include <Arduino.h>


#ifndef ESP8266LIBRARY_H
#define ESP8266LIBRARY_H


class ESP8266Library
{
    public:
        ESP8266Library(int baud);
        virtual ~ESP8266Library();

        String init();
    protected:
        int _baud;

    private:
};

#endif // ESP8266LIBRARY_H



C++ code
Code: Select all#include "ESP8266Library.h"
#include <Arduino.h>

#define Wifi Serial

ESP8266Library::ESP8266Library(int baud)
{
  _baud = baud;

}

ESP8266Library::~ESP8266Library()
{

}

 String ESP8266Library::init()
 {
  Wifi.begin(_baud);
  Wifi.setTimeout(5000);

  Wifi.println(F("AT"));
  delay(1000);
  String s;
  char c;

  for(int i = 0; i < 10; i++)
  {
    c = Wifi.read();
    s = s + c;

  }


  return s;
}



Main code.
Code: Select all#include <Arduino.h>
#include <ESP8266Library.h>

ESP8266Library wifi(9600);

void setup()
{
  delay(1000);
  String i = wifi.init();
  delay(1000);
  Serial.println(i);
  delay(1000);
}

void loop()
{

}



This all results in the next:
Image

I hope someone could help me out in the right direction :roll:
User avatar
By flagtrax
#60439 Looking at your post, I'm not sure what platform you are working from. One can program the 8266 via the original "AT" command OS, from the Arduino IDE, from the Nodemcu/lua platform, and now I've seen support directly from Windows 10. Being a newbie myself, with a bit of experience, I know it can be a bit confusing. I struggle in different situations due to the fact that my previous experiences are ancient with regard to today's technology. The first think you must understand is what ever platform you are using, you first need to know how your module was/is configured when you received it. For example, the vast majority of generic modules are supplied with the "AT" command OS loaded. If that is the case, you need to find tutorials on how to use the module in that mode. Most have gone beyond that mode to loading 'sketches' via the Arduino IDE or uploading Lua code via ESPlorer IDE.
There are lots of tutorials out there for all this, but a word of caution. Watch out for dated material! This is a fast moving technology, and what was true a few months ago, may not be true today!
And I will pass on what I've been told by several on this great forum....read...read.....read.