So in brief my question is how to make two ESP8266 communicate over WiFi (TCP socket)?
If you need code, or additional information, I can give some.
Thank you in advance!!!
Explore... Chat... Share...
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <WiFiServer.h>
#include <Wire.h>
const char *ssid = "SumoRobot";
const char *password = "ZumoShield";
WiFiServer server(80);
void setup() {
Serial.begin(115200);
pinMode(BUILTIN_LED, OUTPUT);
digitalWrite(BUILTIN_LED,LOW);
Wire.begin();
WiFi.softAP(ssid, password);
IPAddress myIP = WiFi.softAPIP();
server.begin();
}
WiFiClient client;
void loop() {
if(!client.connected())
{
WiFiClient client = server.available();
}
if(client)
{
while(!client.available())
{
delay(1);
}
String s=client.readStringUntil('\r');
if(s.length()!=0)
{
Serial.println(s);
Wire.beginTransmission(7);
Wire.write(s.c_str());
Wire.endTransmission();
}
client.flush();
}
}
#include <ESP8266WiFi.h>
#include<Wire.h>
const int MPU_addr=0x68;
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
const char* ssid = "SumoRobot";
const char* password = "ZumoShield";
const char* host = "192.168.4.1";
WiFiClient client;
void setup() {
Serial.begin(115200);
delay(100);
Serial.println("Serial begins");
pinMode(BUILTIN_LED, OUTPUT);
digitalWrite(BUILTIN_LED,LOW);
Wire.begin();
Wire.beginTransmission(MPU_addr);
Wire.write(0x6B);
Wire.write(0);
Wire.endTransmission(true);
delay(10);
Serial.println("Accelerometer OK");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("WIFI OK");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
}
Serial.println("Connected to Wifi");
}
String message="";
long cntAccel=0,cntSend=0;
void loop() {
cntSend++;
cntAccel++;
if(cntAccel==333)
{
Wire.beginTransmission(MPU_addr);
Wire.write(0x3B);
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr,14,true);
AcX=Wire.read()<<8|Wire.read();
AcY=Wire.read()<<8|Wire.read();
AcZ=Wire.read()<<8|Wire.read();
Tmp=Wire.read()<<8|Wire.read();
GyX=Wire.read()<<8|Wire.read();
GyY=Wire.read()<<8|Wire.read();
GyZ=Wire.read()<<8|Wire.read();
int16_t roll=atan2(AcY,AcZ)*180/PI;
int16_t pitch=atan2(AcX,sqrt(AcY*AcY+AcZ*AcZ))*180/PI;
if(roll>25&&pitch>-30&&pitch<30)
{
message+='F';
}
if(roll<-38&&pitch>-30&&pitch<30)
{
message+='B';
}
if(pitch>35)
{
message+='R';
}
if(pitch<-35)
{
message+='L';
}
cntAccel=0;
}
if(cntSend==800)
{
if(!client.connected())
{
client.connect(host,80);
}
if(message.length()>0)
{
Serial.println(message);
client.println(message);
message="";
}
cntSend=0;
}
}
It takes about 20-25 seconds for home assistant c[…]
I tried to upgrade tof my sonoff basic R2 with the[…]
a problem Perhaps you want to define "Probl[…]
Rebooting your router will not give you a faster I[…]
There are no other notifications from esptool.py i[…]
Using the Arduino IDE, you'll learn how to set up […]
In this project, you will post to Twitter using an[…]
In this project, we will build a water level contr[…]
I guess I'm late, but I had the same problem and f[…]
Last night I received my first D1 Minis for a lear[…]
Although I am aware that this is an old post, I fe[…]