So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By John Travland
#90878 I am using an ESP-12 to simulate a Wifi ELM327/OBDII module...serving up OBD data ("RPM" from a potentiometer in this case) to a connected app on my phone (Torque for example). I am able to connect my phone to my 8266 ELMSim. I can also open the app and select my ELMSim as the OBDII module. The issue is when the app sends commands like "AT Z". I am having trouble "receiving" the command in order to respond to it. Any assistance is greatly appreciated.

#include <ESP8266WiFi.h>
#include <SPI.h>

const char *ssid = "ELMSim";
WiFiServer server(35000);

IPAddress local_IP(192, 168, 0, 10); //ESP static ip
IPAddress gateway(192, 168, 0, 10); //IP Address of your WiFi Router (Gateway)
IPAddress subnet(255, 255, 255, 0); //Subnet mask


//Pot for adjusting value
int RPMsensorPin = 0;
int RPMsensorValue = 0;
int RPMtxValue = 0;

void setup() {
Serial.begin(38400);
server.begin();
delay(10);

//Static IP address configuration
WiFi.softAP(ssid);
WiFi.softAPConfig(local_IP, gateway, subnet);
while (WiFi.status() != WL_CONNECTED){
//Serial.println("ELM Sim is available");

delay(500);
}
}

void loop() {

//Read the value of the sensors
RPMsensorValue = analogRead(RPMsensorPin);
if (RPMsensorValue <40){
RPMsensorValue=40;
}
else {
RPMsensorValue = analogRead(RPMsensorPin);
}

RPMtxValue = RPMsensorValue/10;

WiFiClient client = server.available();
// wait for a client (OBD Phone App) to connect
if (!client){
Serial.println("\n[Client connected]");
}
while (client.connected())
// Wait until the client sends some data
{
if (client.available())
{
// Read the first line of the App request
String RHrequest = client.readStringUntil('\r');
Serial.println(RHrequest);


if(!RHrequest.startsWith("AT")) {
server.println("OK");
}
}
}
}