Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Josiel Moraes
#28950 I have a TCP server on one machine, I would like to connect several esp8266 network to send data to the server. The problem is create the first esp8266 an AP and then connect the second esp8266 at first, but can not send data.

When I create the A, I need to put the same information (ip gatway) my network for it to be a signal repeater?

Sorry for my English
code below

Server:
#include "ESP8266.h"
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); /* RX:D3, TX:D2 */
#define SSID "casa"
#define PASSWORD "casa@123"
#define NOMEAP "internet"
#define SENHA "123456789"

#define HOST_NAME "192.168.1.4"
#define HOST_PORT (9000)

uint8_t buffer[128] = {0};
uint8_t mux_id;
uint32_t len;

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");
}
if (wifi.enableMUX()) {
Serial.print("multiple ok\r\n");
} else {
Serial.print("multiple err\r\n");
}

if(wifi.setSoftAPParam(NOMEAP, SENHA)){
Serial.print("Criado Ponto\n");
}

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

}

void loop() {

}



Client:
#include "ESP8266.h"
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11);

#define SSID "sen"
#define PASSWORD "123456789"
#define HOST_NAME "192.168.1.4"
#define HOST_PORT (15030)

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");
}

if (wifi.enableMUX()) {
Serial.print("multiple ok\r\n");
} else {
Serial.print("multiple err\r\n");
}


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

void loop(void)
{
uint8_t buffer[128] = {0};
static uint8_t mux_id = 0;

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


char *hello = "Hello, this is client!";
if (wifi.send(mux_id, (const uint8_t*)hello, strlen(hello))) {
Serial.println("send ok");
} else {
Serial.println("send err");
}


if (wifi.releaseTCP(mux_id)) {
Serial.print("release tcp ");
Serial.print(mux_id);
Serial.println(" ok");
} else {
Serial.print("release tcp ");
Serial.print(mux_id);
Serial.println(" err");
}

delay(3000);
mux_id++;
if (mux_id >= 5) {
mux_id = 0;
}
}