wifi settings prep

This commit is contained in:
2021-08-25 12:35:09 +02:00
parent 73518dda4f
commit 1cfd6f9bef
9 changed files with 153 additions and 151 deletions

View File

@@ -9,6 +9,8 @@
"string": "cpp", "string": "cpp",
"unordered_map": "cpp", "unordered_map": "cpp",
"vector": "cpp", "vector": "cpp",
"initializer_list": "cpp" "initializer_list": "cpp",
"string_view": "cpp",
"ranges": "cpp"
} }
} }

View File

@@ -15,6 +15,8 @@ framework = arduino
monitor_speed = 115200 monitor_speed = 115200
lib_deps = lib_deps =
glmnet/Dsmr@^0.3 glmnet/Dsmr@^0.3
juerd/ESP-WiFiSettings @ ^3.8.0
lib_ldf_mode = deep+ lib_ldf_mode = deep+
compile_flags = ;compile_flags =
-std=c++11 ; -std=c++11
board_build.filesystem = littlefs

View File

@@ -1,13 +1,44 @@
#include "connection.h" #include "connection.h"
String wifiState;
FS *filesystem = &SPIFFS;
void initWifiConnection(void)
{
// Set custom callback functions
WiFiSettings.onSuccess = []()
{
wifiState = "Success";
};
WiFiSettings.onFailure = []()
{
wifiState = "Failed";
};
WiFiSettings.onWaitLoop = []()
{
wifiState = "Waiting";
return 500; // Delay next function call by 500ms
};
// Callback functions do not have to be lambda's, e.g.
// WiFiSettings.onPortalWaitLoop = blink;
// Define custom settings saved by WifiSettings
// These will return the default if nothing was set before
String host = WiFiSettings.string("server_host", "default.example.org");
int port = WiFiSettings.integer("server_port", 443);
// Connect to WiFi with a timeout of 30 seconds
// Launches the portal if the connection failed
WiFiSettings.connect(true, 30);
}
void initConnection(void) void initConnection(void)
{ {
filesystem->begin();
initWifiConnection();
} }
void handleConnection(void) void handleConnection(void)
{ {
} }
wifiStrength getWifiStrength(void)
{
return signal_3;
}

View File

@@ -1,5 +1,9 @@
#pragma once #pragma once
#include <littleFS.h>
#include <WiFiSettings.h>
void initConnection( void ); void initConnection( void );
void handleConnection(void); void handleConnection(void);

View File

@@ -0,0 +1 @@
hello world!

View File

