1#ifndef wifidumbdisplay_h
2#define wifidumbdisplay_h
7#include "dumbdisplay.h"
13#define LOG_DDWIFI_STATUS
27 server(serverPort, tProtMode::TCP_MODE, tBlockingMode::NON_BLOCKING_MODE) {
29 this->password = passphrase;
30 this->port = serverPort;
35 const char* getWhat() {
50 int count = client.available();
53 Serial.print(
"- available: ");
54 Serial.println(count);
60 char ch = client.read();
62 Serial.print(
"- read:[");
68 void print(
const String &s) {
69#ifdef WRITE_BYTE_BY_BYTES
70 for (
size_t i = 0; i < s.length(); i++) {
85 void print(
const char *p) {
86#ifdef WRITE_BYTE_BY_BYTES
96 Serial.print(
"* print: [");
109 void write(uint8_t b) {
110#ifdef WRITE_BYTE_BY_BYTES
112 size_t count = client.write(b);
122 void write(
const uint8_t *buf,
size_t size) {
123#ifdef WRITE_BYTE_BY_BYTES
124 for (
size_t i = 0; i < size; i++) {
129 Serial.print(
"*** write ");
131 Serial.print(
" ... ");
132 size_t written = client.write(buf, size);
133 Serial.println(written);
135 client.write(buf, size);
142 bool preConnect(
bool firstCall) {
144 if (!Serial) Serial.begin(DD_SERIAL_BAUD);
158 if (firstCall && !client.connected()) {
159 connectionState =
'0';
162 return connectionState ==
'C';
164 if (firstCall && !client.connected()) {
165 Serial.println(
"setup WIFI");
167 WiFi.begin(ssid, password);
168 connectionState =
' ';
172 return connectionState ==
'C';
176 if (client.connected()) {
177 Serial.println(
"stop client for new setup");
186 Serial.println(
"setup WIFI");
187 WiFi.begin(ssid, password);
188 connectionState =
' ';
193 return connectionState ==
'C';
202 WiFi.begin(ssid, password);
203 connectionState =
' ';
209 return connectionState ==
'C';
217 void validConnection() {
218#ifdef LOG_DDWIFI_STATUS
219 Serial.println(
" ... validate ...");
223 bool canConnectPassive() {
226 bool canUseBuffer() {
301 void checkConnection() {
302 if (connectionState ==
'0' || connectionState ==
'C') {
303 if (connectionState ==
'0' || WiFi.status() != WL_CONNECTED) {
304 if (connectionState ==
'C') {
305 Serial.println(
"lost WiFi ... try bind WiFi again ...");
309 Serial.println(
"setup WIFI");
310 WiFi.begin(ssid, password);
311 connectionState =
' ';
313 }
else if (!client.connected()) {
315 Serial.println(
"lost connection ... try bind again ...");
316 connectionState =
'W';
322 if (connectionState ==
' ') {
323 uint8_t status = WiFi.status();
324 if (status == WL_CONNECTED) {
325 Serial.print(
"binded WIFI ");
326 Serial.println(ssid);
328 connectionState =
'W';
331 long diff = millis() - stateMillis;
332 if (stateMillis == 0 || diff > 1000) {
333 Serial.print(
"binding WIFI ");
335#ifdef LOG_DDWIFI_STATUS
336 Serial.print(
" ... ");
337 Serial.print(status);
339 Serial.println(
" ...");
340 stateMillis = millis();
344 uint8_t status = WiFi.status();
345 if (status != WL_CONNECTED) {
346 connectionState =
' ';
349 long diff = millis() - stateMillis;
351 IPAddress localIP = WiFi.localIP();
353#ifdef LOG_DDWIFI_STATUS
354 Serial.print(
"via WIFI ... ");
355 Serial.print(WiFi.status());
356 Serial.print(
" ... ");
358 Serial.print(
"listening on ");
359 Serial.print(localIP);
362 Serial.println(
" ...");
370 stateMillis = millis();
372 WiFiClient cli = server.available();
380 if (cli && cli.connected()) {
385 connectionState =
'C';
387 Serial.println(
"client connected");
399 char connectionState;
Definition: amb82wifidumbdisplay.h:19