・Bodmer/TFT_eSPI Arduino and PlatformIO IDE compatible TFT library optimised for the STM32, ESP8266 and ESP32 that supports different driver chips https://github.com/Bodmer/TFT_eSPI
#include<ESP8266WiFi.h>#include<WiFiClient.h>#include<DNSServer.h>#include<ESP8266WebServer.h>#include<ESP8266mDNS.h>#include<SPI.h>#include<SD.h>#defineDBG_OUTPUT_PORTSerial#defineLED_PIN5constchar*ssid="esp8266";constchar*password="xxxxxxx";constchar*host="sd.local";constbyteDNS_PORT=53;IPAddressapIP(192,168,0,1);DNSServerdnsServer;ESP8266WebServerserver(80);staticboolhasSD=false;voidreturnOK(){server.send(200,"text/plain","");}voidreturnFail(Stringmsg){server.send(500,"text/plain",msg+"\r\n");}boolloadFromSdCard(Stringpath){StringdataType="text/plain";if(path.endsWith("/"))path+="index.htm";if(path.endsWith(".src"))path=path.substring(0,path.lastIndexOf("."));elseif(path.endsWith(".htm"))dataType="text/html";elseif(path.endsWith(".css"))dataType="text/css";elseif(path.endsWith(".js"))dataType="application/javascript";elseif(path.endsWith(".png"))dataType="image/png";elseif(path.endsWith(".gif"))dataType="image/gif";elseif(path.endsWith(".jpg"))dataType="image/jpeg";elseif(path.endsWith(".ico"))dataType="image/x-icon";elseif(path.endsWith(".xml"))dataType="text/xml";elseif(path.endsWith(".pdf"))dataType="application/pdf";elseif(path.endsWith(".zip"))dataType="application/zip";FiledataFile=SD.open(path.c_str());if(dataFile.isDirectory()){path+="/index.htm";dataType="text/html";dataFile=SD.open(path.c_str());}if(!dataFile)returnfalse;if(server.hasArg("download"))dataType="application/octet-stream";if(server.streamFile(dataFile,dataType)!=dataFile.size()){DBG_OUTPUT_PORT.println("Sent less data than expected!");}dataFile.close();returntrue;}voidhandleNotFound(){if(hasSD&&loadFromSdCard(server.uri()))return;Stringmessage="SDCARD Not Detected\n\n";message+="URI: ";message+=server.uri();message+="\nMethod: ";message+=(server.method()==HTTP_GET)?"GET":"POST";message+="\nArguments: ";message+=server.args();message+="\n";for(uint8_ti=0;i<server.args();i++){message+=" NAME:"+server.argName(i)+"\n VALUE:"+server.arg(i)+"\n";}server.send(404,"text/plain",message);DBG_OUTPUT_PORT.print(message);}// LEDの制御voidhandleLED(){if(!server.hasArg("LED")){Stringmsg="Command Error\n";returnFail(msg);return;}Stringcmd=server.arg("LED");if(cmd=="on"){digitalWrite(LED_PIN,HIGH);DBG_OUTPUT_PORT.println("LED ON");}if(cmd=="off"){digitalWrite(LED_PIN,LOW);DBG_OUTPUT_PORT.println("LED OFF");}returnOK();}voidsetup(void){pinMode(LED_PIN,OUTPUT);digitalWrite(LED_PIN,LOW);DBG_OUTPUT_PORT.begin(115200);DBG_OUTPUT_PORT.setDebugOutput(true);DBG_OUTPUT_PORT.print("\n");WiFi.mode(WIFI_AP);WiFi.softAPConfig(apIP,apIP,IPAddress(255,255,255,0));WiFi.softAP(ssid,password);dnsServer.setTTL(300);dnsServer.setErrorReplyCode(DNSReplyCode::ServerFailure);dnsServer.start(DNS_PORT,host,apIP);server.onNotFound(handleNotFound);server.on("/do",HTTP_GET,handleLED);server.begin();DBG_OUTPUT_PORT.println("HTTP server started");if(SD.begin(SS)){DBG_OUTPUT_PORT.println("SD Card initialized.");hasSD=true;}}voidloop(void){dnsServer.processNextRequest();server.handleClient();}
最近のコメント