@@ -1,142 +1,108 @@
#include "display.h" #include "display.h"
SSD1306Wire display(0x3c, SDA, SCL); SSD1306Wire display(0x3c, SDA, SCL);
bool initOK = false;
OLEDDisplayUi ui(&display); e_displayStates displayState = DISPLAY_INIT;
uint32_t lastDisplayCycle = 0;
uint32_t lastDisplayUpdate = 0;
void drawDSMRstats(void)
int screenW = 128;
int screenH = 64;
int clockCenterX = screenW / 2;
int clockCenterY = ((screenH - 16) / 2) + 16; // top yellow part is 16 px height
int clockRadius = 23;
// utility function for digital clock display: prints leading 0
String twoDigits(int digits)
{ {
if (digits < 10) display.setTextAlignment(TEXT_ALIGN_LEFT);
{ display.setFont(ArialMT_Plain_10);
String i = '0' + String(digits); display.drawString(0, 0, "DSMR stats:");
return i; display.drawString(0, 11, getMsgCount());
}
else
{
return String(digits);
}
} }
void msOverlay(OLEDDisplay *display, OLEDDisplayUiState *state) void drawElecFrame(void)
{ {
display.setTextAlignment(TEXT_ALIGN_LEFT);
display.setFont(ArialMT_Plain_10);
display.drawString(0, 0, "Electricity:");
display.drawString(0, 11, getElecDelivered());
display.drawString(0, 22, getElecReturned());
} }
void initFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) void drawGasFrame(void)
{ {
// draw an xbm image. display.setTextAlignment(TEXT_ALIGN_LEFT);
// Please note that everything that should be transitioned display.setFont(ArialMT_Plain_10);
// needs to be drawn relative to x and y display.drawString(0, 0, getGasDelivered());
//display->drawXbm(x + 34, y + 14, WiFi_Logo_width, WiFi_Logo_height, WiFi_Logo_bits);
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(ArialMT_Plain_16);
display->drawString(64 + x, 8 + y, "DU-DSMR-W");
//display->
} }
void DSMRStatsFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y) void drawInitFrame(void)
{ {
// Demonstrates the 3 included default sizes. The fonts come from SSD1306Fonts.h file display.setTextAlignment(TEXT_ALIGN_CENTER);
// Besides the default fonts there will be a program to convert TrueType fonts into this format display.setFont(ArialMT_Plain_16);
display.drawString(64, 12, "DU-DSMR-W");
display->setTextAlignment(TEXT_ALIGN_LEFT); display.drawXbm(0, 0, wifiicon10x10_width, wifiicon10x10_height, wifi10x10_png_bits);
display->setFont(ArialMT_Plain_10); display.drawXbm(16,0, download_cloud_solid_png_width, download_cloud_solid_png_height, download_cloud_solid_png_bits);
display->drawString(0 + x, 0 + y, "DSMR stats:");
display->drawString(0 + x, 11 + y, getMsgCount());
} }
void ElecFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(ArialMT_Plain_10);
display->drawString(0 + x, 0 + y, "Electricity:");
display->drawString(0 + x, 11 + y, getElecDelivered());
display->drawString(0 + x, 22 + y, getElecReturned());
}
void GasFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(ArialMT_Plain_10);
display->drawString(0 + x, 0 + y, getGasDelivered());
}
void drawFrame5(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
}
// This array keeps function pointers to all frames
// frames are the single views that slide in
FrameCallback frames[] = {initFrame, DSMRStatsFrame, ElecFrame, GasFrame};//, drawFrame5};
// how many frames are there?
int frameCount = 4;
// Overlays are statically drawn on top of a frame eg. a clock
//OverlayCallback overlays[] = {msOverlay};
//int overlaysCount = 1;
void initDisplay(void) void initDisplay(void)
{ {
// The ESP is capable of rendering 60fps in 80Mhz mode
// but that won't give you much time for anything else
// run it in 160Mhz mode or just set it to 30 fps
ui.setTargetFPS(30);
display.init(); display.init();
// Customize the active and inactive symbol drawInitFrame();
//ui.setActiveSymbol(activeSymbol); display.display();
//ui.setInactiveSymbol(inactiveSymbol);
// You can change this to Serial.printf("initdisplay: h=%u, w=%u\n", display.height(), display.width());
// TOP, LEFT, BOTTOM, RIGHT }
ui.setIndicatorPosition(RIGHT);
// Defines where the first frame is located in the bar. e_displayStates nextFrame(void)
ui.setIndicatorDirection(LEFT_RIGHT); {
displayState = static_cast<e_displayStates>(static_cast<int>(displayState) + 1);
// You can change the transition that is used if (displayState == DISPLAU_LAST)
// SLIDE_LEFT, SLIDE_RIGHT, SLIDE_UP, SLIDE_DOWN {
ui.setFrameAnimation(SLIDE_UP); displayState = DISPLAY_DSMR1;
}
// Add frames return displayState;
ui.setFrames(frames, frameCount);
// Add overlays
//ui.setOverlays(overlays, overlaysCount);
//ui.disableAllIndicators();
// Initialising the UI will init the display too.
ui.init();
Serial.printf("initdisplay: h=%u, w=%u", display.height(), display.width());
//display.flipScreenVertically();
} }
void handleDisplay(void) void handleDisplay(void)
{ {
int remainingTimeBudget = ui.update(); uint32_t timeNow = millis();
if (remainingTimeBudget > 0) if (timeNow - lastDisplayUpdate > DISPLAY_CYCLE_TIME)
{ {
// You can do some work here //lastDisplayUpdate
// Don't do stuff if you are below your display.clear();
// time budget.
Serial.println(remainingTimeBudget); switch (displayState)
//delay(remainingTimeBudget); {
case DISPLAY_INIT:
{
drawInitFrame();
}
break;
case DISPLAY_DSMR1:
{
drawElecFrame();
}
break;
case DISPLAY_DSMR2:
{
drawGasFrame();
}
break;
case DISPLAY_DSMR3:
{
drawDSMRstats();
}
break;
default:
{
displayState = nextFrame();
}
break;
}
display.display();
lastDisplayUpdate = timeNow;
}
if (timeNow - lastDisplayCycle > DISPLAY_CYCLE_TIME)
{
displayState = nextFrame();
lastDisplayCycle = timeNow;
} }
} }

View File

