2424
2525// Define LED_BUILTIN if not defined by the board package
2626#ifndef LED_BUILTIN
27- #if defined(ESP8266)
28- // Most ESP8266 modules (NodeMCU, Wemos) use GPIO 2
29- #define LED_BUILTIN 2
30- #elif defined(ESP32)
31- // Many ESP32 dev boards use GPIO 2
32- #define LED_BUILTIN 2
33- #elif defined(STM32F1xx)
34- // "Blue Pill" STM32 usually uses PC13
35- #define LED_BUILTIN PC13
36- #else
37- // Default for Arduino Uno, Mega, Nano, Leonardo, etc.
38- #define LED_BUILTIN 13
39- #endif
27+ #if defined(ESP8266)
28+ // Most ESP8266 modules (NodeMCU, Wemos) use GPIO 2
29+ #define LED_BUILTIN 2
30+ #elif defined(ESP32)
31+ // Many ESP32 dev boards use GPIO 2
32+ #define LED_BUILTIN 2
33+ #elif defined(STM32F1xx)
34+ // "Blue Pill" STM32 usually uses PC13
35+ #define LED_BUILTIN PC13
36+ #else
37+ // Default for Arduino Uno, Mega, Nano, Leonardo, etc.
38+ #define LED_BUILTIN 13
39+ #endif
4040#endif
41-
4241
4342#include < SerialNetworkBridge.h>
4443
@@ -47,62 +46,62 @@ SerialTCPClient client(Serial, 0);
4746
4847void setup ()
4948{
50- Serial.begin (115200 );
51- while (!Serial)
52- ;
49+ Serial.begin (115200 );
50+ while (!Serial)
51+ ;
5352#if defined(LED_BUILTIN)
54- pinMode (LED_BUILTIN, OUTPUT);
55- digitalWrite (LED_BUILTIN, LOW );
53+ pinMode (LED_BUILTIN, OUTPUT);
54+ digitalWrite (LED_BUILTIN, HIGH );
5655#endif
5756}
5857
59- void loop ( )
58+ void flashLED ( int times, int delayMs )
6059{
61- // 1. Ping the PC Host first to ensure bridge is running
62- if (client.pingHost (500 ))
63- {
64-
65- // Step 1: Pong Received (Flash LED Once)
6660#if defined(LED_BUILTIN)
67- digitalWrite (LED_BUILTIN, HIGH);
68- delay (100 );
69- digitalWrite (LED_BUILTIN, LOW);
70- delay (100 );
61+ for (int i = 0 ; i < times; i++)
62+ {
63+ digitalWrite (LED_BUILTIN, LOW);
64+ delay (delayMs);
65+ digitalWrite (LED_BUILTIN, HIGH);
66+ delay (delayMs);
67+ }
7168#endif
69+ }
7270
73- // Step 2: Send HTTP Request
74- if (client.connect (" httpbin.org" , 80 ))
75- {
71+ void loop ()
72+ {
73+ // 1. Ping the PC Host first to ensure bridge is running
74+ if (client.pingHost (500 ))
75+ {
7676
77- client.println (" GET /get HTTP/1.1" );
78- client.println (" Host: httpbin.org" );
79- client.println (" Connection: close" );
80- client.println ();
77+ // Step 1: Pong Received (Flash LED Once)
78+ flashLED (20 , 50 );
8179
82- // Read and consume the response
83- while (client.connected () || client.available ())
84- {
85- if (client.available ())
86- {
87- client.read ();
88- }
89- }
90- client.stop ();
80+ // Step 2: Send HTTP Request
81+ if (client.connect (" httpbin.org" , 443 ))
82+ {
9183
92- // Step 3: HTTP Success (Flash LED Twice quickly)
93- // Total visual sequence: Flash (Pong)... Flash-Flash (HTTP)
94- # if defined(LED_BUILTIN)
95- digitalWrite (LED_BUILTIN, HIGH );
96- delay ( 100 );
97- digitalWrite (LED_BUILTIN, LOW);
98- delay ( 100 );
99- digitalWrite (LED_BUILTIN, HIGH);
100- delay ( 100 );
101- digitalWrite (LED_BUILTIN, LOW);
102- # endif
84+ client. println ( " GET /get HTTP/1.1 " );
85+ client. println ( " Host: httpbin.org " );
86+ client. println ( " Connection: close " );
87+ client. println ( );
88+
89+ // Read and consume the response
90+ while (client. connected () || client. available ())
91+ {
92+ if (client. available ())
93+ {
94+ client. read ();
10395 }
96+ }
97+ client.stop ();
98+
99+ // Step 3: HTTP Success (Flash LED Twice quickly)
100+ // Total visual sequence: Flash (Pong)... Flash-Flash (HTTP)
101+ flashLED (60 , 50 );
104102 }
103+ }
105104
106- // Wait 5 seconds before repeating
107- delay (5000 );
105+ // Wait 5 seconds before repeating
106+ delay (5000 );
108107}
0 commit comments