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