I've looked high and low and worded my searches every way possible and cannot figure out how to get / read data from a local web server that was created by an Arduino ESP8266. The web server is super simple and only displays two lines of text. I just want to be able to read one of those lines and display it in the app.
If you could just point me towards a tutorial on getting the information from my local web server that would be awesome.
Everything I keep finding is for HTTP related or msq etc... I don't want to write anything to the webserver all I want to do is read one line of text.!
Here is the Arduino sketch used to create the local web server -
/*****************************************************
Date: 18 june 2018
Written by: Usman Ali Butt
Property off: microcontroller-project.com
***************************************************/
#include <ESP8266WiFi.h>
const char* ssid = "Your SSID";
const char* password = "Your Wifi Password";
int BAT= A0; //Analog channel A0 as used to measure battery voltage
float RatioFactor=5.714; //Resistors Ration Factor
WiFiServer server(80);
void setup() {
Serial.begin(9600);
delay(10);
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
server.begin(); // Start the server
Serial.println("Server started");
// Print the IP address on serial monitor
Serial.print("Use this URL to connect: ");
Serial.print("http://"); //URL IP to be typed in mobile/desktop browser
Serial.print(WiFi.localIP());
Serial.println("/");
}
void loop() {
int value = LOW;
float Tvoltage=0.0;
float Vvalue=0.0,Rvalue=0.0;
// Check if a client has connected
WiFiClient client = server.available();
if (!client) {
return;
}
// Wait until the client sends some data
Serial.println("new client");
while(!client.available()){
delay(1);
}
// Read the first line of the request
String request = client.readStringUntil('\r');
Serial.println(request);
client.flush();
// Match the request
if (request.indexOf("/bat=ON") != -1) {
/////////////////////////////////////Battery Voltage//////////////////////////////////
for(unsigned int i=0;i<10;i++){
Vvalue=Vvalue+analogRead(BAT); //Read analog Voltage
delay(5); //ADC stable
}
Vvalue=(float)Vvalue/10.0; //Find average of 10 values
Rvalue=(float)(Vvalue/1024.0)5; //Convert Voltage in 5v factor
Tvoltage=Rvalue RatioFactor; //Find original voltage by multiplying with factor
/////////////////////////////////////Battery Voltage//////////////////////////////////
value = HIGH;
}
// Return the response
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println(""); // do not forget this one
client.println("");
client.println("");
client.println("Battery Voltage =");
client.print(Tvoltage);
client.println(" ");
if(value == HIGH) {
client.println("Updated");
} else {
client.print("Not Updated");
}
client.println("--------");
if(Tvoltage<=5){
client.println("Battery dead OR disconnected");
}
else if(Tvoltage>5 && Tvoltage<=10){
client.println("Need Imediate recharge");
}
else if(Tvoltage>10 && Tvoltage<=12){
client.println("Recharge");
}
else{
client.println("Battery Full");
}
client.println(" ");
client.println("<a href="/bat=ON"">Status ");
client.println("");
delay(1);
Serial.println("Client disonnected");
Serial.println("");
}
Taifun
December 28, 2019, 3:23pm
2
see this exampple
I tried this, but did not get a response…
[Unbenannt]
probably someone else has an idea?
Taifun
hambo.aia (2.0 KB)
Taifun
Trying to push the limits! Snippets , Tutorials and Extensions from Pura Vida Apps by Taifun.
ABG
December 28, 2019, 9:38pm
3
See the Arduino and WiFi section of FAQ
https://sites.google.com/view/ai2-faq-view/home
for esp8266 samples.
Taifun
July 23, 2022, 11:51am
5
It does not look like you read the linked thread... it does not use any extension ...
Taifun
PS: I will close this thread, as it is already a few years old... feel free to start a new thread and read first
Before you ask a question / open a new topic
please take care of the following points:
The forum was previously searched for similar topics / issues.
Give a precise (detailed) description of
the issue / bug,
the goal.
Show the (relevant) blocks (images, screenshots of blocks in high quality).
Debug your blocks (connect to Companion and right mouse click: → Do it).
Name the Android / iOS version running on your (test) device.
Do not open multiple threads on the same topic.
If you haven't al…