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.
#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
#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.
#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:
I hope someone could help me out in the right direction