File tree Expand file tree Collapse file tree 3 files changed +35
-8
lines changed Expand file tree Collapse file tree 3 files changed +35
-8
lines changed Original file line number Diff line number Diff line change 1515 See file LICENSE.txt for further informations on licensing terms.
1616
1717 Parts of this class are based on
18-
18+
1919 - EthernetClientStream - Copyright (C) 2013 Norbert Truchsess. All rights reserved.
20-
20+
2121 published under the same license.
2222
23- Last updated April 15th , 2016
23+ Last updated April 17th , 2016
2424 */
2525
2626#ifndef WIFI_CLIENT_STREAM_H
@@ -55,9 +55,14 @@ class WiFiClientStream : public WiFiStream
5555 if ( millis () - _time_connect >= MILLIS_RECONNECT )
5656 {
5757 _connected = _client.connect ( _remote_ip, _port );
58- if ( !_connected ) {
58+ if ( !_connected )
59+ {
5960 _time_connect = millis ();
6061 }
62+ else if ( _currentHostConnectionCallback )
63+ {
64+ (*_currentHostConnectionCallback)(HOST_CONNECTION_CONNECTED);
65+ }
6166 }
6267 }
6368
@@ -87,6 +92,10 @@ class WiFiClientStream : public WiFiStream
8792 if ( _client)
8893 {
8994 _client.stop ();
95+ if ( _currentHostConnectionCallback )
96+ {
97+ (*_currentHostConnectionCallback)(HOST_CONNECTION_DISCONNECTED);
98+ }
9099 }
91100 _connected = false ;
92101 _time_connect = millis ();
Original file line number Diff line number Diff line change 2020
2121 published under the same license.
2222
23- Last updated April 16th , 2016
23+ Last updated April 17th , 2016
2424 */
2525
2626#ifndef WIFI_SERVER_STREAM_H
@@ -49,8 +49,12 @@ class WiFiServerStream : public WiFiStream
4949
5050 // passive TCP connect (accept)
5151 WiFiClient newClient = _server.available ();
52- if ( !_client ) return false ; // could this work on all platforms? if( !(_client && _client.connected()) ) return false;
52+ if ( !newClient ) return false ;
5353 _client = newClient;
54+ if ( _currentHostConnectionCallback )
55+ {
56+ (*_currentHostConnectionCallback)(HOST_CONNECTION_CONNECTED);
57+ }
5458
5559 return true ;
5660 }
@@ -90,6 +94,10 @@ class WiFiServerStream : public WiFiStream
9094 if ( _client)
9195 {
9296 _client.stop ();
97+ if ( _currentHostConnectionCallback )
98+ {
99+ (*_currentHostConnectionCallback)(HOST_CONNECTION_DISCONNECTED);
100+ }
93101 }
94102 _connected = false ;
95103 }
Original file line number Diff line number Diff line change 1515
1616 See file LICENSE.txt for further informations on licensing terms.
1717
18- Last updated April 15th , 2016
18+ Last updated April 17th , 2016
1919 */
20-
20+
2121#ifndef WIFI_STREAM_H
2222#define WIFI_STREAM_H
2323
2424#include < inttypes.h>
2525#include < Stream.h>
2626
27+ #define HOST_CONNECTION_DISCONNECTED 0
28+ #define HOST_CONNECTION_CONNECTED 1
29+
30+ extern " C" {
31+ // callback function types
32+ typedef void (*hostConnectionCallbackFunction)(byte);
33+ }
34+
2735class WiFiStream : public Stream
2836{
2937protected:
3038 WiFiClient _client;
3139 bool _connected = false ;
40+ hostConnectionCallbackFunction _currentHostConnectionCallback;
3241
3342 // configuration members
3443 IPAddress _local_ip; // DHCP
@@ -54,6 +63,7 @@ class WiFiStream : public Stream
5463 /* * constructor for TCP client */
5564 WiFiStream (IPAddress server_ip, uint16_t server_port) : _remote_ip(server_ip), _port(server_port) {}
5665
66+ inline void attach ( hostConnectionCallbackFunction newFunction ) { _currentHostConnectionCallback = newFunction; }
5767
5868/* *****************************************************************************
5969 * network configuration
You can’t perform that action at this time.
0 commit comments