Skip to content

Instantly share code, notes, and snippets.

@zielu92
Created October 30, 2021 04:33
Show Gist options
  • Save zielu92/ee2d459c9952bc80334b9829a46953e6 to your computer and use it in GitHub Desktop.
Save zielu92/ee2d459c9952bc80334b9829a46953e6 to your computer and use it in GitHub Desktop.
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <uri/UriBraces.h>
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#ifndef STASSID
#define STASSID "SSID"
#define STAPSK "PASSWORD"
#endif
const int row = 4;
const int column = 20;
LiquidCrystal_I2C lcd(0x27,column,row);
const char *ssid = STASSID;
const char *password = STAPSK;
ESP8266WebServer server(80);
void setup() {
Wire.begin();
lcd.begin(column,row);
lcd.home();
lcd.noAutoscroll();
lcd.backlight();
Serial.begin(115200);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid,password);
while(WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.print("[WIFI] Connected to ");
Serial.println(ssid);
Serial.print("[WIFI] IP address: ");
Serial.println(WiFi.localIP());
server.on(F("/"), []() {
server.send(200, "text/plain", "hello there!");
});
server.on(UriBraces("/line/{}/text/{}"), []() {
String line = server.pathArg(0);
String text = server.pathArg(1);
text.replace("%20", " ");
display(line.toInt(), text);
server.send(200, "text/plain", "Line: '" + line + "' and text: '" + text + "'");
});
server.begin();
Serial.println("[SERV] HTTP server started");
}
void loop() {
server.handleClient();
}
void display(int line, String text) {
Serial.println("[LCD] Display '" + text + "' at line: '" + line + "'");
clearLine(line);
lcd.setCursor(0,line);
lcd.print(text);
delay(500);
}
void clearLine(int line) {
lcd.setCursor(0,line);
for(int i = 0; i < column; i++) {
lcd.print(" ");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment