Send text from Arduino to mit app using esp8266 Wifi

I want to send temperature sensor data whenever a button named get temperature is pressed on app it should display the current temperature value. I am able to see new client request whenever I click the button and also Arduino serial print but it does not appear on the app text box... Please help

Welcome,

Most of the devices does not have the temperature sensor. See the documentation.

A sensor component that can measure the ambient (external) temperature. Most Android devices do not have this sensor.

They're using an Arduino Temperature Sensor :slight_smile:

Oh, I thought it is an Android sensor :laughing: :laughing: :laughing:

1 Like

This may help you:

1 Like

Thanks @NishyanthKumar
but i m using Wifi instead of bluetooth ... Here is the sample blocks which i want to use please ignore the cross marks as this is just an example. What i want to do is there is a button on my app which is getTemp when i press that button it sends new client request to esp8266 and whatever output in the form of text i get on serial monitor of arduino should get updated on the text box (temp) located just above the button.
ill also provide sample arduino code here i have given constant temp example but it is a variable in my case and its changing

#include <ESP8266WiFi.h>
const char* ssid = "JioFi2_C4FFC1";
const char* password = "######";
WiFiServer server(80);

void setup() {
Serial.begin(38400);

Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
  
  delay(100); //500
  Serial.print(".");
}

Serial.println("");
Serial.println("Wifi Connected");
Serial.println("Server started ");

Serial.println(WiFi.localIP()); 

server.begin();

}
void loop() {
string temp=38*c
WiFiClient client = server.available();
if (!client){
return;
}
Serial.println("new client");
while(!client.available())
{
delay(1);
}
String req = client.readStringUntil('\r');
Serial.println(req);

  if (req.indexOf("/getTemp")!=-1)
  {
    client.println(temp);
    Serial.println(temp);
  }
  String web = "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n";
  client.print(web);
  client.flush();

}

Ah, sorry. Didn't see that.
I'm not the best at Arduino (I don't know C++), but @Juan_Antonio and @NissanCedric are the go-to people to ask in its terms inside of this Community.

Check

2 Likes

Thanks @Juan_Antonio
I have already gone through these two links but the problem with in my case is that I want to receive the text that obtained on serial monitor of Arduino but these 2 examples will send data from to esp device do I need to make any change in Arduino code or in app blocks to receive text from esp device to app using wifi.. ... Please help :pray:

Here many examples with ESP32

1 Like

Check your phone to see if its web browser can reach that 192.168... address.

You may need to switch from your cell service's net access to local WiFi access to get there.

thanks for your support @Juan_Antonio I tried your example of analog read from potentiometer... but in my case it displays "Error1101: unable to connect to specific URL http://192.168.1.184/temp"
i made the same program as like yours but to get temperature data in form of string
the only difference here is :
this is from your code-
if (req.indexOf("consulta") != -1){
valor = analogRead(Ent_Anilogica);
valor_map = map(valor, 0, 4095, 0, 330);
Serial.println(valor);
}

this is from my code-
if (req.indexOf("/getTemp")!=-1)
{
client.println(temp);
Serial.println(temp);
}

I can't understand why its not working please help.

@Sneha_Jangid
Try

if(req.indexOf("getTemp")!=-1)

@Juan_Antonio did but same error

@ABG checked but not working

consulta22

#include <ESP8266WiFi.h>

const char* ssid = "XXXXXXX";
const char* password = "XXXXXXXXXXXX";

String temperature = "34";

WiFiServer server(80);

void setup() {
Serial.begin(115200);

// Conecta a la red wifi.
Serial.println();
Serial.print("Conectando con ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("Conectado con WiFi.");

// Inicio del Servidor web.
server.begin();
Serial.println("Servidor web iniciado.");

// Esta es la IP
Serial.print("Esta es la IP para conectar: ");
Serial.print("http://");
Serial.print(WiFi.localIP());
}

void loop() {
// Consulta si se ha conectado algún cliente.
WiFiClient client = server.available();
if (!client) {
return;
}

Serial.print("Nuevo cliente: ");
Serial.println(client.remoteIP());

// Espera hasta que el cliente envíe datos.
while(!client.available()){ delay(1); }

/////////////////////////////////////////////////////
// Lee la información enviada por el cliente.
String req = client.readStringUntil('\r');
Serial.println(req);

// Realiza la petición del cliente.
if (req.indexOf("consulta") != -1){
temperature = String(random(1,100));
Serial.println(temperature);
delay(10);
}

//////////////////////////////////////////////
// Página WEB. ////////////////////////////
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // Importante.

client.println(temperature);

Serial.print("Cliente desconectado: ");
Serial.println(client.remoteIP());
// client.flush();
}

Here with a potentiometer:
http://kio4.com/arduino/347B_esp8266_AI2_Potenciometro.htm

1 Like

@Sneha_Jangid did it work ?