Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- BasicHTTPClient.ino
- Created on: 24.05.2015
- hardware, esp32, but can also be an esp8266
- serial VFD screen, in my case a 20l203da5
- replace SSID and PASSWORD with your wifi name and password.
- replace PRICE and CHANGE with your codes from https://thingspeak.com/apps/thinghttp
- in https://thingspeak.com/apps/thinghttp add 2 ThingHTTP's
- for PRICE add url: https://finance.yahoo.com/quote/GME/
- parse string: /html/body/div[1]/div/div/div[1]/div/div[2]/div/div/div[4]/div/div/div/div[3]/div[1]/div/span[1]
- for CHANGE add url: https://finance.yahoo.com/quote/GME/
- parse string: /html/body/div[1]/div/div/div[1]/div/div[2]/div/div/div[4]/div/div/div/div[3]/div[1]/div/span[2]
- copy the api_key after saving into PRICE and CHANGE
- */
- #include <Arduino.h>
- #include <WiFi.h>
- #include <WiFiMulti.h>
- #include <HTTPClient.h>
- #define USE_SERIAL Serial
- WiFiMulti wifiMulti;
- void setup() {
- USE_SERIAL.begin(9600);
- delay(1000);
- USE_SERIAL.write(0x1B);
- USE_SERIAL.write(0x40);
- USE_SERIAL.write(0x0C); //CLEAR SCREEN CMD
- USE_SERIAL.println("StockTicker VFD");
- 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() {
- String gme_price, gme_change = "wifi not connected";
- // wait for WiFi connection
- if ((wifiMulti.run() == WL_CONNECTED)) {
- HTTPClient http;
- // USE_SERIAL.print("[HTTP] begin...\n");
- // configure traged server and url
- http.begin("https://api.thingspeak.com/apps/thinghttp/send_request?api_key=PRICE"); //HTTP
- // USE_SERIAL.print("[HTTP] GET...\n");
- // start connection and send HTTP header
- int httpCode = http.GET();
- // httpCode will be negative on error
- if (httpCode > 0) {
- // 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 == HTTP_CODE_OK) {
- String payload = http.getString();
- gme_price = payload;
- }
- } else {
- // USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
- }
- // USE_SERIAL.print("[HTTP] begin...\n");
- // configure traged server and url
- http.begin("https://api.thingspeak.com/apps/thinghttp/send_request?api_key=CHANGE"); //HTTP
- // USE_SERIAL.print("[HTTP] GET...\n");
- // start connection and send HTTP header
- httpCode = http.GET();
- // httpCode will be negative on error
- if (httpCode > 0) {
- // 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 == HTTP_CODE_OK) {
- String payload = http.getString();
- gme_change = payload;
- }
- } else {
- // USE_SERIAL.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
- }
- http.end();
- }
- USE_SERIAL.write(0x0C); //CLEAR SCREEN CMD
- USE_SERIAL.println("GME $" + gme_price);
- USE_SERIAL.println(gme_change);
- // delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement