Hello,
As far as I understand you will read data from a website/page.
I had this question also. I have a webserver running on a ESP32 with a BME280 sensor which give temperature, humidity and air pressure.
With the help of the OkHttp librari which example can be find on the internet.
https://www.bing.com/videos/search?q...6FORM%3DHDRSC3
With help of string manipulation and unique letter combination I was able to retract the temp, humi, and airpress data.
[code]
package com.example.okhttprequestexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import java.lang.String;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class MainActivity extends AppCompatActivity {
private TextView mTextViewResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTextViewResult = findViewById(R.id.text_view_tempb);
OkHttpClient client = new OkHttpClient();
String url = "http://192.168.2.11";
Request request = new Request.Builder()
.url(url)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (response.isSuccessful()) {
final String myResponse = response.body().string();
MainActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
int index_tempb = myResponse.indexOf("Temperature");
// mTextViewResult.setText(myResponse);
String tempb = myResponse.substring(index_tempb-102,index_tempb-97);
System.out.println(myResponse.substring(index_temp b-102,index_tempb-97));
mTextViewResult.setText(myResponse.substring(index _tempb-102,index_tempb-97));
int index_tempi = myResponse.indexOf("Humidity");
String tempi = myResponse.substring(index_tempi-98,index_tempi-93);
//mTextViewResult1.setText(myResponse.substring(inde x_tempi-98,index_tempi-93));
mTextViewResult.setText(myResponse.substring(index _tempi-98,index_tempi-93));
}
});
}
}
});
}
}
[code/]
Succes,
ilioSS