Can´t HTTP GET with appinventor the ARDUINO wifi server

91 views
Skip to first unread message

Guillermo Daniel Basili Sosa

unread,
Aug 2, 2019, 7:44:43 PM8/2/19
to MIT App Inventor Forum
Hello there, I´m struggling with a sensor that is sending by ESP8266 arduino board to HTTP, I´m getting unable to receive response from IP
Although is working on the browser, is not working on APP INVENTOR.
My thoughts are that maybe my ARDUINO HTTP SERVER header is wrong can sombody help me? I will post in here the arduino code.
---------------------------------------------------------------------------------------------------------------------
For app inventor the blocks setup are basic ones, my server address is 192.168.0.16, I also tried adding the port :8080 but no success!
Please help me out!
Regards
#include <ESP8266WiFi.h>

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

WiFiServer server(80);


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

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

  server.begin();
  Serial.printf("Web server started, open %s in a web browser\n", WiFi.localIP().toString().c_str());
}


// prepare a web page to be send to a client (web browser)
String prepareHtmlPage()
{
  String htmlPage =
     String("HTTP/1.1 200 OK\r\n") +
            "Content-Type: text/html\r\n" +
            "Connection: close\r\n" +  // the connection will be closed after completion of the response
            "Refresh: 5\r\n" +  // refresh the page automatically every 5 sec
            "\r\n" +
            "<!DOCTYPE HTML>" +
            "<html>" +
            "Analog input:  " + String(analogRead(A0)) +
            "</html>" +
            "\r\n";
  return htmlPage;
}


void loop()
{
  WiFiClient client = server.available();
  // wait for a client (web browser) to connect
  if (client)
  {
    Serial.println("\n[Client connected]");
    while (client.connected())
    {
      // read line by line what the client (web browser) is requesting
      if (client.available())
      {
        String line = client.readStringUntil('\r');
        Serial.print(line);
        // wait for end of client's request, that is marked with an empty line
        if (line.length() == 1 && line[0] == '\n')
        {
          client.println(prepareHtmlPage());
          break;
        }
      }
    }
    delay(1); // give the web browser time to receive the data

    // close the connection:
    client.stop();
    Serial.println("[Client disonnected]");
  }
}

Taifun

unread,
Aug 3, 2019, 8:07:58 AM8/3/19
to MIT App Inventor Forum
It would really help if you provided a screenshot of your relevant blocks, so we can see what you are trying to do, and where the problem may be.

Taifun

Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun. 

Guillermo Daniel Basili Sosa

unread,
Aug 5, 2019, 8:18:38 AM8/5/19
to MIT App Inventor Forum
here it goes Taifun
app inventor.JPG

Guillermo Daniel Basili Sosa

unread,
Aug 5, 2019, 8:19:17 AM8/5/19
to MIT App Inventor Forum
as I said, when I go on the browser it shows perfectly, but I cannot transpose that to my label!

Taifun

unread,
Aug 5, 2019, 9:25:19 AM8/5/19
to MIT App Inventor Forum
what happens, if you use the webviewer together with that url?
Taifun

Guillermo Daniel Basili Sosa

unread,
Aug 5, 2019, 9:30:51 AM8/5/19
to MIT App Inventor Forum
when I perform the getResponse and I click the button on app inventor, it shows error 1101 unable to retrieve information error appears.
Is there a way to retrieve the value from <body> from html?
If I load the webviewer the message AnalogSensor appears perfectly, but I need to transpose that to my textbox or label to make my calculations

Taifun

unread,
Aug 5, 2019, 9:52:27 AM8/5/19
to MIT App Inventor Forum
when I perform the getResponse and I click the button on app inventor, it shows error 1101 unable to retrieve information error appears.
do you test using a real device together with the companion app?
or do you use the emulator?
did you try after building the app?

Is there a way to retrieve the value from <body> from html?
there might be an extension which is ale to do this, see the extensions directory here https://puravidaapps.com/extensions.php

Taifun

Guillermo Daniel Basili Sosa

unread,
Aug 5, 2019, 10:00:02 AM8/5/19
to MIT App Inventor Forum
build it didnt work, any guidelines?

Guillermo Daniel Basili Sosa

unread,
Aug 5, 2019, 11:07:03 AM8/5/19
to MIT App Inventor Forum
Actually my thing is pretty easy, I have a analogsensor from arduino that when you open the browser at that address ( lets say 192.168.0.10) it shows analog sensor : 240 I need that 240 in my app inventor labelbox

TimAI2

unread,
Aug 5, 2019, 11:54:15 AM8/5/19
to MIT App Inventor Forum
Try with responseCode ?

Guillermo Daniel Basili Sosa

unread,
Aug 5, 2019, 11:57:52 AM8/5/19
to MIT App Inventor Forum
That's the thing it's like the code it's no getting inside the response block, it just appears the 1101 and is not going any further, in the web browser the arduino is working perfectly

Guillermo Daniel Basili Sosa

unread,
Aug 5, 2019, 12:00:16 PM8/5/19
to MIT App Inventor Forum
I meant the block gottext isn't triggering, it's like is cutting down when it tries to connect to my localip

TimAI2

unread,
Aug 5, 2019, 12:22:56 PM8/5/19
to MIT App Inventor Forum
Is you app/companion/emulator on the same network as the arduino ? 

Guillermo Daniel Basili Sosa

unread,
Aug 5, 2019, 12:27:23 PM8/5/19
to MIT App Inventor Forum
yes for sure, same network, I tried to disconnect everything to not have any other client connected, ping is permanent and stable,  its very weird, cause such a simple task, but app inventor cannot see the localIP address

Guillermo Daniel Basili Sosa

unread,
Aug 5, 2019, 12:29:10 PM8/5/19
to MIT App Inventor Forum
Im trying directly on phone, connected to the same wifi, I missed to say that
Message has been deleted

TimAI2

unread,
Aug 5, 2019, 12:40:36 PM8/5/19
to MIT App Inventor Forum
In your first post you say your server address is 192.168.0.16 (sixteen)
but in your blocks it reads 192.168.0.10 (ten)

?? Could it be that easy ??
Message has been deleted

Guillermo Daniel Basili Sosa

unread,
Aug 5, 2019, 12:53:03 PM8/5/19
to MIT App Inventor Forum
sorry about that I might captured the wrong picture, no, the server of arduino is working on 192.168.0.10 as so the appinventor URL, I tried on a different phone but it doesnt work, I´m totally lost in this one, 

Guillermo Daniel Basili Sosa

unread,
Aug 5, 2019, 12:55:10 PM8/5/19
to MIT App Inventor Forum
I could also snip the ping to 192.168.0.10 but its responding perfectly, this is my real blocks,
app inventor.JPG

Chris Ward

unread,
Aug 5, 2019, 1:12:52 PM8/5/19
to MIT App Inventor Forum
Hi Guillermo

I have never tried this myself but:

Your Arduino Sketch is creating a Web page, yet GET expects the data to be in the Http address?

So, with Arduino set up as the Web Server, a GET request something like this:


in the Sketch, on receipt of the request, the Server would return the requested value:

server.send(200,"text/plain", requestedData);


TimAI2

unread,
Aug 5, 2019, 2:18:51 PM8/5/19
to MIT App Inventor Forum
^^^ my next move ;)

TimAI2

unread,
Aug 5, 2019, 2:27:58 PM8/5/19
to MIT App Inventor Forum
The only other thing I can think of is that the web component wants to POST and not GET ?

Chris Ward

unread,
Aug 5, 2019, 2:35:53 PM8/5/19
to MIT App Inventor Forum
... GET = request data from the Web Server, Arduino is hosting the Web Server (ESP8266 WiFi module)

Normally I could test the same setup here but my lab bench is currently fully dedicated to a 3D printer build :)

Guillermo Daniel Basili Sosa

unread,
Aug 5, 2019, 2:48:19 PM8/5/19
to MIT App Inventor Forum
Actually it's a post because value is on html body not on the address, any guidance to get the post command? So I can let my arduino code as it is?

Taifun

unread,
Aug 5, 2019, 3:21:07 PM8/5/19
to MIT App Inventor Forum
altenatively you could write the data from the Arduino into the page title of the webpage and on the App Inventor side use the webviewer component and its CurrentPageTitle property to get the value

Taifun

Chris Ward

unread,
Aug 5, 2019, 3:27:28 PM8/5/19
to MIT App Inventor Forum

Chris Ward

unread,
Aug 5, 2019, 3:32:18 PM8/5/19
to MIT App Inventor Forum
If you include a Title in the HTML, and save the value as the title, a WebViewer component can be used to collect the value:

Chris Ward

unread,
Aug 5, 2019, 3:33:28 PM8/5/19
to MIT App Inventor Forum
@Taifun - beat me to it!

Mohammad Raza

unread,
Aug 9, 2019, 7:34:12 AM8/9/19
to MIT App Inventor Forum
Hi, I am facing exactly the same problem, when I use web browser fon my laptop 192.168.10.10 I get data from ESP 8266 (Analogue value) but when I use MIT app inventor 2, I similar program mentioned by Guillermo Daniel Basili Sosa I receive error "1101" 

Chris Ward

unread,
Aug 9, 2019, 8:22:05 AM8/9/19
to MIT App Inventor Forum
Hello Mohammad

As discussed above, the data should either be added to the end of the URL, or define a tiny HTML web page and set the data as the page title. Experiment!
Reply all
Reply to author
Forward
0 new messages