-->
Page 1 of 1

Sending AT command and read (NodeMCU)

PostPosted: Mon Jan 02, 2017 8:42 am
by Xhendos
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:

Re: Sending AT command and read (NodeMCU)

PostPosted: Wed Jan 04, 2017 10:46 pm
by flagtrax
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.