@@ -1,12 +1,23 @@
#pragma once #pragma once
#include "Arduino.h" #include "Arduino.h"
#include "OLEDDisplayUi.h" #include "SSD1306Wire.h"
#include "SSD1306Wire.h" // legacy include: `#include "SSD1306.h"`
#include "board.h" #include "board.h"
#include "images.h" #include "images.h"
#include "dsmrhandler.h" #include "dsmrhandler.h"
#include "connection.h" #include "connection.h"
#define DISPLAY_UPDATE_TIME 200
#define DISPLAY_CYCLE_TIME 3000
typedef enum{
DISPLAY_INIT,
DISPLAY_DSMR1,
DISPLAY_DSMR2,
DISPLAY_DSMR3,
DISPLAU_LAST
}e_displayStates;
void initDisplay(void); void initDisplay(void);
void handleDisplay(void); void handleDisplay(void);

View File

@@ -1,35 +1,22 @@
#pragma once #pragma once
#include "Arduino.h" #include "Arduino.h"
#define WiFi_Logo_width 60
#define WiFi_Logo_height 36
const uint8_t WiFi_Logo_bits[] { #define wifiicon10x10_width 13
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, #define wifiicon10x10_height 10
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, const PROGMEM uint8_t wifi10x10_png_bits[] = {
0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF, 0xf0, 0x01, 0x0c, 0x06, 0x02, 0x08, 0xf0, 0x01, 0x08, 0x02, 0x00, 0x00,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00
0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
0xFF, 0x03, 0x00, 0x00, 0x00, 0xFC, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
0x00, 0xFF, 0xFF, 0xFF, 0x07, 0xC0, 0x83, 0x01, 0x80, 0xFF, 0xFF, 0xFF,
0x01, 0x00, 0x07, 0x00, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x0C, 0x00,
0xC0, 0xFF, 0xFF, 0x7C, 0x00, 0x60, 0x0C, 0x00, 0xC0, 0x31, 0x46, 0x7C,
0xFC, 0x77, 0x08, 0x00, 0xE0, 0x23, 0xC6, 0x3C, 0xFC, 0x67, 0x18, 0x00,
0xE0, 0x23, 0xE4, 0x3F, 0x1C, 0x00, 0x18, 0x00, 0xE0, 0x23, 0x60, 0x3C,
0x1C, 0x70, 0x18, 0x00, 0xE0, 0x03, 0x60, 0x3C, 0x1C, 0x70, 0x18, 0x00,
0xE0, 0x07, 0x60, 0x3C, 0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C,
0xFC, 0x73, 0x18, 0x00, 0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00,
0xE0, 0x87, 0x70, 0x3C, 0x1C, 0x70, 0x18, 0x00, 0xE0, 0x8F, 0x71, 0x3C,
0x1C, 0x70, 0x18, 0x00, 0xC0, 0xFF, 0xFF, 0x3F, 0x00, 0x00, 0x08, 0x00,
0xC0, 0xFF, 0xFF, 0x1F, 0x00, 0x00, 0x0C, 0x00, 0x80, 0xFF, 0xFF, 0x1F,
0x00, 0x00, 0x06, 0x00, 0x80, 0xFF, 0xFF, 0x0F, 0x00, 0x00, 0x07, 0x00,
0x00, 0xFE, 0xFF, 0xFF, 0xFF, 0xFF, 0x01, 0x00, 0x00, 0xF8, 0xFF, 0xFF,
0xFF, 0x7F, 0x00, 0x00, 0x00, 0x00, 0xFE, 0xFF, 0xFF, 0x01, 0x00, 0x00,
0x00, 0x00, 0xFC, 0xFF, 0xFF, 0x00, 0x00, 0x00, 0x00, 0x00, 0xF8, 0xFF,
0x7F, 0x00, 0x00, 0x00, 0x00, 0x00, 0xE0, 0xFF, 0x1F, 0x00, 0x00, 0x00,
0x00, 0x00, 0x80, 0xFF, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFC,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
}; };
#define download_cloud_solid_png_width 18
#define download_cloud_solid_png_height 9
const PROGMEM uint8_t download_cloud_solid_png_bits[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x91, 0xb9, 0x03, 0x5b, 0x12, 0x01,
0x55, 0x12, 0x01, 0x51, 0x13, 0x01, 0x91, 0x13, 0x01, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00 };
const uint8_t activeSymbol[] = { const uint8_t activeSymbol[] = {
B00000000, B00000000,
B00000000, B00000000,

View File

@@ -4,7 +4,6 @@
#include "connection.h" #include "connection.h"
void setup() { void setup() {
// put your setup code here, to run once: // put your setup code here, to run once:
Serial.begin(115200); Serial.begin(115200);
@@ -18,7 +17,6 @@ void setup() {
void loop() { void loop() {
// put your main code here, to run repeatedly: // put your main code here, to run repeatedly:
Serial.print(".|.ß");
handleDisplay(); handleDisplay();
handleConnection(); handleConnection();
} }