-->
Page 1 of 4

ESP8266 just to send and receive data to another ESP8266

PostPosted: Fri Mar 31, 2017 12:11 pm
by Diogo Martins
Hello people!

I'm studying about this module for a while but i've not found a similar application to the one I want to do.
I want to use a MCU, not Arduino, to receive some data and send through ESP8266 via WIFI to another ESP8266 via WIFI.
Both boards will have a MCU and an ESP8266.
My question is, how do I do this without having to program a custom firmware to ESP8266? I want to use it as it comes.
What's the peripheral(I2C, UART, SPI) that I may use for it?

Thanks.

Re: ESP8266 just to send and receive data to another ESP8266

PostPosted: Mon Apr 03, 2017 7:17 am
by urbanze
sending data with 2 or more ESP? do with wireless (or no), use server and client library to simple send data, see this example:

esp1 connect and send data to esp2 server.


Sending data:

Code: Select all#include <ESP8266WiFi.h>

WiFiClient cl;

void setup()
{
   pinMode(LED_BUILTIN, OUTPUT);
   WiFi.mode(WIFI_STA);
   reconnect();
}


void loop()
{
   while (WiFi.status() == WL_CONNECTED)
   {
      cl.println("1");//Sending "1" to another esp8266
      digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
      delay(2000);
   }

   reconnect();
}

void reconnect()
{
   WiFi.disconnect();

   while (WiFi.status() != WL_CONNECTED)
   {
      digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
      WiFi.begin("xxxxxx", "xxxxxx");
      delay(5000);
   }
   
   cl.connect("192.168.4.1", 23);
}


Receiving data:

Code: Select all#include <ESP8266WiFi.h>

WiFiServer sv(23);
WiFiClient cl;

void setup()
{
   WiFi.mode(WIFI_AP);
   WiFi.softAP("xxxxx", "xxxxx");

   pinMode(LED_BUILTIN, OUTPUT);


   sv.begin();


   delay(25);
}


void loop()
{   
   while (cl.connected())
   {
      String req = cl.readStringUntil('\r');

      if (req == "1")
      {
         //do anything
      }

      if (req == "2")
      {
         //do anything
      }

      if (req == "3")
      {
         //do anything
      }

      if (req == "4")
      {
         //do anything
      }

   }

   recreate();
}



void recreate()
{
   while (sv.hasClient() == 0)
   {
      digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
      delay(50);
   }

   digitalWrite(LED_BUILTIN, 1);
   cl = sv.available();
}

Re: ESP8266 just to send and receive data to another ESP8266

PostPosted: Mon Apr 03, 2017 8:46 am
by Diogo Martins
Thanks, but I don't want to program a custom firmware.
Also, I want to use an external MCU to control the ESP8266.
Is that possible?

Re: ESP8266 just to send and receive data to another ESP8266

PostPosted: Mon Apr 03, 2017 8:52 am
by Diogo Martins
Sorry, is it an Arduino code?
I don't want to use Arduino in my project, I'm already using a STM32 mcu.