Hello,
For the project I,am working on I have the following chalenge,
With the help of a ESP32 and the BME280 sensor I have a server which gives the sensor data.
No problem s far.
But I would like to have the data in an app on my android mobile.
The url page is converted to a tekst file with the help of the OkHttprequest methode which you can fins on you-tube works like a charm.
In this page/file/string??? I can read the temp. I will retrieve from the file howe can this be done???
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_result);
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() {
mTextViewResult.setText(myResponse);
}
});
}
}
});
}
}
As newbee I think this must be programmed in the listing/script as shown above.
Any hints and help is welcome.
Regards ilioSS