diff --git a/Hardware/photo_2020-11-06_13-23-24.jpg b/Hardware/photo_2020-11-06_13-23-24.jpg new file mode 100644 index 0000000..c51b7bb Binary files /dev/null and b/Hardware/photo_2020-11-06_13-23-24.jpg differ diff --git a/src/MQTT_Reader06.ino b/src/MQTT_Reader06.ino index 94a87e6..9068f58 100644 --- a/src/MQTT_Reader06.ino +++ b/src/MQTT_Reader06.ino @@ -42,6 +42,17 @@ #include // ESP32 #include // ESP32 #include // ESP32 + #include + #include // E-Paper + //#include // 2.13" b/w + //#include // 2.13" b/w new panel + #include // E-Paper + #include + #include + #include + #include + #include + #include #else #include // EPS8266 #include // ESP8266 @@ -59,24 +70,40 @@ #include #include #include + + // #include // for retreiving the MAC adress // Definition der Pins #ifdef ESP32 - #define SS_PIN 17 // GPIO17 - #define RST_PIN 16 // GPIO16 - #define BEEP_PIN 14 // GPIO16 - #define BUTTON_PIN 13 // GPIO2 + #define SS_PIN 32 // GPIO17 + #define RST_PIN 33 // GPIO16 + #define BEEP_PIN 27 // GPIO16 + #define BUTTON_PIN 39 // GPIO39 + #define CS 19 // ESP32 + + #define SPI_MOSI 23 + #define SPI_MISO -1 + #define SPI_CLK 18 + + #define ELINK_SS 5 + #define ELINK_BUSY 4 + #define ELINK_RESET 16 + #define ELINK_DC 17 #else -// #define SS_PIN 15 // GPIO15 -> uncomment this for the old PCB - #define SS_PIN 2 // GPIO2 - #define RST_PIN 0 // GPIO00 - #define BEEP_PIN 16 // GPIO16 +// #define SS_PIN 15 // GPIO15 -> uncomment this for the old PCB + #define SS_PIN 2 // GPIO2 + #define RST_PIN 0 // GPIO00 + #define BEEP_PIN 16 // GPIO16 #define BUTTON_PIN 13 // GPIO2 -> uncomment this for the old PCB + #define CS 15 // ESP8266 #endif -#define CS 15 +#define HSPI_MOSI 15 +#define HSPI_MISO 2 +#define HSPI_SCLK 14 + // to make some messages easier to read #define CONNECT_TO_WIFI 0 @@ -128,19 +155,20 @@ int maxMessage = 18; String lastLine1, lastLine2; // to save previous displayed messages boolean linesSaved = 0; // no previous message has been saved +int fsize=0; // current font size (for E-paper) -String Message_Disp[] = {"verfügbar", // 0 - equipment available // 0 +String Message_Disp[] = {"verfuegbar", // 0 - equipment available // 0 "reserviert", // 0 - equipment reserved // 1 "reserviert ab", // 13 - reserved starting from // 2 "in Benutzung", // 0 - equipment in use // 3 "freigegeben", // 0 - access granted // 4 "Anmeld. fehlgeschlagen", // 8 - login error // 5 - "Nutzungsgebühr ", // 15 - usage fee // 6 + "Nutzungsgebuehr", // 15 - usage fee // 6 "Nutzung nicht erlaubt", // 13 - operation not allowed // 7 "Nutzung auf eigenem Risiko", // 11 - operation at own risk // 8 "gesperrt durch", // 14 - equipment locked by // 9 "freizugeben durch", // 11 - to be released by // 10 - "außerhalb der Nutzungzeit", // 14 - outside ooperating hours// 11 + "ausserhalb der Nutzungzeit", // 15 - outside ooperating hours// 11 "Nutzungsdauer", // 13 - duration of use // 12 "abgemeldet", // 0 - logged out // 13 "abschalten in", // 13 - equipment will lock down// 14 @@ -148,9 +176,9 @@ String Message_Disp[] = {"verfügbar", // 0 - equipment av "Karte unbekannt", // 0 - card unknown // 16 "Berechtigung endet", // 12 - training to expire // 17 "Ruhemodus", // 0 - sleep mode // 18 - "Aufsicht bestätigen"}; // 8 - confirm presence // 19 + "Aufsicht bestaetigen"}; // 8 - confirm presence // 19 -int SplitAt[]={0,0,13,0,0,8,15,13,11,14,11,14,14,0,13,0,0,12,0,8}; +int SplitAt[]={0,0,13,0,0,8,15,13,11,15,11,14,14,0,13,0,0,12,0,8}; /* String Message_Com[] = {"1", // equipment available @@ -175,6 +203,15 @@ String Message_Com[] = {"1", // equipment availab "20"}; // sleep mode */ + +//----------- E-Paper-Stuff +#ifdef ESP32 + SPIClass eSPI(HSPI); + GxIO_Class io(eSPI, /*CS=5*/ ELINK_SS, /*DC=*/ ELINK_DC, /*RST=*/ ELINK_RESET); + GxEPD_Class EPaper(io, /*RST=*/ ELINK_RESET, /*BUSY=*/ ELINK_BUSY); +#endif + + EthernetClient ethClient; // in case of Ethernet connection WiFiClient wifiClient; // in case of Wifi connection PubSubClient MQTTclient; // The MQTT Client @@ -249,7 +286,13 @@ void setup(void){ digitalWrite(CS, HIGH); // -> needs to be set, otherwise MISO will be pulled LOW - SPI.begin(); + #ifdef ESP32 + SPI.begin(HSPI_SCLK, HSPI_MISO, HSPI_MOSI, CS); // for the LAN Module and the RC522 module + eSPI.begin(SPI_CLK, SPI_MISO, SPI_MOSI, ELINK_SS); // For the e-Paper Module + #else + SPI.begin(); + #endif + rfid.PCD_Init(); // RC522 initialize // rfid.PCD_PerformSelfTest(); @@ -258,6 +301,16 @@ void setup(void){ Serial.println("Booting..."); des.init(C_key,IV); + + #ifdef ESP32 + EPaper.init(); // enable diagnostic output on Serial + EPaper.setRotation(3); + EPaper.fillScreen(GxEPD_WHITE); + EPaper.setTextColor(GxEPD_BLACK); + EPaper.setFont(&FreeMonoBold12pt7b); + EPaper.setCursor(0, 0); + EPaper.update(); + #endif display.init(); // initialize display display.clear(); @@ -325,6 +378,7 @@ void setupMQTT(void){ StatusToDisplay(CONNECT_TO_LAN); WiFi.macAddress(mac); + Ethernet.init(CS); // set the correct pin if(Ethernet.begin(mac) == 0) { Serial.println(F("Ethernet configuration using DHCP failed")); StatusToDisplay(ERROR_DHCP); @@ -335,7 +389,7 @@ void setupMQTT(void){ } Serial.print("set Client to Ethernet: "); MQTTclient.setClient(ethClient); - WiFi.forceSleepBegin(); // TODO + //WiFi.forceSleepBegin(); // TODO //WiFi.mode(WIFI_OFF); // TODO Serial.println("OK"); } @@ -1140,6 +1194,12 @@ int len, split=16; */ void StatusToDisplay(int item){ + #ifdef ESP32 + EPaper.setFont(&FreeMonoBold18pt7b); + fsize=18; + #endif + display.setFont(ArialMT_Plain_24); + if(item==CONNECT_TO_WIFI){ display2lines("connecting...", "Wifi"); } @@ -1153,19 +1213,15 @@ void StatusToDisplay(int item){ display2lines("LAN", "connecting..."); } else if(item==MQTT_RFID){ - display.setFont(ArialMT_Plain_24); display2linesRAW("MQTT", "RFID"); } else if(item==IN_AP_MODE){ - display.setFont(ArialMT_Plain_24); display2linesRAW("AP-", "MODE"); } else if(item==ERROR_RFID){ - display.setFont(ArialMT_Plain_24); display2linesRAW("RFID-", "ERROR"); } else if(item==WRONG_RFID_TYPE){ - display.setFont(ArialMT_Plain_24); display2linesRAW("Read-", "ERROR"); } else if(item==ERROR_DHCP){ @@ -1176,6 +1232,10 @@ void StatusToDisplay(int item){ void LastMessageDisplay(void){ if(linesSaved){ display.setFont(ArialMT_Plain_16); + #ifdef ESP32 + EPaper.setFont(&FreeMonoBold12pt7b); + fsize=12; + #endif display2linesRAW(lastLine1, lastLine2); } else @@ -1194,6 +1254,10 @@ void popRFIDerror(void){ void display2lines(String str1, String str2) { display.setFont(ArialMT_Plain_16); + #ifdef ESP32 + EPaper.setFont(&FreeMonoBold12pt7b); + fsize=12; + #endif display2linesRAW(str1, str2); } @@ -1204,11 +1268,26 @@ void display2lines(String str1, String str2) { void display2linesRAW(String str1, String str2) { display.clear(); display.setTextAlignment(TEXT_ALIGN_CENTER); - display.drawString(66, 18, str1); - display.drawString(66, 40, str2); + display.drawString(64, 13, str1); + display.drawString(64, 35, str2); display.setFont(ArialMT_Plain_10); display.drawString(64, 0, ReaderID); // Show the reader ID on top of the screen display.display(); + #ifdef ESP32 + EPaper.fillScreen(GxEPD_WHITE); + int x1=(EPaper.width()/2-(str1.length()*fsize)/2); + EPaper.setCursor(x1,20+2*fsize); + EPaper.println(str1); + int x2=(EPaper.width()/2-(str2.length()*fsize)/2); + EPaper.setCursor(x2,50+2*fsize); + EPaper.println(str2); + EPaper.setFont(&FreeMonoBold9pt7b); + EPaper.setCursor(EPaper.width()-8*9,12); + EPaper.print(F("ID:")); + EPaper.println(ReaderID); + EPaper.updateWindow(0, 0, EPaper.width()-1, EPaper.height()-1, true); + // EPaper.update(); + #endif }