1#ifndef wifidumbdisplay_h
2#define wifidumbdisplay_h
7#include "dumbdisplay.h"
9#if defined(ARDUINO_UNOR4_WIFI)
12 #include <ESP8266WiFi.h>
29 DDWiFiServerIO(
const char* ssid,
const char *passphrase,
int serverPort = DD_WIFI_PORT):
DDInputOutput(DD_SERIAL_BAUD,
false,
false),
32 this->password = passphrase;
33 this->port = serverPort;
37 const char* getWhat() {
41 bool availableAdditionalClient(WiFiClient& additionalClient) {
42 if (client.connected()) {
43 WiFiClient cli = server.available();
45 additionalClient = cli;
52 return client.available() > 0;
57 void print(
const String &s) {
60 void print(
const char *p) {
63 void write(uint8_t b) {
66 void write(
const uint8_t *buf,
size_t size) {
68 Serial.print(
"*** write ");
70 Serial.print(
" ... ");
71 size_t written = client.write(buf, size);
72 Serial.println(written);
74 client.write(buf, size);
77 bool preConnect(
bool firstCall) {
79 if (!Serial) Serial.begin(DD_SERIAL_BAUD);
80#if defined(ARDUINO_UNOR4_WIFI)
81 if (WiFi.status() == WL_NO_MODULE) {
82 Serial.println(
"XXX communication with WiFi module failed");
84 String fv = WiFi.firmwareVersion();
85 if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
86 Serial.println(
"XXX please upgrade the firmware");
88 Serial.println(
"* WIFI_FIRMWARE_LATEST_VERSION=" + String(WIFI_FIRMWARE_LATEST_VERSION));
93 if (firstCall && !client.connected()) {
94 connectionState =
'0';
97 return connectionState ==
'C';
99 if (firstCall && !client.connected()) {
100 Serial.println(
"setup WIFI");
102 WiFi.begin(ssid, password);
103 connectionState =
' ';
107 return connectionState ==
'C';
111 if (client.connected()) {
112 Serial.println(
"stop client for new setup");
121 Serial.println(
"setup WIFI");
122 WiFi.begin(ssid, password);
123 connectionState =
' ';
128 return connectionState ==
'C';
137 WiFi.begin(ssid, password);
138 connectionState =
' ';
144 return connectionState ==
'C';
150 void validConnection() {
151#ifdef LOG_DDWIFI_STATUS
152 Serial.println(
" ... validate ...");
156 bool canConnectPassive() {
159 bool canUseBuffer() {
234 void checkConnection() {
235 if (connectionState ==
'0' || connectionState ==
'C') {
236 if (connectionState ==
'0' || WiFi.status() != WL_CONNECTED) {
237 if (connectionState ==
'C') {
238 Serial.println(
"lost WiFi ... try bind WiFi again ...");
242 Serial.println(
"setup WIFI");
243 WiFi.begin(ssid, password);
244 connectionState =
' ';
246 }
else if (!client.connected()) {
248 Serial.println(
"lost connection ... try bind again ...");
249 connectionState =
'W';
255 if (connectionState ==
' ') {
256 uint8_t status = WiFi.status();
257 if (status == WL_CONNECTED) {
258 Serial.print(
"binded WIFI ");
259 Serial.println(ssid);
261 connectionState =
'W';
264 long diff = millis() - stateMillis;
265 if (stateMillis == 0 || diff > 1000) {
266 Serial.print(
"binding WIFI ");
268#ifdef LOG_DDWIFI_STATUS
269 Serial.print(
" ... ");
270 Serial.print(status);
272 Serial.println(
" ...");
273 stateMillis = millis();
277 uint8_t status = WiFi.status();
278 if (status != WL_CONNECTED) {
279 connectionState =
' ';
282 long diff = millis() - stateMillis;
284 IPAddress localIP = WiFi.localIP();
285 uint32_t localIPValue = localIP;
286#ifdef LOG_DDWIFI_STATUS
287 Serial.print(
"via WIFI ... ");
288 Serial.print(WiFi.status());
289 Serial.print(
" ... ");
291 Serial.print(
"listening on ");
292 Serial.print(localIP);
295 Serial.println(
" ...");
303 stateMillis = millis();
305 WiFiClient cli = server.available();
308 connectionState =
'C';
310 Serial.println(
"client connected");
319 const char *password;
322 char connectionState;
Subclass of DDInputOutput.
Definition: wifidumbdisplay.h:23