#include
#include //https://github.com/esp8266/Arduino
//needed for library
#include
#include //https://github.com/tzapu/WiFiManager
#include
#include
char url[]="http://filmsbykris.com/qr/2020/msg.php";
//amount to wait before loop start
int wait=10000;
//amount to wait each loop
int loop_wait=5000;
void scrollText();
void request();
// set the LCD number of columns and rows
int lcdColumns = 16;
int lcdRows = 2;
// set LCD address, number of columns and rows
// if you don't know your display address, run an I2C scanner sketch
LiquidCrystal_I2C lcd(0x3F, lcdColumns, lcdRows);
void setup(){
// initialize LCD
lcd.init();
// turn on LCD backlight
lcd.backlight();
WiFi.mode(WIFI_STA); // explicitly set mode, esp defaults to STA+AP
// put your setup code here, to run once:
Serial.begin(115200);
// WiFi.mode(WiFi_STA); // it is a good practice to make sure your code sets wifi mode how you want it.
//WiFiManager, Local intialization. Once its business is done, there is no need to keep it around
WiFiManager wm;
//reset settings - wipe credentials for testing
//wm.resetSettings();
// Automatically connect using saved credentials,
// if connection fails, it starts an access point with the specified name ( "AutoConnectAP"),
// if empty will auto generate SSID, if password is blank it will be anonymous AP (wm.autoConnect())
// then goes into a blocking loop awaiting configuration and will return success result
bool res;
// res = wm.autoConnect(); // auto generated AP name from chipid
res = wm.autoConnect("Spy_Pager"); // anonymous ap
// res = wm.autoConnect("AutoConnectAP","password"); // password protected ap
if(!res) {
Serial.println("Failed to connect");
// ESP.restart();
}
else {
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
}
lcd.clear();
lcd.setCursor(0, 0);
// print message
lcd.print("Secret Spy MSG!");
lcd.setCursor(1, 0);
lcd.print("Loading...");
}
void loop(){
request(url);
delay(loop_wait);
}
void request(char *url){
WiFiClient client;
HTTPClient http;
Serial.print("[HTTP] begin...\n");
if (http.begin(client, url)) { // HTTP
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
Serial.printf("[HTTP] GET... code: %d\n", httpCode);
// file found at server
if (httpCode == HTTP_CODE_OK || httpCode == HTTP_CODE_MOVED_PERMANENTLY) {
String payload = http.getString();
Serial.println(payload);
lcd.clear();
lcd.setCursor(0, 0);
// print message
lcd.print("Secret Spy MSG!");
scrollText(1, payload, 250, lcdColumns);
}
} else {
Serial.printf("[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
char msg[] = "[HTTP] GET... failed, error:";
scrollText(1, msg, 250, lcdColumns);
}
http.end();
} else {
Serial.printf("[HTTP} Unable to connect\n");
scrollText(1, "[HTTP} Unable to connect", 250, lcdColumns);
}
}
void scrollText(int row, String message, int delayTime, int lcdColumns) {
for (int i=0; i < lcdColumns; i++) {
message = " " + message;
}
message = message + " ";
for (int pos = 0; pos < message.length(); pos++) {
lcd.setCursor(0, row);
lcd.print(message.substring(pos, pos + lcdColumns));
delay(delayTime);
}
}