ESP8266 LCD Quote of the Day?

Hey,

I’m basing this experimental project off the example “BasicHTTPClient” sketch used in the ESP8266 library:

/**
 * BasicHTTPClient.ino
 *
 *  Created on: 24.05.2015
 *
 */

#include <Arduino.h>

#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>

#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;

void setup() {

    USE_SERIAL.begin(115200);
   // USE_SERIAL.setDebugOutput(true);

    USE_SERIAL.println();
    USE_SERIAL.println();
    USE_SERIAL.println();

    for(uint8_t t = 4; t > 0; t--) {
        USE_SERIAL.printf("[SETUP] WAIT %d...\n", t);
        USE_SERIAL.flush();
        delay(1000);
    }

    WiFiMulti.addAP("SSID", "PASSWORD");

}

void loop() {
    // wait for WiFi connection
    if((WiFiMulti.run() == WL_CONNECTED)) {

        HTTPClient http;

        USE_SERIAL.print("[HTTP] begin...\n");
        // configure traged server and url
        //http.begin("192.168.1.12", 443, "/test.html", true, "7a 9c f4 db 40 d3 62 5a 6e 21 bc 5c cc 66 c8 3e a1 45 59 38"); //HTTPS
        http.begin("192.168.1.12", 80, "/test.html"); //HTTP

        USE_SERIAL.print("[HTTP] GET...\n");
        // start connection and send HTTP header
        int httpCode = http.GET();
        if(httpCode) {
            // HTTP header has been send and Server response header has been handled
            USE_SERIAL.printf("[HTTP] GET... code: %d\n", httpCode);

            // file found at server
            if(httpCode == 200) {
                String payload = http.getString();
                USE_SERIAL.println(payload);
            }
        } else {
            USE_SERIAL.print("[HTTP] GET... failed, no connection or no HTTP server\n");
        }
    }

    delay(10000);
}

However, when I try to replace the “192.168.1.12”, 80, “/test.html” used in the http.begin function with a daily quote website (e.g. http://www.eduro.com/), the serial port returns with an error:

[HTTP] begin...
[HTTP] GET...
[HTTP] GET... code: 200

[HTTP] begin...
[HTTP] GET...
[HTTP] GET... code: 200

How could I go about reading only the first quote of the day and then displaying this on a 1602 LCD (Using the LiquidCrystal Library)? :confused:

HTTP code 200 means OK (that is, successful).

You now need to parse the HTML being sent to you and extract the first quote (if that is what this web page is giving you).

First step is to actually identify what that web site is sending to you apart from the OK response.

^agreed.

It doesnt look like there is an API.. or a webservice or something that specifically gives you the quote of the day.

It looks as if you would have to parse the site content and 'pick' your quote out.

(not sure how much processing power can be used for parsing a page like that?)

If there isn't an api it may be better to use one of the quote sites that does have an api such as https://theysaidso.com/api/.

Google quote api, there are many results.

Hey,

So I found a daily quote API which returns in JSON from https://theysaidso.com/api/ (thanks MartynC!). I replaced the same line, and now I get the following message in the Serial Monitor:

[HTTP] begin...
[HTTP] GET...
[HTTP] GET... code: 200
2b5
{
    "success": {
        "total": 1
    },
    "contents": {
        "quotes": [
            {
                "quote": "You must be the change you want to see in the world....",
                "length": "55",
                "author": "M.K. Gandhi",
                "tags": [
                    "change",
                    "inspire",
                    "leadership"
                ],
                "category": "inspire",
                "date": "2016-06-23",
                "title": "Inspiring Quote of the day",
                "background": "https://theysaidso.com/img/bgs/man_on_the_mountain.jpg",
                "id": "dj0Sq7ipgSdBr1tMOO_WSAeF"
            }
        ]
    }
}
0

How can I now search for "quote" in the feed and return just the quote of the day (I don't need the other data)?

Also, does this need to be done in string format to be easily transferred to an LCD using the LiquidCrystal library?

I never tried parsing a json in Arduino, but give a try with this library https://github.com/bblanchon/ArduinoJson or do some more search and you might get some other libs.