@@ -41,137 +41,137 @@ int status = WL_IDLE_STATUS;
4141
4242void sendRequest ()
4343{
44- static bool requestOpenResult;
45-
46- if (request.readyState () == readyStateUnsent || request.readyState () == readyStateDone)
47- {
48- Serial.println (" \n Sending GET Request to " + String (GET_ServerAddress));
49-
50- requestOpenResult = request.open (" GET" , GET_ServerAddress);
51-
52- // request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
53- if (requestOpenResult)
54- {
55- // Only send() if open() returns true, or crash
56- request.send ();
57- }
58- else
59- {
60- Serial.println (" Can't send bad request" );
61- }
62- }
63- else
64- {
65- Serial.println (" Can't send request" );
66- }
44+ static bool requestOpenResult;
45+
46+ if (request.readyState () == readyStateUnsent || request.readyState () == readyStateDone)
47+ {
48+ Serial.println (" \n Sending GET Request to " + String (GET_ServerAddress));
49+
50+ requestOpenResult = request.open (" GET" , GET_ServerAddress);
51+
52+ // request.setReqHeader("X-CUSTOM-HEADER", "custom_value");
53+ if (requestOpenResult)
54+ {
55+ // Only send() if open() returns true, or crash
56+ request.send ();
57+ }
58+ else
59+ {
60+ Serial.println (" Can't send bad request" );
61+ }
62+ }
63+ else
64+ {
65+ Serial.println (" Can't send request" );
66+ }
6767}
6868
6969void requestCB (void *optParm, AsyncHTTPRequest *request, int readyState)
7070{
71- (void ) optParm;
72-
73- if (readyState == readyStateDone)
74- {
75- AHTTP_LOGWARN (F (" \n **************************************" ));
76- AHTTP_LOGWARN1 (F (" Response Code = " ), request->responseHTTPString ());
77-
78- if (request->responseHTTPcode () == 200 )
79- {
80- Serial.println (F (" \n **************************************" ));
81- Serial.println (request->responseText ());
82- Serial.println (F (" **************************************" ));
83- }
84- }
71+ (void ) optParm;
72+
73+ if (readyState == readyStateDone)
74+ {
75+ AHTTP_LOGWARN (F (" \n **************************************" ));
76+ AHTTP_LOGWARN1 (F (" Response Code = " ), request->responseHTTPString ());
77+
78+ if (request->responseHTTPcode () == 200 )
79+ {
80+ Serial.println (F (" \n **************************************" ));
81+ Serial.println (request->responseText ());
82+ Serial.println (F (" **************************************" ));
83+ }
84+ }
8585}
8686
8787void printWifiStatus ()
8888{
89- // print the SSID of the network you're attached to:
90- Serial.print (" SSID: " );
91- Serial.println (WiFi.SSID ());
92-
93- // print your board's IP address:
94- IPAddress ip = WiFi.localIP ();
95- Serial.print (" Local IP Address: " );
96- Serial.println (ip);
89+ // print the SSID of the network you're attached to:
90+ Serial.print (" SSID: " );
91+ Serial.println (WiFi.SSID ());
92+
93+ // print your board's IP address:
94+ IPAddress ip = WiFi.localIP ();
95+ Serial.print (" Local IP Address: " );
96+ Serial.println (ip);
9797}
9898
9999void setup ()
100100{
101- Serial.begin (115200 );
101+ Serial.begin (115200 );
102102
103- while (!Serial && millis () < 5000 );
103+ while (!Serial && millis () < 5000 );
104104
105- Serial.print (" \n Start AsyncCustomHeader on " );
106- Serial.println (BOARD_NAME);
107- Serial.println (ASYNCTCP_RP2040W_VERSION);
108- Serial.println (ASYNC_HTTP_REQUEST_RP2040W_VERSION);
105+ Serial.print (" \n Start AsyncCustomHeader on " );
106+ Serial.println (BOARD_NAME);
107+ Serial.println (ASYNCTCP_RP2040W_VERSION);
108+ Serial.println (ASYNC_HTTP_REQUEST_RP2040W_VERSION);
109109
110110#if defined(ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN)
111111
112- if (ASYNC_HTTP_REQUEST_RP2040W_VERSION_INT < ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN)
113- {
114- Serial.print (" Warning. Must use this example on Version equal or later than : " );
115- Serial.println (ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN);
116- }
112+ if (ASYNC_HTTP_REQUEST_RP2040W_VERSION_INT < ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN)
113+ {
114+ Serial.print (" Warning. Must use this example on Version equal or later than : " );
115+ Serial.println (ASYNC_HTTP_REQUEST_RP2040W_VERSION_MIN);
116+ }
117117
118118#endif
119119
120- // /////////////////////////////////
120+ // /////////////////////////////////
121121
122- // check for the WiFi module:
123- if (WiFi.status () == WL_NO_MODULE)
124- {
125- Serial.println (" Communication with WiFi module failed!" );
122+ // check for the WiFi module:
123+ if (WiFi.status () == WL_NO_MODULE)
124+ {
125+ Serial.println (" Communication with WiFi module failed!" );
126126
127- // don't continue
128- while (true );
129- }
127+ // don't continue
128+ while (true );
129+ }
130130
131- Serial.print (F (" Connecting to SSID: " ));
132- Serial.println (ssid);
131+ Serial.print (F (" Connecting to SSID: " ));
132+ Serial.println (ssid);
133133
134- status = WiFi.begin (ssid, pass);
134+ status = WiFi.begin (ssid, pass);
135135
136- delay (1000 );
136+ delay (1000 );
137137
138- // attempt to connect to WiFi network
139- while ( status != WL_CONNECTED)
140- {
141- delay (500 );
138+ // attempt to connect to WiFi network
139+ while ( status != WL_CONNECTED)
140+ {
141+ delay (500 );
142142
143- // Connect to WPA/WPA2 network
144- status = WiFi.status ();
145- }
143+ // Connect to WPA/WPA2 network
144+ status = WiFi.status ();
145+ }
146146
147- printWifiStatus ();
147+ printWifiStatus ();
148148
149- // /////////////////////////////////
149+ // /////////////////////////////////
150150
151- request.setDebug (false );
151+ request.setDebug (false );
152152
153- // 5s timeout
154- request.setTimeout (5 );
153+ // 5s timeout
154+ request.setTimeout (5 );
155155
156- request.onReadyStateChange (requestCB);
156+ request.onReadyStateChange (requestCB);
157157}
158158
159159void sendRequestRepeat ()
160160{
161- static unsigned long sendRequest_timeout = 0 ;
161+ static unsigned long sendRequest_timeout = 0 ;
162162
163163#define SEND_REQUEST_INTERVAL 60000L
164164
165- // sendRequest every SEND_REQUEST_INTERVAL (60) seconds: we don't need to sendRequest frequently
166- if ((millis () > sendRequest_timeout) || (sendRequest_timeout == 0 ))
167- {
168- sendRequest ();
165+ // sendRequest every SEND_REQUEST_INTERVAL (60) seconds: we don't need to sendRequest frequently
166+ if ((millis () > sendRequest_timeout) || (sendRequest_timeout == 0 ))
167+ {
168+ sendRequest ();
169169
170- sendRequest_timeout = millis () + SEND_REQUEST_INTERVAL;
171- }
170+ sendRequest_timeout = millis () + SEND_REQUEST_INTERVAL;
171+ }
172172}
173173
174174void loop ()
175175{
176- sendRequestRepeat ();
176+ sendRequestRepeat ();
177177}
0 commit comments