1#ifndef wifidumbdisplay_h
2#define wifidumbdisplay_h
7#include "dumbdisplay.h"
13#define LOG_DDWIFI_STATUS
28 server(serverPort, tProtMode::TCP_MODE, tBlockingMode::NON_BLOCKING_MODE) {
30 this->password = passphrase;
31 this->port = serverPort;
32 this->bufferFilled =
false;
37 const char* getWhat() {
49 char c = this->buffer[0];
50 this->bufferFilled =
false;
60 void print(
const String &s) {
61#ifdef WRITE_BYTE_BY_BYTES
62 for (
size_t i = 0; i < s.length(); i++) {
77 void print(
const char *p) {
78#ifdef WRITE_BYTE_BY_BYTES
96 void write(uint8_t b) {
97#ifdef WRITE_BYTE_BY_BYTES
99 size_t count = client.write(b);
109 void write(
const uint8_t *buf,
size_t size) {
110#ifdef WRITE_BYTE_BY_BYTES
111 for (
size_t i = 0; i < size; i++) {
115 client.write(buf, size);
121 bool preConnect(
bool firstCall) {
123 if (!Serial) Serial.begin(DD_SERIAL_BAUD);
137 if (firstCall && !client.connected()) {
138 connectionState =
'0';
141 return connectionState ==
'C';
143 if (firstCall && !client.connected()) {
144 Serial.println(
"setup WIFI");
146 WiFi.begin(ssid, password);
147 connectionState =
' ';
151 return connectionState ==
'C';
155 if (client.connected()) {
156 Serial.println(
"stop client for new setup");
165 Serial.println(
"setup WIFI");
166 WiFi.begin(ssid, password);
167 connectionState =
' ';
172 return connectionState ==
'C';
181 WiFi.begin(ssid, password);
182 connectionState =
' ';
188 return connectionState ==
'C';
196 void validConnection() {
197#ifdef LOG_DDWIFI_STATUS
198 Serial.println(
" ... validate ...");
202 bool canConnectPassive() {
205 bool canUseBuffer() {
209 void checkConnection() {
210 if (connectionState ==
'0' || connectionState ==
'C') {
211 if (connectionState ==
'0' || WiFi.status() != WL_CONNECTED) {
212 if (connectionState ==
'C') {
213 Serial.println(
"lost WiFi ... try bind WiFi again ...");
217 Serial.println(
"setup WIFI");
218 WiFi.begin(ssid, password);
219 connectionState =
' ';
221 }
else if (!client.connected()) {
223 Serial.println(
"lost connection ... try bind again ...");
224 connectionState =
'W';
230 if (connectionState ==
' ') {
231 uint8_t status = WiFi.status();
232 if (status == WL_CONNECTED) {
233 Serial.print(
"binded WIFI ");
234 Serial.println(ssid);
236 connectionState =
'W';
239 long diff = millis() - stateMillis;
240 if (stateMillis == 0 || diff > 1000) {
241 Serial.print(
"binding WIFI ");
243#ifdef LOG_DDWIFI_STATUS
244 Serial.print(
" ... ");
245 Serial.print(status);
247 Serial.println(
" ...");
248 stateMillis = millis();
252 uint8_t status = WiFi.status();
253 if (status != WL_CONNECTED) {
254 connectionState =
' ';
257 long diff = millis() - stateMillis;
259 IPAddress localIP = WiFi.localIP();
261#ifdef LOG_DDWIFI_STATUS
262 Serial.print(
"via WIFI ... ");
263 Serial.print(WiFi.status());
264 Serial.print(
" ... ");
266 Serial.print(
"listening on ");
267 Serial.print(localIP);
270 Serial.println(
" ...");
271 stateMillis = millis();
273 WiFiClient cli = server.available();
274 if (cli && cli.connected()) {
276 connectionState =
'C';
278 Serial.println(
"client connected");
287 if (this->bufferFilled) {
290 int n = client.read(this->buffer, 1);
292 this->bufferFilled =
true;
302 char connectionState;
Definition: amb82wifidumbdisplay.h:19