forked from arduino-libraries/Arduino_ConnectionHandler
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathWiFiConnectionHandler.h
More file actions
85 lines (70 loc) · 2.84 KB
/
WiFiConnectionHandler.h
File metadata and controls
85 lines (70 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
This file is part of the Arduino_ConnectionHandler library.
Copyright (c) 2019 Arduino SA
This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#ifndef ARDUINO_WIFI_CONNECTION_HANDLER_H_
#define ARDUINO_WIFI_CONNECTION_HANDLER_H_
/******************************************************************************
INCLUDE
******************************************************************************/
#include "ConnectionHandlerInterface.h"
#ifdef ARDUINO_SAMD_MKR1000
#include <WiFi101.h>
#include <WiFiUdp.h>
#elif defined(ARDUINO_ARCH_ZEPHYR)
#include <WiFi.h>
#include <WiFiUdp.h>
#elif defined(ARDUINO_SAMD_MKRWIFI1010) || defined(ARDUINO_SAMD_NANO_33_IOT) || \
defined(ARDUINO_AVR_UNO_WIFI_REV2) || defined (ARDUINO_NANO_RP2040_CONNECT)
#include <WiFiNINA.h>
#include <WiFiUdp.h>
#elif defined(ARDUINO_PORTENTA_H7_M7) || defined(ARDUINO_PORTENTA_H7_M7) || \
defined(ARDUINO_NICLA_VISION) || defined(ARDUINO_OPTA) || defined(ARDUINO_GIGA)
#include <WiFi.h>
#include <WiFiUdp.h>
#elif defined(ARDUINO_PORTENTA_C33)
#include <WiFiC3.h>
#include <WiFiUdp.h>
#elif defined(ARDUINO_ARCH_ESP8266)
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#elif defined(ARDUINO_ARCH_ESP32)
#include <WiFi.h>
#include <WiFiUdp.h>
#elif defined(ARDUINO_UNOR4_WIFI)
#include <WiFiS3.h>
#elif defined(ARDUINO_RASPBERRY_PI_PICO_W)
#include <WiFi.h>
#include <WiFiUdp.h>
#endif
#ifndef BOARD_HAS_WIFI
#error "Board doesn't support WIFI"
#endif
/******************************************************************************
CLASS DECLARATION
******************************************************************************/
class WiFiConnectionHandler : public ConnectionHandler
{
public:
WiFiConnectionHandler();
WiFiConnectionHandler(char const * ssid, char const * pass, bool const keep_alive = true);
int ping(IPAddress ip, uint8_t ttl = 128, uint8_t count = 1) override;
int ping(const String &hostname, uint8_t ttl = 128, uint8_t count = 1) override;
int ping(const char* host, uint8_t ttl = 128, uint8_t count = 1) override;
virtual unsigned long getTime() override;
virtual Client & getClient() override { return _wifi_client; }
virtual UDP & getUDP() override { return _wifi_udp; }
protected:
virtual NetworkConnectionState update_handleInit () override;
virtual NetworkConnectionState update_handleConnecting () override;
virtual NetworkConnectionState update_handleConnected () override;
virtual NetworkConnectionState update_handleDisconnecting() override;
virtual NetworkConnectionState update_handleDisconnected () override;
private:
WiFiUDP _wifi_udp;
WiFiClient _wifi_client;
};
#endif /* ARDUINO_WIFI_CONNECTION_HANDLER_H_ */