@@ -61,7 +61,7 @@ ESP8266Interface::ESP8266Interface()
61
61
_connect_retval(NSAPI_ERROR_OK),
62
62
_conn_stat(NSAPI_STATUS_DISCONNECTED),
63
63
_conn_stat_cb(NULL ),
64
- _global_event_queue(NULL ),
64
+ _global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO
65
65
_oob_event_id(0 ),
66
66
_connect_event_id(0 )
67
67
{
@@ -77,8 +77,6 @@ ESP8266Interface::ESP8266Interface()
77
77
_sock_i[i].open = false ;
78
78
_sock_i[i].sport = 0 ;
79
79
}
80
-
81
- _oob2global_event_queue ();
82
80
}
83
81
#endif
84
82
@@ -92,7 +90,7 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
92
90
_initialized(false ),
93
91
_conn_stat(NSAPI_STATUS_DISCONNECTED),
94
92
_conn_stat_cb(NULL ),
95
- _global_event_queue(NULL ),
93
+ _global_event_queue(mbed_event_queue()), // Needs to be set before attaching event() to SIGIO
96
94
_oob_event_id(0 ),
97
95
_connect_event_id(0 )
98
96
{
@@ -108,8 +106,6 @@ ESP8266Interface::ESP8266Interface(PinName tx, PinName rx, bool debug, PinName r
108
106
_sock_i[i].open = false ;
109
107
_sock_i[i].sport = 0 ;
110
108
}
111
-
112
- _oob2global_event_queue ();
113
109
}
114
110
115
111
ESP8266Interface::~ESP8266Interface ()
@@ -169,17 +165,6 @@ int ESP8266Interface::connect(const char *ssid, const char *pass, nsapi_security
169
165
return connect ();
170
166
}
171
167
172
- void ESP8266Interface::_oob2global_event_queue ()
173
- {
174
- _global_event_queue = mbed_event_queue ();
175
- _oob_event_id = _global_event_queue->call_every (ESP8266_RECV_TIMEOUT, callback (this , &ESP8266Interface::proc_oob_evnt));
176
-
177
- if (!_oob_event_id) {
178
- MBED_ERROR (MBED_MAKE_ERROR (MBED_MODULE_DRIVER, MBED_ERROR_CODE_ENOMEM), \
179
- " ESP8266::_oob2geq: unable to allocate OOB event" );
180
- }
181
- }
182
-
183
168
void ESP8266Interface::_connect_async ()
184
169
{
185
170
_cmutex.lock ();
@@ -748,6 +733,11 @@ nsapi_error_t ESP8266Interface::getsockopt(nsapi_socket_t handle, int level, int
748
733
749
734
void ESP8266Interface::event ()
750
735
{
736
+ if (!_oob_event_id) {
737
+ // Throttles event creation by using arbitrary small delay
738
+ _oob_event_id = _global_event_queue->call_in (50 , callback (this , &ESP8266Interface::proc_oob_evnt));
739
+ }
740
+
751
741
for (int i = 0 ; i < ESP8266_SOCKET_COUNT; i++) {
752
742
if (_cbs[i].callback ) {
753
743
_cbs[i].callback (_cbs[i].data );
@@ -824,6 +814,7 @@ void ESP8266Interface::refresh_conn_state_cb()
824
814
825
815
void ESP8266Interface::proc_oob_evnt ()
826
816
{
817
+ _oob_event_id = 0 ; // Allows creation of a new event
827
818
_esp.bg_process_oob (ESP8266_RECV_TIMEOUT, true );
828
819
}
829
820
0 commit comments