I have problem with ports in my esp8622, and i dont know why.
In station mode or connecting to a wifi y only can make tcp server with port 80.
yesterday work but now not, and i dont know what y change. i restart de firmware and nothing.
someone have idea?
ty.
void setup(void)
{
mySerial.begin(9600);
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(CONNECT_NAME, CONNECT_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.setSoftAPParam(NAME, PASSWORD, CHNL, ENCRYPT)) {
Serial.print("Create AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Create AP failure\r\n");
}
if (wifi.enableMUX()) {
Serial.print("multiple ok\r\n");
} else {
Serial.print("multiple err\r\n");
}
if (wifi.startTCPServer(PORT)) {
Serial.print("start tcp server ok\r\n");
} else {
Serial.print("start tcp server err\r\n");
}
if (wifi.setTCPServerTimeout(TIMEOUT)) {
Serial.print("set tcp server timout ok\r\n");
} else {
Serial.print("set tcp server timout err\r\n");
}
pinMode(M_SPEED, OUTPUT);
pinMode(M_BEHIND,OUTPUT);
pinMode(M_FRONT,OUTPUT);
velocity(0);
myServo.attach(7);
myServo.write(93);//mid
Serial.print("setup end\r\n");
}
pd: library--->GitHub - itead/ITEADLIB_Arduino_WeeESP8266: An easy-to-use Arduino ESP8266 library besed on AT firmware.
system
2
You posted part of your code. I'll post part of the answer.
You need to ...
#include "ESP8266.h"
#include "SoftwareSerial.h"
#include "Servo.h"
#define CONNECT_NAME "DELPALACIO"
#define CONNECT_PASSWORD "0000000000"
#define NAME "WifCar"
#define PASSWORD "0000000000"
#define CHNL 7
#define ENCRYPT 3 //0 is encryption type like 0 = Open, 2 =WPA_PSK, 3 = WPA2_PSK, 4 = WPA_WPA2_PSK
#define PORT 80
#define TIMEOUT 0
#define M_BEHIND 4
#define M_FRONT 5
#define M_SPEED 6
SoftwareSerial mySerial(3, 2); /* RX:D3, TX:D2 */
ESP8266 wifi(mySerial);
Servo myServo;
String command;
String value;
void setup(void)
{
mySerial.begin(9600);
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(CONNECT_NAME, CONNECT_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.setSoftAPParam(NAME, PASSWORD, CHNL, ENCRYPT)) {
Serial.print("Create AP success\r\n");
Serial.print("IP: ");
Serial.println(wifi.getLocalIP().c_str());
} else {
Serial.print("Create AP failure\r\n");
}
if (wifi.enableMUX()) {
Serial.print("multiple ok\r\n");
} else {
Serial.print("multiple err\r\n");
}
if (wifi.startTCPServer(PORT)) {
Serial.print("start tcp server ok\r\n");
} else {
Serial.print("start tcp server err\r\n");
}
if (wifi.setTCPServerTimeout(TIMEOUT)) {
Serial.print("set tcp server timout ok\r\n");
} else {
Serial.print("set tcp server timout err\r\n");
}
pinMode(M_SPEED, OUTPUT);
pinMode(M_BEHIND,OUTPUT);
pinMode(M_FRONT,OUTPUT);
velocity(0);
myServo.attach(7);
myServo.write(93);//mid
Serial.print("setup end\r\n");
}
void loop(void)
{
uint8_t buffer[128] = {0};
uint8_t mux_id;
uint32_t len = wifi.recv(&mux_id, buffer, sizeof(buffer), 100);
String msg;
if (len > 0) {
for(uint32_t i = 0; i < len; i++) {
if ((char)buffer[i] != ';')
msg+= (char)buffer[i];
else
{
msg+=';'; //adding ; for split
command = getStringPartByNr(msg, '=', 0);
value = getStringPartByNr(msg, '=', 1);
Serial.print("Msg["+msg+"]:: "+command+" "+value+"\r\n");
if(command.equalsIgnoreCase("MAR"))
{
gear(value);
}
else if(command.equalsIgnoreCase("VEL"))
{
velocity(value.toInt());
}
else if(command.equalsIgnoreCase("ROT"))
{
revolution(value.toInt());
}
msg=""; //clear msg
}
}
}
}
void gear(String g){
if(g.equalsIgnoreCase("del"))
{
//Serial.print("Front\r\n");
digitalWrite(M_BEHIND,LOW);
digitalWrite(M_FRONT,HIGH);
}
else if(g.equalsIgnoreCase("tra"))
{
//Serial.print("Behind\r\n");
digitalWrite(M_BEHIND,HIGH);
digitalWrite(M_FRONT,LOW);
}
}
void velocity(int v){
analogWrite(M_SPEED, v);
//Serial.print("Speed: "+String(v)+"\r\n");
}
void revolution(int r){
int maped =map(r,-10, 10, 125, 0); //map servo and acelerometer values
myServo.write(maped);
//Serial.print("Servo: "+String(maped)+"\r\n");
}
String getStringPartByNr(String data, char separator, int index)
{
// spliting a string and return the part nr index
// split by separator
int stringData = 0; //variable to count data part nr
String dataPart = ""; //variable to hole the return text
for(int i = 0; i<data.length()-1; i++) { //Walk through the text one letter at a time
if(data[i]==separator) {
//Count the number of times separator character appears in the text
stringData++;
}else if(stringData==index) {
//get the text when separator is the rignt one
dataPart.concat(data[i]);
}else if(stringData>index) {
//return text and stop if the next separator appears - to save CPU-time
return dataPart;
break;
}
}
//return text if this is the last part
return dataPart;
}
system
4
In station mode or connecting to a wifi y only can make tcp server with port 80.
Your code doesn't demonstrate trying to create a TCP server connected to a different port.
yesterday work but now not
Yesterday, what worked? Connecting to a different port? On the same server? From the same location?
Yesterday, what worked? Connecting to a different port? On the same server? From the same location?
yes, with port 400, with same server and same location