esp32-env-monitor/esp32-env-monitor.ino

61 lines
1.2 KiB
Arduino
Raw Normal View History

2019-05-02 15:40:41 +02:00
#include <Arduino.h>
2019-05-02 15:06:21 +02:00
#include <WiFi.h>
#include "wifi_login.h"
2019-05-02 15:40:41 +02:00
#include <U8x8lib.h>
#ifdef U8X8_HAVE_HW_SPI
#include <SPI.h>
#endif
U8X8_SSD1327_EA_W128128_4W_HW_SPI u8x8(/* cs=*/ 10, /* dc=*/ 9, /* reset=*/ 8);
// setup the terminal (U8X8LOG) and connect to u8g2 for automatic refresh of the display
// The size (width * height) depends on the display
#define U8LOG_WIDTH 16
#define U8LOG_HEIGHT 12
uint8_t u8log_buffer[U8LOG_WIDTH*U8LOG_HEIGHT];
U8X8LOG u8x8log;
2019-05-02 15:06:21 +02:00
void setup() {
2019-05-02 15:40:41 +02:00
//Init Display
u8x8.begin();
u8x8.setFont(u8x8_font_chroma48medium8_r);
u8x8log.begin(u8x8, U8LOG_WIDTH, U8LOG_HEIGHT, u8log_buffer);
u8x8log.setRedrawMode(0); // 0: Update screen with newline, 1: Update screen for every char
2019-05-02 15:06:21 +02:00
//Init wifi connection
WiFi.begin(ssid, password);
2019-05-02 15:40:41 +02:00
u8x8log.print("Connecting to SSID:\n");
u8x8log.print(ssid);
u8x8log.print("\n");
u8x8log.print("\n");
2019-05-02 15:06:21 +02:00
while (WiFi.status() != WL_CONNECTED) {
delay(500);
2019-05-02 15:40:41 +02:00
u8x8log.print(".");
2019-05-02 15:06:21 +02:00
}
2019-05-02 15:40:41 +02:00
u8x8log.print("\n");
u8x8log.print("WiFi connected\n");
u8x8log.print("IP address:\n");
u8x8log.println(WiFi.localIP());
u8x8log.print("\n");
u8x8log.print("\n");
2019-05-02 15:06:21 +02:00
}
void loop() {
2019-05-02 15:40:41 +02:00
//Clear screen
u8x8log.print("\f");
delay(10000);
2019-05-02 15:06:21 +02:00
}