ESP-12 Server stops receiving from Mobil App Client
Posted: Mon Mar 29, 2021 8:34 pm
I am using an ESP-12 as a Server that receives and responds to a Mobile App. It receives and responds to up to 4 queries (sometimes only one, other times 2-4) but then stops receiving. If I disconnect and reconnect, it will receive/respond to 1 less command than before. Anyone have ideas on how to resolve this?
I am basically simulating a WiFi OBD/ELM327 module and feeding responses to an app (such as Torque). My code is as follows:
#include <ESP8266WiFi.h>
const char *ssid = "ELMSim";
const char *OKresponse = "OK\r";
const char *ELMresponse = "ELM327 v1.5\r";
const char *CMD = ">\r";
WiFiServer server(35000);
//Pot for adjusting value
int RPMsensorPin = 0;
int RPMsensorValue = 0;
int RPMtxValue = 0;
IPAddress myIP(192, 168, 4, 1);
void setup() {
Serial.begin(38400);
delay(100);
Serial.println();
Serial.println("Configuring access point...");
WiFi.mode(WIFI_AP_STA);
WiFi.softAPConfig(myIP, myIP, IPAddress(255, 255, 255, 0)); // subnet FF FF FF 00
WiFi.softAP(ssid);
Serial.println("AP IP address: ");
Serial.println(myIP);
server.begin();
}
void loop() {
WiFiClient client = server.available();
if(client) {
delay(10);
Serial.println("Client Connected");
client.println(CMD);
while(client.connected()) {
delay(10);
while(client.available()){
String RHRequest = client.readStringUntil('\r');
Serial.println(RHRequest);
if(RHRequest.equals("AT Z")) {
delay(10);
client.println(ELMresponse);
Serial.print("Response sent by ELMSim...");
Serial.println(ELMresponse);
delay(10);
client.println(CMD);
}
else if(RHRequest.equals("AT SP 0")) {
client.println(RHRequest);
Serial.print("Response sent by ELMSim...");
Serial.println(RHRequest);
delay(10);
client.println(OKresponse);
Serial.print("Response sent by ELMSim...");
Serial.println(OKresponse);
delay(10);
client.println(CMD);
Serial.print("Response sent by ELMSim...");
Serial.println(CMD);
}
else if(RHRequest.equals("AT AL")) {
client.println(RHRequest);
Serial.print("Response sent by ELMSim...");
Serial.println(RHRequest);
delay(10);
client.println(OKresponse);
Serial.print("Response sent by ELMSim...");
Serial.println(OKresponse);
delay(10);
client.println(CMD);
Serial.print("Response sent by ELMSim...");
Serial.println(CMD);
}
else if(RHRequest.equals("AT E0")) {
client.println(RHRequest);
Serial.print("Response sent by ELMSim...");
Serial.println(RHRequest);
delay(10);
client.println(OKresponse);
Serial.print("Response sent by ELMSim...");
Serial.println(OKresponse);
delay(10);
client.println(CMD);
Serial.print("Response sent by ELMSim...");
Serial.println(CMD);
}
else if(RHRequest.equals("AT S0")) {
client.println(OKresponse);
Serial.print("Response sent by ELMSim...");
Serial.println(OKresponse);
delay(10);
client.println(CMD);
Serial.print("Response sent by ELMSim...");
Serial.println(CMD);
}
else if(RHRequest.equals("AT H0")) {
client.println(OKresponse);
client.println(CMD);
}
else if(RHRequest.equals("AT ST FF")) {
client.println(OKresponse);
client.println(CMD);
}
else if(RHRequest.equals("01 00")) {
client.println("410080000001 \r");
delay(100);
client.println("4100BFFFB993 \r");
}
//else if(RHRequest.equals("01 0C")) {
//string rpmread = (a0value, HEX)
//rpmsend = concat 41010,rpmread
client.flush();
}
}
}
}
I am basically simulating a WiFi OBD/ELM327 module and feeding responses to an app (such as Torque). My code is as follows:
#include <ESP8266WiFi.h>
const char *ssid = "ELMSim";
const char *OKresponse = "OK\r";
const char *ELMresponse = "ELM327 v1.5\r";
const char *CMD = ">\r";
WiFiServer server(35000);
//Pot for adjusting value
int RPMsensorPin = 0;
int RPMsensorValue = 0;
int RPMtxValue = 0;
IPAddress myIP(192, 168, 4, 1);
void setup() {
Serial.begin(38400);
delay(100);
Serial.println();
Serial.println("Configuring access point...");
WiFi.mode(WIFI_AP_STA);
WiFi.softAPConfig(myIP, myIP, IPAddress(255, 255, 255, 0)); // subnet FF FF FF 00
WiFi.softAP(ssid);
Serial.println("AP IP address: ");
Serial.println(myIP);
server.begin();
}
void loop() {
WiFiClient client = server.available();
if(client) {
delay(10);
Serial.println("Client Connected");
client.println(CMD);
while(client.connected()) {
delay(10);
while(client.available()){
String RHRequest = client.readStringUntil('\r');
Serial.println(RHRequest);
if(RHRequest.equals("AT Z")) {
delay(10);
client.println(ELMresponse);
Serial.print("Response sent by ELMSim...");
Serial.println(ELMresponse);
delay(10);
client.println(CMD);
}
else if(RHRequest.equals("AT SP 0")) {
client.println(RHRequest);
Serial.print("Response sent by ELMSim...");
Serial.println(RHRequest);
delay(10);
client.println(OKresponse);
Serial.print("Response sent by ELMSim...");
Serial.println(OKresponse);
delay(10);
client.println(CMD);
Serial.print("Response sent by ELMSim...");
Serial.println(CMD);
}
else if(RHRequest.equals("AT AL")) {
client.println(RHRequest);
Serial.print("Response sent by ELMSim...");
Serial.println(RHRequest);
delay(10);
client.println(OKresponse);
Serial.print("Response sent by ELMSim...");
Serial.println(OKresponse);
delay(10);
client.println(CMD);
Serial.print("Response sent by ELMSim...");
Serial.println(CMD);
}
else if(RHRequest.equals("AT E0")) {
client.println(RHRequest);
Serial.print("Response sent by ELMSim...");
Serial.println(RHRequest);
delay(10);
client.println(OKresponse);
Serial.print("Response sent by ELMSim...");
Serial.println(OKresponse);
delay(10);
client.println(CMD);
Serial.print("Response sent by ELMSim...");
Serial.println(CMD);
}
else if(RHRequest.equals("AT S0")) {
client.println(OKresponse);
Serial.print("Response sent by ELMSim...");
Serial.println(OKresponse);
delay(10);
client.println(CMD);
Serial.print("Response sent by ELMSim...");
Serial.println(CMD);
}
else if(RHRequest.equals("AT H0")) {
client.println(OKresponse);
client.println(CMD);
}
else if(RHRequest.equals("AT ST FF")) {
client.println(OKresponse);
client.println(CMD);
}
else if(RHRequest.equals("01 00")) {
client.println("410080000001 \r");
delay(100);
client.println("4100BFFFB993 \r");
}
//else if(RHRequest.equals("01 0C")) {
//string rpmread = (a0value, HEX)
//rpmsend = concat 41010,rpmread
client.flush();
}
}
}
}